From: Ciro Scognamiglio Date: Thu, 12 Jul 2012 15:00:53 +0000 (+0200) Subject: added -s|--summary, will print a short summary and then exit X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=70d0fed095397aa26c1dc26cb56ffe8533b788b7;p=infrastructure.git added -s|--summary, will print a short summary and then exit --- diff --git a/scripts/clean-backupdb.py b/scripts/clean-backupdb.py index 4fcbb06..ab15ddf 100755 --- a/scripts/clean-backupdb.py +++ b/scripts/clean-backupdb.py @@ -151,19 +151,20 @@ class File: def cleanup (self, preserved): global counter counter+=1 + src = os.path.abspath(os.path.basename(self.path())); if self.options.destination: dst = os.path.abspath(self.options.destination) + '/' + os.path.basename(self.path()) if self.options.verbose: print "moving %s\n\tto %s"%(self.path(), dst) if not self.options.dry_run: - os.rename (self.path(), dst) + os.rename (src, dst) else: - if self.options.dry_run: - print "Would cleanup %s"%(self.path()) + if self.options.verbose: + print "Would cleanup %s"%(src) print " (keeping %s)"%preserved.path() - else: - if self.options.verbose: print "unlink",self.path() - os.unlink (self.path()) + if not self.options.dry_run: + if self.options.verbose: print "unlink",src + os.unlink (src) # all files in a given timeslot (either month or week) class Group: @@ -282,7 +283,13 @@ class Index: self.insert (dir, filename, p, s, d) def cleanup (self): - for kind in self.index.values(): kind.cleanup() + for kind in self.index.values(): + kind.cleanup() + + def summary (self): + print "%-30s%-10s%s"%("Prefix","Suffix","Num") + for kind in self.index.values(): + print "%-30s%-10s%3s"%(kind.prefix, kind.suffix, len(kind.list)) def handle_dir_pattern (index, dir, pattern): try: @@ -306,6 +313,8 @@ def main (): help="move to instead of removing the file") parser.add_option ("-o","--offset",dest='offset',action='store',type='int',default=0, help="pretend we run days in the future") + parser.add_option ("-s","--summary",dest='summary',action='store_true',default=False, + help="print a summary then exit") (options, args) = parser.parse_args() if options.extra_verbose: options.verbose=True try: @@ -342,7 +351,10 @@ def main (): for (dir, pattern) in dir_patterns: handle_dir_pattern (index, dir, pattern) index.epilogue() index.show() - index.cleanup() + if (options.summary) : + index.summary() + else: + index.cleanup() print 'Found %d entries to unlink'%counter if __name__ == '__main__':