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:
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:
help="move to <destination> instead of removing the file")
parser.add_option ("-o","--offset",dest='offset',action='store',type='int',default=0,
help="pretend we run <offset> 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:
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__':