CVS: src/si/extras entitycheck.py,1.22,1.23
Mats Wichmann <[email protected]>
| Newsgroups | gmane.linux.lsb.implementation |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/lsb/src/si/extras
In directory sc8-pr-cvs1:/tmp/cvs-serv31061
Modified Files:
entitycheck.py
Log Message:
Spit-n-polish (hopefully no functional changes)
Index: entitycheck.py
===================================================================
RCS file: /cvsroot/lsb/src/si/extras/entitycheck.py,v
retrieving revision 1.22
retrieving revision 1.23
diff -C2 -r1.22 -r1.23
*** entitycheck.py 10 Jan 2003 17:50:27 -0000 1.22
--- entitycheck.py 10 Jan 2003 18:45:36 -0000 1.23
***************
*** 41,47 ****
def usage(code, msg=''):
print __doc__ % (entity_file, package_path, patch_path, md5sum_file,
update_file, fallback_url)
- if msg: print msg
sys.exit(code)
--- 41,47 ----
def usage(code, msg=''):
+ if msg: print "ERROR:", msg; print
print __doc__ % (entity_file, package_path, patch_path, md5sum_file,
update_file, fallback_url)
sys.exit(code)
***************
*** 91,96 ****
"""
self.message = "not found"
for loc in locations:
- self.front = "%s ->" % self.name
if self.name != loc.name: continue
pkgpath = "%s/%s" % (destination, self.file)
--- 91,96 ----
"""
self.message = "not found"
+ self.front = "%s ->" % self.name
for loc in locations:
if self.name != loc.name: continue
pkgpath = "%s/%s" % (destination, self.file)
***************
*** 102,106 ****
loc.path, destination)
self.running_output()
! print
self.message = "skipped"
break
--- 102,106 ----
loc.path, destination)
self.running_output()
! print # line break so previous message isn't overwritten
self.message = "skipped"
break
***************
*** 118,124 ****
break
except IOError:
if os.path.exists(pkgpath): os.remove(pkgpath)
! else: # if we didn't "break" out of loop, fetch failed
! self.message = "retrieval failed"
break
--- 118,126 ----
break
except IOError:
+ # if it dies, remove the partial file
if os.path.exists(pkgpath): os.remove(pkgpath)
!
! # if we didn't "break" out of inner loop, the fetch failed
! else: self.message = "retrieval failed"
break
***************
*** 140,144 ****
entities = open(entity_file)
except IOError, message:
! usage(1, 'Cannot open entity file <%s>' % entity_file)
packages = []
--- 142,146 ----
entities = open(entity_file)
except IOError, message:
! usage(1, 'Cannot open entity file: \n\t%s' % message)
packages = []
***************
*** 164,168 ****
self.alternate = alternate
! def parse_locations(file):
"""Parse the locations file. Returns a list of package
location instances.
--- 166,170 ----
self.alternate = alternate
! def parse_locations():
"""Parse the locations file. Returns a list of package
location instances.
***************
*** 175,179 ****
# in one place over time (e.g., if it moves to an "old" directory
# when a new version is released)
! package_file = open(file)
locations = []
for line in package_file.readlines():
--- 177,186 ----
# in one place over time (e.g., if it moves to an "old" directory
# when a new version is released)
!
! try:
! package_file = open(update_file)
! except IOError, message:
! usage(1, 'Cannot open locations file: \n\t%s' % message)
!
locations = []
for line in package_file.readlines():
***************
*** 235,238 ****
--- 242,248 ----
def dump_coll(collection, msg):
+ """Print a collection: use msg and a count to print a header,
+ then print the file member of each item.
+ """
if collection:
print msg, len(collection)
***************
*** 270,274 ****
"""Generate file fetch report.
Global "noisy" controls whether there's any output
! Return non-zero on fatal error (missing files or bad sums)
"""
# "fetch" report split from regular report because we want report
--- 280,284 ----
"""Generate file fetch report.
Global "noisy" controls whether there's any output
! Return non-zero on fatal error (failed retrievals).
"""
# "fetch" report split from regular report because we want report
***************
*** 283,314 ****
return 0
! def readmd5(md5sum_file):
"""Read and parse a checksum file.
Returns a dictionary of sums indexed by filename.
"""
try:
! f = open(md5sum_file)
except IOError, message:
! print "%s: %s" % (sys.argv[0], message)
! print "checksum file not found, quitting"
! sys.exit(1)
checksums = {}
! for line in f.readlines():
(sum, name) = string.split(line)
checksums[name] = sum
return checksums
def writemd5(collection):
! """Generate a new checksum file from checksums saved in entities
! """
! f = open(md5sum_file, 'w')
if noisy: print "writing checksums to", md5sum_file
for entity in collection:
! f.write("%s %s\n" % (entity.md5sum, entity.file))
def retrieve_packages(missing_packages):
! """Retrieve packages identified as missing.
! """
! locations = parse_locations(update_file)
retrieved = 0
fails, missing = [], []
--- 293,323 ----
return 0
! def readmd5():
"""Read and parse a checksum file.
Returns a dictionary of sums indexed by filename.
"""
try:
! sums = open(md5sum_file)
except IOError, message:
! usage(1, 'Cannot open checksum file: \n\t%s' % message)
!
checksums = {}
! for line in sums.readlines():
(sum, name) = string.split(line)
checksums[name] = sum
+ sums.close()
return checksums
def writemd5(collection):
! """Generate a new checksum file from checksums saved in entities. """
! sums = open(md5sum_file, 'w')
if noisy: print "writing checksums to", md5sum_file
for entity in collection:
! sums.write("%s %s\n" % (entity.md5sum, entity.file))
! sums.close()
def retrieve_packages(missing_packages):
! """Retrieve packages identified as missing."""
! locations = parse_locations()
retrieved = 0
fails, missing = [], []
***************
*** 360,367 ****
--- 369,378 ----
usage(1, "Path to packages <%s> is invalid" % patch_path)
+ # 3. Parse the entity file and see if those entities exist
packages, patches = parse_entities()
found_packages, missing_packages = check_missing(package_path, packages)
found_patches, missing_patches = check_missing(patch_path, patches)
+ # 4. Scan the package and patch directories for extra files
if package_path == patch_path:
extras = check_extra(package_path, found_packages + found_patches)
***************
*** 370,375 ****
extras = extras + check_extra(patch_path, found_patches)
if check_sums:
! checksums = readmd5(md5sum_file)
bad_packages, no_packages = check_checksums(found_packages, checksums)
bad_patches, no_patches = check_checksums(found_patches, checksums)
--- 381,388 ----
extras = extras + check_extra(patch_path, found_patches)
+ # 5. check checksums, if requested
+ # Whether doing sums or not, generate a report of the work to date
if check_sums:
! checksums = readmd5()
bad_packages, no_packages = check_checksums(found_packages, checksums)
bad_patches, no_patches = check_checksums(found_patches, checksums)
***************
*** 383,387 ****
missing_packages, missing_patches, extras)
! # go fetch files if needed
if fetch_files:
retrieved = 0
--- 396,400 ----
missing_packages, missing_patches, extras)
! # 6. Go fetch missing files if requested, and do another report
if fetch_files:
retrieved = 0
***************
*** 399,403 ****
exitcode = exitcode + fetch_report(retrieved, fails, missing)
! # quit non-zero if any entities were missing
if exitcode:
if generate_sums:
--- 412,417 ----
exitcode = exitcode + fetch_report(retrieved, fails, missing)
! # 7. Quit non-zero if anything failed - missing entities, or
! # failed retrievals, etc.
if exitcode:
if generate_sums:
***************
*** 405,409 ****
sys.exit(exitcode)
! # if no errors, it's okay to go ahead and generate the new checksum file
if generate_sums:
writemd5(found_packages + found_patches)
--- 419,424 ----
sys.exit(exitcode)
! # 8. Generate a new checksum file, if requested (only if nothing fatal
! # happened above)
if generate_sums:
writemd5(found_packages + found_patches)