[Lsb-messages] /var/www/bzr/lsb/4.1/appbat r944: Add --delete-bad to entitycheck; deletes files with bad checksums (backport).
Jeff Licquia
licquia at linuxfoundation.org
Fri Mar 23 20:54:21 UTC 2012
------------------------------------------------------------
revno: 944
committer: Jeff Licquia <licquia at linuxfoundation.org>
branch nick: appbat
timestamp: Fri 2012-03-23 16:54:21 -0400
message:
Add --delete-bad to entitycheck; deletes files with bad checksums (backport).
modified:
extras/entitycheck.py
-------------- next part --------------
=== modified file 'extras/entitycheck.py'
--- a/extras/entitycheck.py 2011-03-22 21:44:57 +0000
+++ b/extras/entitycheck.py 2012-03-23 20:54:21 +0000
@@ -22,6 +22,7 @@
-d PATH, --patchpath=PATH -- use PATH for patches [%s]
-g, --gensum -- generate md5 sums for found entities
-c, --checksum -- check md5 sums against file
+--delete-bad -- delete files with bad checksums
-s FILE, --sumfile=FILE -- use md5sum file FILE [%s]
-f, --fetch -- fetch missing pkgs
--dryrun -- test what pkgs would be retrieved
@@ -60,6 +61,7 @@
dry_run = None
noisy = True
show_extras = None
+delete_bad = False
def usage(code, msg=''):
if msg: print "ERROR:", msg; print
@@ -88,6 +90,11 @@
s = sum.digest()
self.md5sum = "%02x"*len(s) % tuple(map(ord, s))
+ def delete_file(self):
+ """Delete this entity's file, if it exists"""
+ if self.fullpath and os.path.exists(self.fullpath):
+ os.unlink(self.fullpath)
+
def running_output(self):
"""Print running output of (front, message) using \b and \r tricks."""
if noisy:
@@ -445,12 +452,18 @@
print 'Error: cannot write to package directory "%s"' % package_path
return (retrieved, fails, missing)
+def delete_bad_checksums(collection):
+ if collection:
+ for item in collection:
+ print "Deleting " + item.file
+ item.delete_file()
+
## Main
# 1. Process command-line arguments
shortopts = 'qe:p:d:gcs:fu:z:wh'
longopts = ['quiet', 'entityfile=', 'packagepath=', 'patchpath=',
'gensum', 'checksum', 'sumfile=', 'fetch', 'updatefile=',
- 'dryrun', 'fallback=', 'wget', 'help', 'show-extras']
+ 'dryrun', 'fallback=', 'wget', 'help', 'show-extras', 'delete-bad']
try:
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
except getopt.error, msg:
@@ -481,6 +494,7 @@
if opt in ('--quiet', '-q'): noisy = False
if opt == '--show-extras':
show_extras = 'yes'
+ if opt == '--delete-bad': delete_bad = True
# 2. Check directories are okay up front
# also saves time to make sure the checksum file is there
@@ -536,14 +550,18 @@
# tell us what happened on the fetch
exitcode = fetch_report(retrieved, fails, missing)
-# 7. Quit non-zero if anything failed - missing entities, or
+# 7. Delete files with bad checksums if requested.
+if check_sums and delete_bad:
+ delete_bad_checksums(bad_packages + bad_patches)
+
+# 8. Quit non-zero if anything failed - missing entities, or
# failed retrievals, etc.
if exitcode:
if generate_sums:
print "Not writing checksum file, errors found"
sys.exit(exitcode)
-# 8. Generate a new checksum file, if requested (only if nothing fatal
+# 9. Generate a new checksum file, if requested (only if nothing fatal
# happened above)
if generate_sums:
writemd5(found_packages + found_patches)
More information about the lsb-messages
mailing list