@@ -48,13 +48,11 @@ def uninstall(version=None, packages=None):
4848 packages = _filter_installed_packages (version , packages )
4949
5050 ipylib_path = compas_rhino ._get_ironpython_lib_path (version )
51+ # We install COMPAS packages in the scripts folder
52+ # instead of directly as IPy module.
5153 scripts_path = compas_rhino ._get_scripts_path (version )
5254
53- print ('Uninstalling COMPAS packages from Rhino {0} scripts folder:' .format (version ))
54- print ('Location scripts folder: {}' .format (scripts_path ))
55- print ()
56-
57- print ('The following packages have been detected and will be uninstalled:' )
55+ print ('Uninstalling COMPAS packages from Rhino {0} scripts folder: \n {1}' .format (version , scripts_path ))
5856
5957 results = []
6058 symlinks_to_uninstall = []
@@ -65,50 +63,66 @@ def uninstall(version=None, packages=None):
6563 if os .path .exists (symlink_path ):
6664 symlinks_to_uninstall .append (dict (name = package , link = symlink_path ))
6765
68- legacy_path = os .path .join (ipylib_path , package )
69- if os .path .exists (legacy_path ):
70- symlinks_to_uninstall .append (dict (name = package , link = legacy_path ))
66+ # Handle legacy install location
67+ # This does not always work,
68+ # and especially not in cases where it is in any case not necessary :)
69+ if ipylib_path :
70+ legacy_path = os .path .join (ipylib_path , package )
71+ if os .path .exists (legacy_path ):
72+ symlinks_to_uninstall .append (dict (name = package , link = legacy_path ))
7173
72- symlinks = [ link [ 'link' ] for link in symlinks_to_uninstall ]
73- uninstall_results = compas . _os . remove_symlinks ( symlinks )
74+ if not symlinks_to_uninstall :
75+ print ( ' \n No packages to uninstall.' )
7476
75- uninstalled_packages = []
76- for uninstall_data , success in zip (symlinks_to_uninstall , uninstall_results ):
77- if success :
78- uninstalled_packages .append (uninstall_data ['name' ])
79- result = 'OK'
80- else :
81- result = 'ERROR: Cannot remove symlink, try to run as administrator.'
82- results .append ((uninstall_data ['name' ], result ))
77+ else :
78+ uninstalled_packages = []
8379
84- if not all (uninstall_results ):
85- exit_code = - 1
80+ symlinks = [link ['link' ] for link in symlinks_to_uninstall ]
81+ uninstall_results = compas ._os .remove_symlinks (symlinks )
82+
83+ for uninstall_data , success in zip (symlinks_to_uninstall , uninstall_results ):
84+ if success :
85+ uninstalled_packages .append (uninstall_data ['name' ])
86+ result = 'OK'
87+ else :
88+ result = 'ERROR: Cannot remove symlink, try to run as administrator.'
89+
90+ results .append ((uninstall_data ['name' ], result ))
91+
92+ if not all (uninstall_results ):
93+ exit_code = - 1
94+
95+ if exit_code == - 1 :
96+ results .append (('compas_bootstrapper' , 'WARNING: One or more packages failed, will not uninstall bootstrapper.' ))
8697
87- if exit_code == - 1 :
88- results .append (('compas_bootstrapper' , 'WARNING: One or more packages failed, will not uninstall bootstrapper.' ))
89- else :
90- if compas_rhino ._try_remove_bootstrapper (scripts_path ):
91- results .append (('compas_bootstrapper' , 'OK' ))
9298 else :
93- results .append (('compas_bootstrapper' , 'ERROR: Cannot remove compas_bootstrapper, try to run as administrator.' ))
99+ if compas_rhino ._try_remove_bootstrapper (scripts_path ):
100+ results .append (('compas_bootstrapper' , 'OK' ))
101+ else :
102+ results .append (('compas_bootstrapper' , 'ERROR: Cannot remove compas_bootstrapper, try to run as administrator.' ))
94103
95- if not compas_rhino ._try_remove_bootstrapper (ipylib_path ):
96- results .append (('compas_bootstrapper' , 'ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.' ))
104+ # Handle legacy bootstrapper
105+ # Again, only if possible...
106+ if ipylib_path :
107+ if not compas_rhino ._try_remove_bootstrapper (ipylib_path ):
108+ results .append (('compas_bootstrapper' , 'ERROR: Cannot remove legacy compas_bootstrapper, try to run as administrator.' ))
97109
98- for package , status in results :
99- print (' {} {}' .format (package .ljust (20 ), status ))
110+ print ('\n The following packages have been detected and will be uninstalled:\n ' )
100111
101- if status != 'OK' :
102- exit_code = - 1
112+ for package , status in results :
113+ print ( ' {} {}' . format ( package . ljust ( 20 ), status ))
103114
104- if exit_code == 0 and len (uninstalled_packages ):
105- print ()
106- print ('Running post-uninstallation steps...' )
107- print ()
108- if not _run_post_execution_steps (after_rhino_uninstall (uninstalled_packages )):
109- exit_code = - 1
115+ if status != 'OK' :
116+ exit_code = - 1
117+
118+ if exit_code == 0 and uninstalled_packages :
119+ print ('\n Running post-uninstallation steps...\n ' )
120+
121+ if not _run_post_execution_steps (after_rhino_uninstall (uninstalled_packages )):
122+ exit_code = - 1
110123
111124 print ('\n Uninstall completed.' )
125+
112126 if exit_code != 0 :
113127 sys .exit (exit_code )
114128
@@ -131,13 +145,14 @@ def _filter_installed_packages(version, packages):
131145 packages = list (itertools .chain .from_iterable (installable_rhino_packages ()))
132146
133147 # Handle legacy install
134- legacy_bootstrapper = compas_rhino ._get_bootstrapper_path (ipylib_path )
135- if os .path .exists (legacy_bootstrapper ):
136- bootstrapper_data = compas_rhino ._get_bootstrapper_data (legacy_bootstrapper )
137- legacy_packages = bootstrapper_data .get ('INSTALLED_PACKAGES' , None )
138-
139- if legacy_packages :
140- packages .extend (legacy_packages )
148+ if ipylib_path :
149+ legacy_bootstrapper = compas_rhino ._get_bootstrapper_path (ipylib_path )
150+ if os .path .exists (legacy_bootstrapper ):
151+ bootstrapper_data = compas_rhino ._get_bootstrapper_data (legacy_bootstrapper )
152+ legacy_packages = bootstrapper_data .get ('INSTALLED_PACKAGES' , None )
153+
154+ if legacy_packages :
155+ packages .extend (legacy_packages )
141156
142157 return packages
143158
0 commit comments