| 1 | # Copyright: 2006 Brian Harring <ferringb@gmail.com> |
|---|
| 2 | # License: GPL2 |
|---|
| 3 | |
|---|
| 4 | import time |
|---|
| 5 | from pkgcore_checks.base import Template, versioned_feed, Result |
|---|
| 6 | from pkgcore_checks import addons |
|---|
| 7 | |
|---|
| 8 | day = 24*3600 |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | class StaleUnstableKeyword(Result): |
|---|
| 12 | """ |
|---|
| 13 | packages that have unstable keywords that have been unstable for over a |
|---|
| 14 | month |
|---|
| 15 | """ |
|---|
| 16 | |
|---|
| 17 | __slots__ = ("category", "package", "version", "keywords", "period") |
|---|
| 18 | |
|---|
| 19 | threshold = versioned_feed |
|---|
| 20 | |
|---|
| 21 | def __init__(self, pkg, keywords, period): |
|---|
| 22 | Result.__init__(self) |
|---|
| 23 | self._store_cpv(pkg) |
|---|
| 24 | self.keywords = tuple(sorted(keywords)) |
|---|
| 25 | self.period = period |
|---|
| 26 | |
|---|
| 27 | @property |
|---|
| 28 | def short_desc(self): |
|---|
| 29 | return "no change in %i days for unstable keywords [ %s ]" % ( |
|---|
| 30 | self.period, ', '.join(self.keywords)) |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | class StaleUnstableReport(Template): |
|---|
| 34 | """Ebuilds that have sat unstable for over a month""" |
|---|
| 35 | |
|---|
| 36 | feed_type = versioned_feed |
|---|
| 37 | required_addons = (addons.ArchesAddon,) |
|---|
| 38 | known_results = (StaleUnstableKeyword,) |
|---|
| 39 | |
|---|
| 40 | def __init__(self, options, arches, staleness=long(day*30)): |
|---|
| 41 | Template.__init__(self, options) |
|---|
| 42 | self.staleness = staleness |
|---|
| 43 | self.start_time = None |
|---|
| 44 | self.targets = frozenset("~%s" % x.lstrip("~") for x in options.arches) |
|---|
| 45 | |
|---|
| 46 | def start(self): |
|---|
| 47 | self.start_time = time.time() |
|---|
| 48 | |
|---|
| 49 | def feed(self, pkg, reporter): |
|---|
| 50 | unchanged_time = self.start_time - pkg._mtime_ |
|---|
| 51 | if unchanged_time < self.staleness: |
|---|
| 52 | return |
|---|
| 53 | unstable = [x for x in pkg.keywords if x in self.targets] |
|---|
| 54 | if not unstable: |
|---|
| 55 | return |
|---|
| 56 | reporter.add_report( |
|---|
| 57 | StaleUnstableKeyword(pkg, unstable, int(unchanged_time/day))) |
|---|