[Qa-jenkins-scm] [jenkins.debian.net] 01/06: reproducible: common: add classes Package, Build, Bug, Issue, Note, NotedPkg describing a package and its state

Holger Levsen holger at moszumanska.debian.org
Sat Aug 15 10:51:21 UTC 2015


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch master
in repository jenkins.debian.net.

commit 0bf1f0e447ff18d154394b7e6ac8318aedf00e49
Author: Mattia Rizzolo <mattia at mapreri.org>
Date:   Wed May 13 18:55:15 2015 +0200

    reproducible: common: add classes Package, Build, Bug, Issue, Note, NotedPkg describing a package and its state
---
 bin/reproducible_common.py | 132 ++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 131 insertions(+), 1 deletion(-)

diff --git a/bin/reproducible_common.py b/bin/reproducible_common.py
index da777b6..8eae095 100755
--- a/bin/reproducible_common.py
+++ b/bin/reproducible_common.py
@@ -570,6 +570,137 @@ def irc_msg(msg):
     kgb.extend(str(msg).strip().split())
     call(kgb)
 
+
+class Bug:
+    def __init__(self, bug):
+        self.bug = bug
+
+    def __str__(self):
+        return str(self.bug)
+
+
+class Issue:
+    def __init__(self, name):
+        self.name = name
+        query = 'SELECT url, description  FROM issues WHERE name="{}"'
+        result = query_db(query.format(self.name))
+        try:
+            self.url = result[0][0]
+        except IndexError:
+            self.url = ''
+        try:
+            self.desc = result[0][0]
+        except IndexError:
+            self.desc = ''
+
+
+class Note:
+    def __init__(self, pkg, results):
+        log.debug(str(results))
+        self.issues = [Issue(x) for x in json.loads(results[0])]
+        self.bugs = [Bug(x) for x in json.loads(results[1])]
+        self.comment = results[2]
+
+
+class NotedPkg:
+    def __init__(self, package, suite, arch):
+        self.package = package
+        self.suite = suite
+        self.arch = arch
+        query = 'SELECT n.issues, n.bugs, n.comments ' + \
+                'FROM sources AS s JOIN notes AS n ON s.id=n.package_id ' + \
+                'WHERE s.name="{}" AND s.suite="{}" AND s.architecture="{}"'
+        result = query_db(query.format(self.package, self.suite, self.arch))
+        try:
+            result = result[0]
+        except IndexError:
+            self.note = None
+        else:
+            self.note = Note(self, result)
+
+class Build:
+    def __init__(self, package, suite, arch):
+        self.package = package
+        self.suite = suite
+        self.arch = arch
+        self.status = False
+        self.version = False
+        self.build_date = False
+        self._get_package_status()
+
+    def _get_package_status(self):
+        try:
+            query = 'SELECT r.status, r.version, r.build_date ' + \
+                    'FROM results AS r JOIN sources AS s ' + \
+                    'ON r.package_id=s.id WHERE s.name="{}" ' + \
+                    'AND s.architecture="{}" AND s.suite="{}"'
+            query = query.format(self.package, self.arch, self.suite)
+            result = query_db(query)[0]
+        except IndexError:  # not tested, look whether it actually exists
+            query = 'SELECT version FROM sources WHERE name="{}" ' + \
+                    'AND suite="{}" AND architecture="{}"'
+            query = query.format(self.package, self.suite, self.arch)
+            try:
+                result = query_db(query)[0][0]
+                if result:
+                    result = ('untested', str(result), False)
+            except IndexError:  # there is no package with this name in this
+                return          # suite/arch, or none at all
+        self.status = str(result[0])
+        self.version = str(result[1])
+        # this is currently used only on rb-pkg pages, no need to have
+        if result[2]:                       # parsable timestamps and the like
+            self.build_date = 'at ' + str(result[2]) + ' UTC'
+        else:
+            self.build_date = \
+                '<span style="color:red;font-weight:bold;">UNTESTED</span>'
+
+
+class Package:
+    def __init__(self, name, no_notes=False):
+        self.name = name
+        self._status = {}
+        for suite in SUITES:
+            self._status[suite] = {}
+            for arch in ARCHS:
+                self._status[suite][arch] = Build(self.name, suite, arch)
+                if not no_notes:
+                    self.note = NotedPkg(self.name, suite, arch).note
+                else:
+                    self.note = False
+        try:
+            self.status = self._status[defaultsuite][defaultarch].status
+        except KeyError:
+            self.status = False
+        query = 'SELECT notify_maintainer FROM sources WHERE name="{}"'
+        try:
+            result = int(query_db(query.format(self.name))[0][0])
+        except IndexError:
+            result = 0
+        self.notify_maint = '⚑' if result == 1 else ''
+
+    def get_status(self, suite, arch):
+        """ This returns False if the package does not exists in this suite """
+        try:
+            return self._status[suite][arch].status
+        except KeyError:
+            return False
+
+    def get_build_date(self, suite, arch):
+        """ This returns False if the package does not exists in this suite """
+        try:
+            return self._status[suite][arch].build_date
+        except KeyError:
+            return False
+
+    def get_tested_version(self, suite, arch):
+        """ This returns False if the package does not exists in this suite """
+        try:
+            return self._status[suite][arch].version
+        except KeyError:
+            return False
+
+
 # init the databases connections
 conn_db = start_db_connection()  # the local sqlite3 reproducible db
 # get_bugs() is the only user of this, let it initialize the connection itself,
@@ -577,4 +708,3 @@ conn_db = start_db_connection()  # the local sqlite3 reproducible db
 # also "share" the bugs, to avoid collecting them multiple times per run
 conn_udd = None
 bugs = None
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/qa/jenkins.debian.net.git



More information about the Qa-jenkins-scm mailing list