| 1 | # Copyright: 2006 Brian Harring <ferringb@gmail.com> |
|---|
| 2 | # License: GPL2 |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | from pkgcore_checks.base import Template, package_feed, versioned_feed, Result |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | class 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 | |
|---|
| 24 | class 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 | elif "-%s" % key in state: |
|---|
| 51 | continue |
|---|
| 52 | elif key in arches: |
|---|
| 53 | dropped.append((key, lastpkg)) |
|---|
| 54 | arches.discard(key) |
|---|
| 55 | state = oldstate |
|---|
| 56 | lastpkg = pkg |
|---|
| 57 | |
|---|
| 58 | for key, pkg in dropped: |
|---|
| 59 | reporter.add_report(DroppedKeywordWarning(key, pkg)) |
|---|