diff options
author | Marius Mauch <genone@gentoo.org> | 2008-09-25 15:25:27 +0000 |
---|---|---|
committer | Marius Mauch <genone@gentoo.org> | 2008-09-25 15:25:27 +0000 |
commit | 0467e091671d015b390083a9b8c95b36087aefa9 (patch) | |
tree | f709bb3d782d04d0ff2a9bb396646973e60f3965 | |
parent | a9c43e00915ed2eb0ebf47227403c3235b164c5a (diff) | |
download | portage-0467e091671d015b390083a9b8c95b36087aefa9.tar.gz portage-0467e091671d015b390083a9b8c95b36087aefa9.tar.bz2 portage-0467e091671d015b390083a9b8c95b36087aefa9.zip |
Add a new AgeSet class to select installed packages that have been installed more/less than n days ago
svn path=/main/trunk/; revision=11540
-rw-r--r-- | pym/portage/sets/dbapi.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/pym/portage/sets/dbapi.py b/pym/portage/sets/dbapi.py index 2ddefb861..438c9e2ca 100644 --- a/pym/portage/sets/dbapi.py +++ b/pym/portage/sets/dbapi.py @@ -248,3 +248,34 @@ class CategorySet(PackageSet): return rValue multiBuilder = classmethod(multiBuilder) +class AgeSet(EverythingSet): + _operations = ["merge", "unmerge"] + + def __init__(self, vardb, mode="older", age=7): + super(AgeSet, self).__init__(vardb) + self._mode = mode + self._age = age + + def _filter(self, atom): + import time, os + + cpv = self._db.match(atom)[0] + path = self._db.getpath(cpv, filename="COUNTER") + age = (time.time() - os.stat(path).st_mtime) / (3600 * 24) + if ((self._mode == "older" and age <= self._age) \ + or (self._mode == "newer" and age >= self._age)): + return False + else: + return True + + def singleBuilder(cls, options, settings, trees): + mode = options.get("mode", "older") + if str(mode).lower() not in ["newer", "older"]: + raise SetConfigError("invalid 'mode' value %s (use either 'newer' or 'older')" % mode) + try: + age = int(options.get("age", "7")) + except ValueError, e: + raise SetConfigError("value of option 'age' is not an integer") + return AgeSet(vardb=trees["vartree"].dbapi, mode=mode, age=age) + + singleBuilder = classmethod(singleBuilder) |