@@ -59,37 +59,13 @@ def __init__(self, in_str, linefeed=True):
5959 else :
6060 raise TypeError ("JSONStreamLoads(): input must be of type \' str\' ." )
6161
62- if linefeed :
63- self ._load = self .loadsByLine ()
64- else :
65- self ._load = self .loadsByCharacter ()
62+ self ._load = self .loadAll ()
6663
67- def objects (self ):
64+ def load (self ):
6865 return self ._load
6966
70- def loadsByLine (self ):
71- out = []
72- buf = ''
73- for l in self ._buffer .splitlines ():
74- buf += l .strip ().strip ('\0 ' )
75- try :
76- out .append (json .loads (buf ))
77- buf = ''
78- except :
79- pass
80- return out
81-
82- def loadsByCharacter (self ):
83- out = []
84- buf = ''
85- for l in self ._buffer :
86- buf += l
87- try :
88- out .append (json .loads (buf .strip ().strip ('\0 ' )))
89- buf = ''
90- except :
91- pass
92- return out
67+ def loadAll (self ):
68+ return json .loads (self ._buffer )
9369
9470
9571# use conda to update to the latest package
@@ -107,8 +83,9 @@ def __init__(self, conda_prefix=ANACONDA_PREFIX, dry_run=False):
10783 super ().__init__ ()
10884 self ._dry_run = dry_run
10985 self ._conda_prefix = conda_prefix
110- self ._channel = 'gpi'
111- self ._packages = ['gpi' , 'gpi-core-nodes' , 'gpi-docs' ]
86+ self ._packages = ['gpi' , 'gpi_core' ]
87+ # DDB - No docs for now on c-f, restore later
88+ # self._packages = ['gpi', 'gpi_core', 'gpi-docs']
11289
11390 self ._packages_for_installation = []
11491 self ._packages_for_update = []
@@ -152,9 +129,9 @@ def _getStatus(self):
152129 # Check for the latest versions online
153130 for pkg in self ._packages :
154131 if self ._current_versions [pkg ] is None :
155- self ._latest_versions [pkg ] = self .updatePkg (pkg , self . _channel , dry_run = True , install = True )
132+ self ._latest_versions [pkg ] = self .updatePkg (pkg , dry_run = True , install = True )
156133 else :
157- self ._latest_versions [pkg ] = self .updatePkg (pkg , self . _channel , dry_run = True )
134+ self ._latest_versions [pkg ] = self .updatePkg (pkg , dry_run = True )
158135 pdone += step
159136 self ._status_pdone (pdone )
160137
@@ -184,6 +161,7 @@ def __str__(self):
184161 for pkg in self ._packages_for_update :
185162 o = self ._current_versions [pkg ]
186163 n = self ._latest_versions [pkg ]
164+ msg += pkg + '<br>'
187165 msg += tab + str (o ) + ' ➪ ' + str (n ) + '<br>'
188166
189167 # installs
@@ -193,11 +171,12 @@ def __str__(self):
193171 msg += 'The following packages will be installed:<br><br>'
194172 for pkg in self ._packages_for_installation :
195173 n = self ._latest_versions [pkg ]
174+ msg += pkg + '<br>'
196175 msg += tab + str (n ) + '<br>'
197176
198177 if self .numberOfUpdates ():
199178 msg += '<br><br>GPI will be <b>automatically restarted</b> after updating.' \
200- + ' Make sure your networks are saved before proceeding.'
179+ + ' Please make sure your networks are saved before proceeding.'
201180
202181 if msg == '' :
203182 msg = 'GPI is up to date.'
@@ -208,9 +187,13 @@ def statusMessage(self):
208187 return str (self )
209188
210189 def checkConda (self ):
211- cmd = self ._conda_prefix + '/bin/conda --version >/dev/null 2>&1'
190+ cmd_unix = 'conda --version >/dev/null 2>&1'
191+ cmd_win = 'conda --version > NUL'
212192 try :
213- subprocess .check_output (cmd , shell = True )
193+ if Specs .inWindows ():
194+ subprocess .check_output (cmd_win , shell = True )
195+ else :
196+ subprocess .check_output (cmd_unix , shell = True )
214197 except subprocess .CalledProcessError as e :
215198 print ('Failed to execute conda, aborting...' )
216199 print (e .cmd , e .output )
@@ -221,14 +204,15 @@ def checkConda(self):
221204 raise
222205
223206 def getInstalledPkgVersion (self , name ):
224- cmd = self . _conda_prefix + '/bin/ conda list --json'
207+ cmd = ' conda list --json'
225208 try :
226209 output = subprocess .check_output (cmd , shell = True ).decode ('utf8' )
227- conda = JSONStreamLoads (output ).objects ()[ - 1 ]
210+ conda = JSONStreamLoads (output ).load ()
228211 for pkg in conda :
229- m = re .match ('(' + name + ')-([0-9]+\.*[0-9]*\.*[0-9]*)-(.*)' , pkg )
212+ pkg_str = json .dumps (pkg )
213+ m = re .search (name + '-([0-9]+\.[0-9]+\.[0-9]+)-[^"]*' , pkg_str )
230214 if m :
231- return pkg
215+ return m [ 1 ]
232216 except :
233217 print ('Failed to retrieve installed package information on ' + name + ', skipping...' )
234218 print (cmd )
@@ -269,21 +253,21 @@ def _updateAllPkgs(self):
269253 # Install or update all the packages that have been determined.
270254 for pkg in self ._packages_for_installation :
271255 # if there is no package (due to user changes) then install it
272- self .updatePkg (pkg , self . _channel , install = True )
256+ self .updatePkg (pkg , install = True )
273257 pdone += step
274258 self ._updateAllPkgs_pdone (pdone )
275259 self .message .emit (message_hdr + pkg )
276260 for pkg in self ._packages_for_update :
277261 # if there is a latest version then update
278- self .updatePkg (pkg , self . _channel )
262+ self .updatePkg (pkg )
279263 pdone += step
280264 self ._updateAllPkgs_pdone (pdone )
281265 self .message .emit (message_hdr + pkg )
282266
283267 self ._updateAllPkgs_pdone (100 )
284268 self .message .emit ('Package updates complete. Relaunching...' )
285269
286- def updatePkg (self , name , channel , dry_run = False , install = False ):
270+ def updatePkg (self , name , dry_run = False , install = False ):
287271 # Updates to the latest package and returns the package string.
288272 # -dry_run will just return the latest package string.
289273 # -install will install the package if its not currently installed.
@@ -292,27 +276,42 @@ def updatePkg(self, name, channel, dry_run=False, install=False):
292276 if install : conda_sub = 'install'
293277 dry_cmd = ''
294278 if dry_run : dry_cmd = '--dry-run --no-deps'
295- cmd = self . _conda_prefix + '/bin/ conda '+ conda_sub + ' -c ' + channel + ' ' + name + ' -y --json ' + dry_cmd
279+ cmd = ' conda '+ conda_sub + ' ' + name + ' -y --json ' + dry_cmd
296280
297281 try :
298282 output = subprocess .check_output (cmd , shell = True ).decode ('utf8' )
299- conda = JSONStreamLoads (output ).objects ()
300- conda = conda [- 1 ]
301-
302- if conda ['success' ]:
303- if 'message' in conda : # if we're up to date
304- return
305- for pkg in conda ['actions' ]['LINK' ]:
306- if pkg .startswith (name ):
307- return pkg .split ()[0 ]
283+ if dry_run :
284+ conda = JSONStreamLoads (output ).load ()
285+
286+ if conda ['success' ]:
287+ if 'message' in conda : # if we're up to date
288+ return
289+ for pkg in conda ['actions' ]['LINK' ]:
290+ pkg_str = pkg ['dist_name' ]
291+ if pkg_str .startswith (name ):
292+ m = re .search ('-([0-9]+\.[0-9]+\.[0-9]+)-' , pkg_str )
293+ return m [1 ]
294+ else :
295+ raise RuntimeError ('conda returned a failure status.' )
308296 else :
309- raise RuntimeError ('conda returned a failure status.' )
297+ m = re .search ('\" success\" : true' , output )
298+ if m [0 ] is not None :
299+ print ("Successfully updated " ,name )
300+ else :
301+ print ("Update unsuccessful, even though a newer package was found." )
302+ print ("This is likely due to a dependency problem. Please create an" )
303+ print ("issue at https://github.com/conda-forge/gpi-feedstock " )
310304 except subprocess .CalledProcessError as e :
311- print ('Failed to update to new package, aborting...' )
305+ print ('Failed to update to new package. Please try again.' )
306+ print ('If the problem persists, create an issue at' )
307+ print ('https://github.com/conda-forge/gpi-feedstock' )
312308 print (e .cmd , e .output )
313309 raise
314310 except :
315- print ('Failed to retrieve package update information, aborting...' )
311+ print ('Failed to retrieve package update information.' )
312+ print ('This may be due to a network or package manager issue.' )
313+ print ('If the problem persists, create an issue at' )
314+ print ('https://github.com/conda-forge/gpi-feedstock' )
316315 print (cmd )
317316 raise
318317
0 commit comments