|
| 1 | +from datetime import datetime |
1 | 2 | import os |
2 | 3 | import stat |
3 | 4 | from collections import defaultdict |
@@ -295,18 +296,44 @@ def feed(self, pkgset): |
295 | 296 |
|
296 | 297 |
|
297 | 298 | class LiveOnlyPackage(results.PackageResult, results.Warning): |
298 | | - """Package only has VCS-based ebuilds.""" |
| 299 | + """Package has only had VCS-based ebuilds for over a year.""" |
299 | 300 |
|
300 | | - desc = 'all versions are VCS-based' |
| 301 | + def __init__(self, age, **kwargs): |
| 302 | + super().__init__(**kwargs) |
| 303 | + self.age = age |
| 304 | + |
| 305 | + @property |
| 306 | + def desc(self): |
| 307 | + return f'all versions are VCS-based added over {self.age} years ago' |
301 | 308 |
|
302 | 309 |
|
303 | 310 | class LiveOnlyCheck(GentooRepoCheck): |
304 | | - """Scan for packages with only live versions.""" |
| 311 | + """Scan for old packages with only live versions.""" |
305 | 312 |
|
306 | 313 | scope = base.package_scope |
307 | 314 | _source = sources.PackageRepoSource |
| 315 | + required_addons = (git.GitAddon,) |
308 | 316 | known_results = frozenset([LiveOnlyPackage]) |
309 | 317 |
|
| 318 | + def __init__(self, *args, git_addon): |
| 319 | + super().__init__(*args) |
| 320 | + self.today = datetime.today() |
| 321 | + self.added_repo = git_addon.cached_repo(git.GitAddedRepo) |
| 322 | + |
310 | 323 | def feed(self, pkgset): |
| 324 | + # disable check when git repo parsing is disabled |
| 325 | + if self.added_repo is None: |
| 326 | + return |
| 327 | + |
311 | 328 | if all(pkg.live for pkg in pkgset): |
312 | | - yield LiveOnlyPackage(pkg=pkgset[0]) |
| 329 | + # assume highest package version is most recently committed |
| 330 | + pkg = sorted(pkgset)[-1] |
| 331 | + try: |
| 332 | + match = self.added_repo.match(pkg.versioned_atom)[0] |
| 333 | + except IndexError: |
| 334 | + # probably an uncommitted package |
| 335 | + return |
| 336 | + added = datetime.strptime(match.date, '%Y-%m-%d') |
| 337 | + years_old = round((self.today - added).days / 365, 2) |
| 338 | + if years_old > 1: |
| 339 | + yield LiveOnlyPackage(years_old, pkg=pkg) |
0 commit comments