@@ -143,30 +143,9 @@ def searchPathsForComponent(name, version_required, search_paths):
143
143
return local_component
144
144
return None
145
145
146
- def satisfyVersion (
147
- name ,
148
- version_required ,
149
- available ,
150
- search_paths ,
151
- working_directory ,
152
- update_installed = None
153
- ):
154
- ''' returns a Component for the specified version (either to an already
155
- installed copy (from the available list, or from disk), or to a newly
156
- downloaded one), or None if the version could not be satisfied.
157
146
158
- update_installed = {None, 'Check', 'Update'}
159
- None: prevent any attempt to look for new versions if the
160
- component already exists
161
- Check: check for new versions, and pass new version information to
162
- the component object
163
- Update: replace any existing version with the newest available, if
164
- the newest available has a higher version
165
- '''
166
-
147
+ def satisfyVersionFromAvailble (name , version_required , available ):
167
148
spec = None
168
- v = None
169
-
170
149
if name in available :
171
150
logger .debug ('satisfy %s from already installed components' % name )
172
151
try :
@@ -181,31 +160,28 @@ def satisfyVersion(
181
160
r .getName (), name , r .path
182
161
))
183
162
return r
163
+ return None
184
164
165
+ def satisfyVersionFromSearchPaths (name , version_required , search_paths , update = False ):
166
+ ''' returns a Component for the specified version, if found in the list of
167
+ search paths. If `update' is True, then also check for newer versions
168
+ of the found component, and update it in-place (unless it was installed
169
+ via a symlink).
170
+ '''
171
+ spec = None
172
+ v = None
185
173
186
174
local_component = searchPathsForComponent (name , version_required , search_paths )
187
175
logger .debug ("%s %s locally" % (('found' , 'not found' )[not local_component ], name ))
188
- if local_component and (local_component .installedLinked () or update_installed != 'Update' ):
189
- logger .debug ("satisfy component from directory: %s" % local_component .path )
190
- # if a component exists (has a valid description file), and either is
191
- # not outdated, or we are not updating
192
- if name != local_component .getName ():
193
- raise Exception ('Component %s found in incorrectly named directory %s (%s)' % (
194
- local_component .getName (), name , local_component .path
195
- ))
196
- return local_component
197
-
198
- # if we need to check for latest versions, get the latest available version
199
- # before checking for a local component so that we can create the local
200
- # component with a handle to its latest available version
201
- if update_installed is not None :
202
- #logger.debug('attempt to check latest version of %s @%s...' % (name, version_required))
203
- v = latestSuitableVersion (name , version_required )
204
- if local_component :
205
- local_component .setLatestAvailable (v )
206
-
207
176
if local_component :
208
- if not local_component .outdated ():
177
+ if update and not local_component .installedLinked ():
178
+ #logger.debug('attempt to check latest version of %s @%s...' % (name, version_required))
179
+ v = latestSuitableVersion (name , version_required )
180
+ if local_component :
181
+ local_component .setLatestAvailable (v )
182
+
183
+ # if we don't need to update, then we're done
184
+ if local_component .installedLinked () or not local_component .outdated ():
209
185
logger .debug ("satisfy component from directory: %s" % local_component .path )
210
186
# if a component exists (has a valid description file), and either is
211
187
# not outdated, or we are not updating
@@ -214,27 +190,36 @@ def satisfyVersion(
214
190
local_component .getName (), name , local_component .path
215
191
))
216
192
return local_component
217
- elif local_component .outdated ():
218
- logger .info ('%soutdated: %s@%s -> %s' % (
219
- ('update ' if update_installed == 'Update' else '' ),
220
- name ,
221
- local_component .getVersion (),
222
- v
223
- ))
224
- # must rm the old component before continuing
225
- fsutils .rmRf (local_component .path )
193
+
194
+ # otherwise, we need to update the installed component
195
+ logger .info ('update outdated: %s@%s -> %s' % (
196
+ name ,
197
+ local_component .getVersion (),
198
+ v
199
+ ))
200
+ # must rm the old component before continuing
201
+ fsutils .rmRf (local_component .path )
202
+ return _satisfyVersionByInstallingVersion (name , version_required , local_component .path , v )
203
+ return None
226
204
227
- if not v and update_installed is None :
228
- v = latestSuitableVersion (name , version_required )
205
+ def satisfyVersionByInstalling (name , version_required , working_directory ):
206
+ ''' installs and returns a Component for the specified name+version
207
+ requirement, into a subdirectory of `working_directory'
208
+ '''
209
+ v = latestSuitableVersion (name , version_required )
210
+ install_into = os .path .join (working_directory , name )
211
+ return _satisfyVersionByInstallingVersion (name , version_required , install_into , v )
229
212
230
- if not v :
231
- raise access_common .ComponentUnavailable (
232
- 'Dependency "%s":"%s" is not a supported form.' % (name , version_required )
233
- )
234
- directory = os .path .join (working_directory , name )
213
+ def _satisfyVersionByInstallingVersion (name , version_required , working_directory , version ):
214
+ ''' installs and returns a Component for the specified version requirement into
215
+ 'working_directory' using the provided remote version object.
216
+ This function is not normally called via `satisfyVersionByInstalling',
217
+ which looks up a suitable remote version object.
218
+ '''
219
+ assert (version )
235
220
logger .info ('download ' + name )
236
- v .unpackInto (directory )
237
- r = component .Component (directory )
221
+ version .unpackInto (working_directory )
222
+ r = component .Component (working_directory )
238
223
if not r :
239
224
raise Exception (
240
225
'Dependency "%s":"%s" is not a valid component.' % (name , version_required )
@@ -245,6 +230,35 @@ def satisfyVersion(
245
230
))
246
231
return r
247
232
233
+ def satisfyVersion (
234
+ name ,
235
+ version_required ,
236
+ available ,
237
+ search_paths ,
238
+ working_directory ,
239
+ update_installed = None
240
+ ):
241
+ ''' returns a Component for the specified version (either to an already
242
+ installed copy (from the available list, or from disk), or to a newly
243
+ downloaded one), or None if the version could not be satisfied.
244
+
245
+ update_installed = None / 'Update'
246
+ None: prevent any attempt to look for new versions if the
247
+ component already exists
248
+ Update: replace any existing version with the newest available, if
249
+ the newest available has a higher version
250
+ '''
251
+
252
+ r = satisfyVersionFromAvailble (name , version_required , available )
253
+ if r is not None :
254
+ return r
255
+
256
+ r = satisfyVersionFromSearchPaths (name , version_required , search_paths , update_installed == 'Update' )
257
+ if r is not None :
258
+ return r
259
+
260
+ return satisfyVersionByInstalling (name , version_required , working_directory )
261
+
248
262
249
263
def satisfyTarget (name , version_required , working_directory , update_installed = None ):
250
264
''' returns a Target for the specified version (either to an already
0 commit comments