-
-
Notifications
You must be signed in to change notification settings - Fork 147
devel: import bumpbuddy out of date information #598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,129 @@ | ||||||
| #!/usr/bin/python | ||||||
|
|
||||||
|
|
||||||
| """ | ||||||
| read_bumpbuddy_status | ||||||
|
|
||||||
| Usage: ./manage.py read_bumpbuddy_status | ||||||
| """ | ||||||
|
|
||||||
|
|
||||||
| import logging | ||||||
|
|
||||||
| import requests | ||||||
| from django.conf import settings | ||||||
| from django.core.cache import cache | ||||||
| from django.core.management.base import BaseCommand | ||||||
| from django.utils.timezone import now | ||||||
|
|
||||||
| from main.models import Package | ||||||
| from packages.alpm import AlpmAPI | ||||||
| from packages.models import FlagRequest | ||||||
|
|
||||||
| logger = logging.getLogger("command") | ||||||
| logger.setLevel(logging.WARNING) | ||||||
|
|
||||||
|
|
||||||
| alpm = AlpmAPI() | ||||||
|
|
||||||
|
|
||||||
| class Command(BaseCommand): | ||||||
| def process_package(self, pkgdata): | ||||||
| pkgbase = pkgdata['pkgbase'] | ||||||
| version = pkgdata['local_version'] | ||||||
| upstream_version = pkgdata['upstream_version'] | ||||||
| logger.debug("Import new out of date package '%s'", pkgbase) | ||||||
|
|
||||||
| packages = Package.objects.filter(pkgbase=pkgbase) | ||||||
| found_packages = list(packages) | ||||||
|
|
||||||
| if len(found_packages) == 0: | ||||||
| logger.error("no matching packages found for pkgbase='%s'", pkgbase) | ||||||
| return | ||||||
|
|
||||||
| # already flagged | ||||||
| not_flagged_packages = [pkg for pkg in found_packages if pkg.flag_date is None] | ||||||
| if len(not_flagged_packages) == 0: | ||||||
| return | ||||||
|
|
||||||
| ood_packages = [pkg for pkg in not_flagged_packages if alpm.vercmp(upstream_version, pkg.pkgver) > 0] | ||||||
| if len(ood_packages) == 0: | ||||||
| logger.debug("package is not out of date for pkgbase='%s'", pkgbase) | ||||||
| return | ||||||
|
|
||||||
| pkg = ood_packages[0] | ||||||
|
|
||||||
| # find a common version if there is one available to store | ||||||
| versions = {(pkg.pkgver, pkg.pkgrel, pkg.epoch) for pkg in ood_packages} | ||||||
| if len(versions) == 1: | ||||||
| version = versions.pop() | ||||||
| else: | ||||||
| version = ('', '', 0) | ||||||
|
|
||||||
| current_time = now() | ||||||
| # Compatibility for old json output without issue | ||||||
| if 'issue' in pkgdata: | ||||||
| issue_url = f"{settings.GITLAB_PACKAGES_REPO}/{pkgbase}/-/issues/{pkgdata['issue']}" | ||||||
| message = f"New version {pkgdata['upstream_version']} is available: {issue_url}" | ||||||
| else: | ||||||
| message = f"New version {pkgdata['upstream_version']} is available." | ||||||
| packages.update(flag_date=current_time) | ||||||
| flag_request = FlagRequest(created=current_time, | ||||||
| user_email="[email protected]", | ||||||
| message=message, | ||||||
| ip_address="0.0.0.0", | ||||||
| pkgbase=pkg.pkgbase, | ||||||
| repo=pkg.repo, | ||||||
| pkgver=version[0], | ||||||
| pkgrel=version[1], | ||||||
| epoch=version[2], | ||||||
| num_packages=len(ood_packages)) | ||||||
|
|
||||||
| return flag_request | ||||||
|
|
||||||
| def handle(self, *args, **options): | ||||||
| v = int(options.get('verbosity', 0)) | ||||||
| if v == 0: | ||||||
| logger.level = logging.ERROR | ||||||
| elif v == 1: | ||||||
| logger.level = logging.INFO | ||||||
| elif v >= 2: | ||||||
| logger.level = logging.DEBUG | ||||||
|
|
||||||
| url = getattr(settings, "BUMPBUDDY_URL", None) | ||||||
| assert url is not None, "BUMPBUDDY_URL not configured" | ||||||
|
|
||||||
| headers = {} | ||||||
| last_modified = cache.get('bumpbuddy:last-modified') | ||||||
| if last_modified: | ||||||
| logger.debug('Setting If-Modified-Since header') | ||||||
| headers = {'If-Modified-Since': last_modified} | ||||||
|
|
||||||
| req = requests.get(url, headers) | ||||||
| if req.status_code == 304: | ||||||
| logger.debug('The rebuilderd data has not been updated since we last checked it') | ||||||
| return | ||||||
|
|
||||||
| if req.status_code != 200: | ||||||
| logger.error("Issues retrieving bumpbuddy data: '%s'", req.status_code) | ||||||
| return | ||||||
|
|
||||||
| last_modified = req.headers.get('last-modified') | ||||||
| if last_modified: | ||||||
| cache.set('bumpbuddy:last-modified', last_modified, 3600) # cache one hour | ||||||
|
|
||||||
| flagged_packages = [] | ||||||
| for pkgdata in req.json().values(): | ||||||
| if not pkgdata['out_of_date']: | ||||||
| continue | ||||||
|
Comment on lines
+117
to
+118
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
We shouldn't only process entries marked as |
||||||
|
|
||||||
| package = self.process_package(pkgdata) | ||||||
| if package is not None: | ||||||
| flagged_packages.append(package) | ||||||
|
|
||||||
| if flagged_packages: | ||||||
| logger.info("Imported %d new out of date packages", len(flagged_packages)) | ||||||
| FlagRequest.objects.bulk_create(flagged_packages) | ||||||
|
|
||||||
|
|
||||||
| # vim: set ts=4 sw=4 et: | ||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the corrent pkgbase in gitlab url's we need to