image-minimizer: Fix argument parsing
Can't pass metavar to args that are just switches.
This commit is contained in:
parent
b91e79d9bc
commit
f616d37f59
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# image-minimizer: removes files and packages on the filesystem
|
# image-minimizer: removes files and packages on the filesystem
|
||||||
#
|
#
|
||||||
# Copyright 2007-2015 Red Hat, Inc.
|
# Copyright 2007-2016 Red Hat, Inc.
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
@ -70,7 +70,7 @@ class ImageMinimizer:
|
|||||||
not_found = True
|
not_found = True
|
||||||
for hdr in mi:
|
for hdr in mi:
|
||||||
not_found = False
|
not_found = False
|
||||||
rpms.add(hdr['name'])
|
rpms.add(hdr['name'].decode("utf8"))
|
||||||
if self.verbose and not_found:
|
if self.verbose and not_found:
|
||||||
print("%s package not found" % pattern)
|
print("%s package not found" % pattern)
|
||||||
|
|
||||||
@ -115,36 +115,30 @@ class ImageMinimizer:
|
|||||||
if os.path.isdir(tag):
|
if os.path.isdir(tag):
|
||||||
self.visited.add(tag)
|
self.visited.add(tag)
|
||||||
else:
|
else:
|
||||||
if self.dryrun:
|
if self.dryrun or self.verbose:
|
||||||
print('rm ' + tag)
|
print("rm %s" % tag)
|
||||||
else:
|
if not self.dryrun:
|
||||||
if self.verbose:
|
|
||||||
print('rm ' + tag)
|
|
||||||
os.remove(tag)
|
os.remove(tag)
|
||||||
|
|
||||||
#remove all empty directory. Every 8k counts!
|
#remove all empty directory. Every 8k counts!
|
||||||
for d in sorted(self.visited, reverse=True):
|
for d in sorted(self.visited, reverse=True):
|
||||||
if len(os.listdir(d)) == 0:
|
if len(os.listdir(d)) == 0:
|
||||||
if self.dryrun:
|
if self.dryrun or self.verbose:
|
||||||
print('rm -rf ' + d)
|
print("rm -rf %s" % d)
|
||||||
else:
|
if not self.dryrun:
|
||||||
if self.verbose:
|
|
||||||
print('rm -rf ' + d)
|
|
||||||
os.rmdir(d)
|
os.rmdir(d)
|
||||||
|
|
||||||
def remove_rpm(self):
|
def remove_rpm(self):
|
||||||
|
|
||||||
def runCallback(reason, amount, total, key, client_data):
|
def runCallback(reason, amount, total, key, client_data):
|
||||||
if self.verbose and reason == rpm.RPMCALLBACK_UNINST_STOP:
|
if self.verbose and reason == rpm.RPMCALLBACK_UNINST_STOP:
|
||||||
print(key, "erased")
|
print("%s erased" % key)
|
||||||
|
|
||||||
if len(self.drops_rpm) == 0:
|
if len(self.drops_rpm) == 0:
|
||||||
return
|
return
|
||||||
|
|
||||||
for pkg in self.drops_rpm:
|
for pkg in self.drops_rpm:
|
||||||
if self.dryrun:
|
if self.verbose:
|
||||||
print("erasing ", pkg)
|
print("erasing: %s " % pkg)
|
||||||
else:
|
|
||||||
self.ts.addErase(pkg)
|
self.ts.addErase(pkg)
|
||||||
if not self.dryrun:
|
if not self.dryrun:
|
||||||
# skip ts.check(), equivalent to --nodeps
|
# skip ts.check(), equivalent to --nodeps
|
||||||
@ -166,10 +160,10 @@ def parse_options():
|
|||||||
help="Root path to prepend to all file patterns and installation root for RPM "
|
help="Root path to prepend to all file patterns and installation root for RPM "
|
||||||
"operations. Defaults to INSTALL_ROOT or /mnt/sysimage/")
|
"operations. Defaults to INSTALL_ROOT or /mnt/sysimage/")
|
||||||
|
|
||||||
parser.add_argument("--dryrun", metavar="BOOL", action="store_true", dest="dryrun",
|
parser.add_argument("--dryrun", action="store_true", dest="dryrun",
|
||||||
help="If set, no filesystem changes are made.")
|
help="If set, no filesystem changes are made.")
|
||||||
|
|
||||||
parser.add_argument("-v", "--verbose", metavar="BOOL", action="store_true", dest="verbose",
|
parser.add_argument("-v", "--verbose", action="store_true", dest="verbose",
|
||||||
help="Display every action as it is performed.")
|
help="Display every action as it is performed.")
|
||||||
|
|
||||||
parser.add_argument("filename", metavar="STRING", help="Filename to process")
|
parser.add_argument("filename", metavar="STRING", help="Filename to process")
|
||||||
@ -186,7 +180,7 @@ def main():
|
|||||||
except SystemExit as e:
|
except SystemExit as e:
|
||||||
sys.exit(e.code)
|
sys.exit(e.code)
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
print("Aborted at user request", file=sys.stderr)
|
print("Aborted at user request")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user