from BuildManager.fileutil import * from BuildManager.package import * from BuildManager import * import os class PackageCleaner: def __init__(self, opts): self.opts = opts def run(self): pkglist = PackageList() pkglist_check = PackageList() logger.info("creating package list") for filename in self.opts.args: pkglist.append(Package(filename)) if self.opts.check: for dir in self.opts.check: logger.info("creating package check list for "+dir) for entry in os.listdir(dir): entrypath = os.path.join(dir, entry) if os.path.isfile(entrypath): pkglist_check.append(Package(entrypath)) logger.info("processing package list") for pkg in pkglist[:]: if pkglist.has_gt(pkg) or pkglist_check.has_gt(pkg): pkglist.remove(pkg) if self.opts.move: move_file(pkg.file, self.opts.move, dryrun=self.opts.dryrun) elif self.opts.copy: copy_file(pkg.file, self.opts.copy, dryrun=self.opts.dryrun) else: logger.info("removing "+pkg.file) if not self.opts.dryrun: os.unlink(pkg.file) return True