summaryrefslogtreecommitdiffstats
path: root/BuildManager/clean.py
blob: e0e3f9398c67f4468fd529d3e6469908ac14510c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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