From 51eac980e4b93a00585224032e7874e43392dafd Mon Sep 17 00:00:00 2001 From: Michael Palimaka Date: Sun, 30 Jul 2017 00:45:30 +1000 Subject: sync: add gentoo-ci pkgcheck results syncronisation --- backend/lib/sync.py | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++- manage.py | 5 +++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/backend/lib/sync.py b/backend/lib/sync.py index c3ed83c..fc1479e 100644 --- a/backend/lib/sync.py +++ b/backend/lib/sync.py @@ -5,7 +5,7 @@ from datetime import datetime import requests from .. import app, db -from .models import Category, Keyword, Maintainer, Package, PackageVersion +from .models import Category, Keyword, Maintainer, Package, PackageVersion, PkgCheck SYNC_BUFFER_SECS = 60*60 #1 hour proj_url = "https://api.gentoo.org/metastructure/projects.xml" @@ -151,6 +151,67 @@ def sync_packages(): db.session.add(new_pkg) db.session.commit() +def sync_pkgcheck(): + data = http_session.get("https://gitweb.gentoo.org/report/gentoo-ci.git/plain/output.xml") + root = ET.fromstring(data.content) + + if root.tag.lower() != 'checks': + print("Downloaded gentoo-ci output.xml root tag isn't 'checks'") + return + + PkgCheck.query.delete() + + for result_elem in root: + if result_elem.tag.lower() != 'result': + print("Skipping unknown subtag <%s>" % result_elem.tag) + continue + + check = { + 'category': None, + 'package': None, + 'version': None, + 'class': '', + 'message': '', + } + + for elem in result_elem: + tag = elem.tag.lower() + text = elem.text + + if tag == 'category': + category = Category.query.filter_by(name=text).first() + if category: + check['category'] = category + else: + print("Skipping unknown category <%s>" % text) + elif tag == 'package': + if check['category']: + package = Package.query.filter_by(category=check['category'],name=text).first() + if package: + check['package'] = package + else: + print("Skipping unknown package <%s>" % text) + else: + print("Skipping package <%s> for which no category is defined" % text) + elif tag == 'version': + if check['package']: + version = PackageVersion.query.filter_by(package=check['package'], version=text).first() + if version: + check['version'] = version + else: + print("Skipping unknown version <%s-%s>" % (check['package'].name, text)) + else: + print("Skipping version <%s> for which no package is defined" % text) + elif tag == 'class': + check['class'] = elem.text.lower() + elif tag == 'msg': + check['message'] = elem.text.lower() + + pkgcheck = PkgCheck(category=check['category'], package=check['package'], version=check['version'], violationclass=check['class'], message=check['message']) + db.session.add(pkgcheck) + + db.session.commit() + def sync_versions(): """Synchronize packages version data from packages.gentoo.org. diff --git a/manage.py b/manage.py index 8df47ee..889c670 100755 --- a/manage.py +++ b/manage.py @@ -44,6 +44,11 @@ def sync_packages(): """Synchronize only Gentoo packages base data (without details)""" sync.sync_packages() +@manager.command +def sync_pkgcheck(): + """Synchronize dev-util/pkgcheck static analysis data""" + sync.sync_pkgcheck() + @manager.command def sync_versions(): """Synchronize only Gentoo package details""" -- cgit v1.2.3-65-gdbad