root/pkgcore-checks/pkgcore_checks/dropped_keywords.py @ ferringb%2540gmail.com-20080624174036-q45fk4fxguj9kjlv

Revision ferringb%2540gmail.com-20080624174036-q45fk4fxguj9kjlv, 1.9 kB (checked in by Brian Harring <ferringb@…>, 7 months ago)

punt trailing whitespace

Line 
1# Copyright: 2006 Brian Harring <ferringb@gmail.com>
2# License: GPL2
3
4
5from pkgcore_checks.base import Template, package_feed, versioned_feed, Result
6
7
8class DroppedKeywordWarning(Result):
9    """Arch keywords dropped during pkg version bumping"""
10
11    __slots__ = ("arch", "category", "package", "version")
12    threshold = versioned_feed
13
14    def __init__(self, arch, pkg):
15        Result.__init__(self)
16        self._store_cpv(pkg)
17        self.arch = arch
18
19    @property
20    def short_desc(self):
21        return "keyword %s was dropped" % self.arch
22
23
24class DroppedKeywordsReport(Template):
25    """scan pkgs for keyword dropping across versions"""
26
27    feed_type = package_feed
28    known_results = (DroppedKeywordWarning,)
29
30    def __init__(self, options):
31        Template.__init__(self, options)
32        self.arches = dict((k, None) for k in options.arches)
33
34    def feed(self, pkgset, reporter):
35        if len(pkgset) == 1:
36            return
37
38        lastpkg = pkgset[-1]
39        state = set(x.lstrip("~") for x in lastpkg.keywords)
40        arches = set(self.arches)
41        dropped = []
42        # pretty simple; pull the last keywords, walk backwards
43        # the difference (ignoring unstable/stable) should be empty;
44        # if it is, report; meanwhile, add the new arch in, and continue
45        for pkg in reversed(pkgset[:-1]):
46            oldstate = set(x.lstrip("~") for x in pkg.keywords)
47            for key in oldstate.difference(state):
48                if key.startswith("-"):
49                    continue
50                if pkg.version == "9999":
51                    continue
52                elif "-%s" % key in state:
53                    continue
54                elif key in arches:
55                    dropped.append((key, lastpkg))
56                    arches.discard(key)
57            state = oldstate
58            lastpkg = pkg
59
60        for key, pkg in dropped:
61            reporter.add_report(DroppedKeywordWarning(key, pkg))
Note: See TracBrowser for help on using the browser.