CVS: src/si/extras entitycheck.py,1.15,1.16

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-serv27184

Modified Files:
	entitycheck.py 
Log Message:
Separate bad-checksum packages from patches
Clean up printing of details


Index: entitycheck.py
===================================================================
RCS file: /cvsroot/lsb/src/si/extras/entitycheck.py,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -r1.15 -r1.16
*** entitycheck.py	7 Jan 2003 02:39:44 -0000	1.15
--- entitycheck.py	7 Jan 2003 04:28:15 -0000	1.16
***************
*** 104,112 ****
          self.name = name
          self.file = file
- 	#print "DBG: entity(%s, %s, %s)" % (name, file)
  
      def domd5(self):
! 	"""Generate md5sum for this entity's filename, and save
! 	"""
  	f = open(self.fullpath, "rb")
  	sum = md5.new()
--- 104,110 ----
          self.name = name
          self.file = file
  
      def domd5(self):
! 	"""Generate md5sum for this entity's filename, and save"""
  	f = open(self.fullpath, "rb")
  	sum = md5.new()
***************
*** 121,124 ****
--- 119,127 ----
  
      def fetch(self, locations, file, fallback, destination):
+ 	"""retrieve a missing or bad file.
+ 	Calls urllib.urlretrieve() up to three times to retrieve to
+ 	destination from 1. main location, 2. alternate (if any),
+ 	3. fallback location
+ 	"""
  	global initial_text
  	for loc in locations:
***************
*** 190,194 ****
  	self.path = path
  	self.alternate = alternate
- 	#print "DBG: location(%s, %s, %s)" % (name, path, alternate)
  
  def parse_locations(file):
--- 193,196 ----
***************
*** 222,247 ****
      found = []
      missing = []
!     for entity in collection:
          # save fullpath in the entity instance since we'll use it again
!         entity.fullpath = os.path.join(path, entity.file)
!         if not os.path.exists(entity.fullpath):
!             missing.append(entity)
          else:
              if check_sums or generate_sums:
!                 entity.domd5()
!             found.append(entity)
      return (found, missing)
  
  def check_extra(path, collection):
!     """Check for files in a path that are not present in the collection.
!     Returns a list of filenames.
      """
      notfound = []
      paths = {}
!     for entity in collection:
!         paths[entity.file] = entity
      for file in os.listdir(path):
          if file not in paths.keys():
!             notfound.append(file)
      return notfound
  
--- 224,249 ----
      found = []
      missing = []
!     for item in collection:
          # save fullpath in the entity instance since we'll use it again
!         item.fullpath = os.path.join(path, item.file)
!         if not os.path.exists(item.fullpath):
!             missing.append(item)
          else:
              if check_sums or generate_sums:
!                 item.domd5()
!             found.append(item)
      return (found, missing)
  
  def check_extra(path, collection):
!     """Check for files in a path that are not described by entities.
!     Returns a list of dummy entities, with only the file attribute defined
      """
      notfound = []
      paths = {}
!     for item in collection:
!         paths[item.file] = item
      for file in os.listdir(path):
          if file not in paths.keys():
!             notfound.append(entity(None, file))
      return notfound
  
***************
*** 260,299 ****
      return badsums
  
! def report(found_pkg, found_pat, missing_pkg, missing_pat, extras, badsums):
!     """Generate final package/patch/checksum report.
      Global "noisy" controls whether there's any output
!     Return non-zero on fatal error (missing files, bad sums)
      """
-     errors = 0
      if noisy:
!         print "Package entities found:", len(found_pkg)
!         print "Patch entities found:", len(found_pat)
! 
!     if badsums:
!         errors = errors + 1
!         if noisy: 
!             print "Files with bad checksums:"
!             for item in badsums:
!                 print "\t", item.file
!     if missing_pkg:
!         errors = errors + 1
!         if noisy: 
!             print "Packages not found:"
!             for item in missing_pkg:
!                 print "\t", item.file
!     if missing_pat:
!         errors = errors + 1
!         if noisy: 
!             print "Patches not found:"
!             for item in missing_pat:
!                 print "\t", item.file
!     if extras:
!         if noisy:
!             # extras is a list of strings, not of entities
!             print "Files not used:"
!             for item in extras:
!                 print "\t", item
  
!     return errors
  
  def readmd5(md5sum_file):
--- 262,290 ----
      return badsums
  
! def dump_coll(collection, msg):
!     if collection:
! 	print msg, len(collection)
! 	for item in collection:
! 	    print "\t", item.file
! 
! def report(fnd_pkg, fnd_pat, miss_pkg, miss_pat, extras, bad_pkg, bad_pat):
!     """Generate package/patch/checksum report.
      Global "noisy" controls whether there's any output
!     Return non-zero on fatal error (missing files or bad sums)
      """
      if noisy:
!         print "Package entities found:", len(fnd_pkg)
!         print "Patch entities found:", len(fnd_pat)
  
!     if noisy:
! 	dump_coll(miss_pkg, "Packages not found:")
! 	dump_coll(miss_pat, "Patches not found:")
! 	dump_coll(bad_pkg, "Bad packages:")
! 	dump_coll(bad_pat, "Bad patches:")
! 	dump_coll(extras, "Files not in use:")
!     if miss_pkg or miss_pat or bad_pkg or bad_pat:
! 	return 1
!     else:
!     	return 0
  
  def readmd5(md5sum_file):
***************
*** 301,305 ****
      Returns a dictionary of sums indexed by filename.
      """
-     if noisy: print "Checking checksums against", md5sum_file
      try:
          f = open(md5sum_file)
--- 292,295 ----
***************
*** 324,329 ****
  def retrieve_packages(missing_packages, file, fallback, destination):
      """Retrieve packages identified as missing.
-     Calls urllib.urlretrieve() up to three times to retrieve from:
-     1. main location, 2. alternate (if any), 3. fallback location
      """
      locations = parse_locations(file)
--- 314,317 ----
***************
*** 344,348 ****
  # Main program:
  if noisy:
!     print 'entitycheck: entities %s, packages from %s, patches from %s' % (entity_file, package_path, patch_path)
  
  if not os.path.isdir(package_path):
--- 332,340 ----
  # Main program:
  if noisy:
!     print 'Checking entities from', entity_file
!     print 'Checking packages from', package_path
!     print 'Checking patches from', patch_path
!     if check_sums:
! 	print "Checking checksums against", md5sum_file
  
  if not os.path.isdir(package_path):
***************
*** 362,378 ****
      extras = extras + check_extra(patch_path, found_patches)
  
  if check_sums:
      checksums = readmd5(md5sum_file)
!     badsums = check_checksums(found_packages + found_patches, checksums)
! else:
!     badsums = None
  
  exitcode = report(found_packages, found_patches, 
!                   missing_packages, missing_patches, extras, badsums)
  
  # go fetch files if needed
  # note: this will try to fetch patches with bad sums, which will fail (for now)
! if fetch_files and badsums:
!     retrieve_packages(badsums, update_file, fallback_url, package_path)
  if fetch_files and missing_packages:
      retrieve_packages(missing_packages, update_file, fallback_url, package_path)
--- 354,371 ----
      extras = extras + check_extra(patch_path, found_patches)
  
+ bad_packages = bad_patches = None
  if check_sums:
      checksums = readmd5(md5sum_file)
!     bad_packages = check_checksums(found_packages, checksums)
!     bad_patches = check_checksums(found_patches, checksums)
  
  exitcode = report(found_packages, found_patches, 
!                   missing_packages, missing_patches, extras,
! 		  bad_packages, bad_patches)
  
  # go fetch files if needed
  # note: this will try to fetch patches with bad sums, which will fail (for now)
! if fetch_files and bad_packages:
!     retrieve_packages(bad_packages, update_file, fallback_url, package_path)
  if fetch_files and missing_packages:
      retrieve_packages(missing_packages, update_file, fallback_url, package_path)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.