| 1 | # Copyright: 2006 Brian Harring <ferringb@gmail.com> |
|---|
| 2 | # License: GPL2 |
|---|
| 3 | |
|---|
| 4 | from pkgcore.restrictions import packages, values |
|---|
| 5 | from pkgcore_checks.base import Template, package_feed, Result |
|---|
| 6 | from pkgcore_checks import addons |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | class UnstableOnly(Result): |
|---|
| 10 | |
|---|
| 11 | """package/keywords that are strictly unstable""" |
|---|
| 12 | |
|---|
| 13 | __slots__ = ("category", "package", "version", "arch") |
|---|
| 14 | |
|---|
| 15 | threshold = package_feed |
|---|
| 16 | |
|---|
| 17 | def __init__(self, pkgs, arch): |
|---|
| 18 | Result.__init__(self) |
|---|
| 19 | self._store_cp(pkgs[0]) |
|---|
| 20 | self.arch = arch |
|---|
| 21 | self.version = tuple(x.fullver for x in pkgs) |
|---|
| 22 | |
|---|
| 23 | @property |
|---|
| 24 | def short_desc(self): |
|---|
| 25 | return "for arch %s, all versions are unstable: [ %s ]" % ( |
|---|
| 26 | self.arch, ', '.join(self.version)) |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | class UnstableOnlyReport(Template): |
|---|
| 30 | """scan for pkgs that have just unstable keywords""" |
|---|
| 31 | |
|---|
| 32 | feed_type = package_feed |
|---|
| 33 | required_addons = (addons.ArchesAddon,) |
|---|
| 34 | known_results = (UnstableOnly,) |
|---|
| 35 | |
|---|
| 36 | def __init__(self, options, arches): |
|---|
| 37 | Template.__init__(self, options) |
|---|
| 38 | arches = set(x.strip().lstrip("~") for x in options.arches) |
|---|
| 39 | # stable, then unstable, then file |
|---|
| 40 | self.arch_restricts = {} |
|---|
| 41 | for x in arches: |
|---|
| 42 | self.arch_restricts[x] = [ |
|---|
| 43 | packages.PackageRestriction("keywords", |
|---|
| 44 | values.ContainmentMatch(x)), |
|---|
| 45 | packages.PackageRestriction("keywords", |
|---|
| 46 | values.ContainmentMatch("~%s" % x)) |
|---|
| 47 | ] |
|---|
| 48 | |
|---|
| 49 | def feed(self, pkgset, reporter): |
|---|
| 50 | # stable, then unstable, then file |
|---|
| 51 | for k, v in self.arch_restricts.iteritems(): |
|---|
| 52 | stable = unstable = None |
|---|
| 53 | for x in pkgset: |
|---|
| 54 | if v[0].match(x): |
|---|
| 55 | stable = x |
|---|
| 56 | break |
|---|
| 57 | if stable is not None: |
|---|
| 58 | continue |
|---|
| 59 | unstable = [x for x in pkgset if v[1].match(x)] |
|---|
| 60 | if unstable: |
|---|
| 61 | reporter.add_report(UnstableOnly(unstable, k)) |
|---|
| 62 | |
|---|
| 63 | def finish(self, reporter): |
|---|
| 64 | self.arch_restricts.clear() |
|---|