~xnox/ubuntu-archive-tools/sru-report-autopkgtest-vomit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/usr/bin/python3

# Copyright (C) 2016  Canonical Ltd.
# Author: Steve Langasek <steve.langasek@canonical.com>

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


import re
import sys
import subprocess


class KernelWorkflowError(Exception):
    """An exception occurred with the state of the workflow bug"""


def get_name_and_version_from_bug(bug):
    title_re = re.compile(
        r'^(?P<package>[a-z0-9.-]+): (?P<version>[0-9.-]+[0-9a-z.~-]*)'
        + ' -proposed tracker$')
    match = title_re.search(bug.title)
    if not match:
        print("Ignoring bug %s, not a kernel SRU tracking bug" % bugnum)
        return (None, None)
    package = match.group('package')
    version = match.group('version')
    # FIXME: check that the package version is correct for the suite
    return (package, version)


def process_sru_bug(lp, bugnum, task_callback, source_callback, context=None):
    """Process the indicated bug and call the provided helper functions
    as needed
    """
    package_re = re.compile(
        (r'^%subuntu/(?P<release>[0-9a-z.-]+)/'
         + '\+source/(?P<package>[a-z0-9.-]+)$') % str(lp._root_uri))
    workflow_re = re.compile(
        r'^%skernel-sru-workflow/(?P<subtask>.*)' % str(lp._root_uri))
    prep_re = re.compile(r'prepare-package(?P<subpackage>.*)')

    packages = []
    source_name = None
    proposed_task = None
    updates_task = None
    security_task = None
    bug = lp.bugs[int(bugnum)]
    package, version = get_name_and_version_from_bug(bug)
    if not package or not version:
        return

    task_results = {}
    for task in bug.bug_tasks:
        # If a task is set to invalid, we do not care about it
        if task.status == 'Invalid':
            continue

        # FIXME: ok not exactly what we want, we probably want a hash?
        task_results.update(task_callback(lp, bugnum, task, context))
        task_match = workflow_re.search(str(task.target))
        if task_match:
            subtask = task_match.group('subtask')
            # FIXME: consolidate subtask / prep_match here
            prep_match = prep_re.search(subtask)
            if prep_match:
                packages.append(prep_match.group('subpackage'))

        pkg_match = package_re.search(str(task.target))
        if pkg_match:
            if source_name:
                print("Too many source packages, %s and %s, ignoring bug %s"
                      % (source_name, pkg_match.group('package'), bugnum))
                continue
            source_name = pkg_match.group('package')
            release = pkg_match.group('release')
            continue

    if not source_name:
        print("No source package to act on, skipping bug %s" % bugnum)
        return

    if source_name != package:
        print("Cannot determine base package for %s, %s vs. %s"
              % (bugnum, source_name, package))
        return

    if not packages:
        print("No packages in the prepare list, don't know what to do")
        return

    if not '' in packages:
        print("No kernel package in prepare list, only meta packages.  "
              "Continue review? [yN] ", end="")
        sys.stdout.flush()
        response = sys.stdin.readline()
        if not response.strip().lower().startswith('y'):
            return

    full_packages = []
    for pkg in packages:
        if pkg == '-lbm':
           pkg = '-backports-modules-3.2.0'

        real_package = re.sub(r'^linux', 'linux' + pkg, package)
        full_packages.append(real_package)

    source_callback(lp, bugnum, task_results, full_packages, release, context)