@@ -146,7 +146,11 @@ def tarball_filename(self):
146146
147147 String. The full-qualified tarball filename.
148148 """
149- return self .tarball_pattern .replace ('VERSION' , self .version )
149+ pattern = self .tarball_pattern
150+ if pattern :
151+ return self .tarball_pattern .replace ('VERSION' , self .version )
152+ else :
153+ return None
150154
151155 @property
152156 def tarball_upstream_url_pattern (self ):
@@ -236,8 +240,8 @@ def all(cls):
236240 base = os .path .join (SAGE_ROOT , 'build' , 'pkgs' )
237241 for subdir in os .listdir (base ):
238242 path = os .path .join (base , subdir )
239- if not os .path .isfile (os .path .join (path , "checksums.ini " )):
240- log .debug ('%s has no checksums.ini ' , subdir )
243+ if not os .path .isfile (os .path .join (path , "type " )):
244+ log .debug ('%s has no type ' , subdir )
241245 continue
242246 try :
243247 yield cls (subdir )
@@ -251,46 +255,60 @@ def path(self):
251255 Return the package directory
252256 """
253257 return os .path .join (SAGE_ROOT , 'build' , 'pkgs' , self .name )
254-
258+
259+ def has_file (self , filename ):
260+ """
261+ Return whether the file exists in the package directory
262+ """
263+ return os .path .exists (os .path .join (self .path , filename ))
264+
255265 def _init_checksum (self ):
256266 """
257267 Load the checksums from the appropriate ``checksums.ini`` file
258268 """
259269 checksums_ini = os .path .join (self .path , 'checksums.ini' )
260270 assignment = re .compile ('(?P<var>[a-zA-Z0-9_]*)=(?P<value>.*)' )
261271 result = dict ()
262- with open (checksums_ini , 'rt' ) as f :
263- for line in f .readlines ():
264- match = assignment .match (line )
265- if match is None :
266- continue
267- var , value = match .groups ()
268- result [var ] = value
272+ try :
273+ with open (checksums_ini , 'rt' ) as f :
274+ for line in f .readlines ():
275+ match = assignment .match (line )
276+ if match is None :
277+ continue
278+ var , value = match .groups ()
279+ result [var ] = value
280+ except IOError :
281+ pass
269282 self .__md5 = result .get ('md5' , None )
270283 self .__sha1 = result .get ('sha1' , None )
271284 self .__cksum = result .get ('cksum' , None )
272- self .__tarball_pattern = result [ 'tarball' ]
285+ self .__tarball_pattern = result . get ( 'tarball' , None )
273286 self .__tarball_upstream_url_pattern = result .get ('upstream_url' , None )
274287 # Name of the directory containing the checksums.ini file
275288 self .__tarball_package_name = os .path .realpath (checksums_ini ).split (os .sep )[- 2 ]
276289
277290 VERSION_PATCHLEVEL = re .compile ('(?P<version>.*)\.p(?P<patchlevel>[0-9]+)' )
278291
279292 def _init_version (self ):
280- with open ( os . path . join ( self . path , 'package-version.txt' )) as f :
281- package_version = f . read (). strip ()
282- match = self . VERSION_PATCHLEVEL . match ( package_version )
283- if match is None :
284- self .__version = package_version
285- self .__patchlevel = - 1
293+ try :
294+ with open ( os . path . join ( self . path , 'package-version.txt' )) as f :
295+ package_version = f . read (). strip ( )
296+ except IOError :
297+ self .__version = None
298+ self .__patchlevel = None
286299 else :
287- self .__version = match .group ('version' )
288- self .__patchlevel = int (match .group ('patchlevel' ))
289-
300+ match = self .VERSION_PATCHLEVEL .match (package_version )
301+ if match is None :
302+ self .__version = package_version
303+ self .__patchlevel = - 1
304+ else :
305+ self .__version = match .group ('version' )
306+ self .__patchlevel = int (match .group ('patchlevel' ))
307+
290308 def _init_type (self ):
291309 with open (os .path .join (self .path , 'type' )) as f :
292310 package_type = f .read ().strip ()
293311 assert package_type in [
294- 'base' , 'standard' , 'optional' , 'experimental' , 'script' , 'pip'
312+ 'base' , 'standard' , 'optional' , 'experimental'
295313 ]
296314 self .__type = package_type
0 commit comments