~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
#!/usr/bin/python
# -*- coding: utf-8 -*-

# Copyright (C) 2013 Canonical Ltd.
# Author: Stéphane Graber <stgraber@ubuntu.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 argparse
import os
import time

from launchpadlib.launchpad import Launchpad
from codecs import open

parser = argparse.ArgumentParser(
    description="Generate list of packages and uploaders for all packagesets.")
parser.add_argument("target", metavar="TARGET",
                    help="Target directory")
parser.add_argument("-a", "--all", action="store_true",
                    help="Sync all series instead of just the active ones")
args = parser.parse_args()

# Authenticated login to Launchpad as anonymous
# doesn't let us list the uploaders
lp = Launchpad.login_with('package_sets_report', 'production')

ubuntu = lp.distributions['ubuntu']

# Get the list of series
if args.all:
    ubuntu_series = [series for series in ubuntu.series
                     if series.status != "Future"]
else:
    ubuntu_series = [series for series in ubuntu.series if series.active]

# cache
teams = {}

for series in ubuntu_series:
    series_name = str(series.name)

    if not os.path.exists(os.path.join(args.target, series_name)):
        os.makedirs(os.path.join(args.target, series_name))

    for pkgset in lp.packagesets.getBySeries(distroseries=series):
        report = ""
        report += "Name: %s\n" % pkgset.name
        report += "Description: %s\n" % pkgset.description
        report += "Owner: %s\n" % pkgset.owner.display_name
        report += "Creation date: %s\n" % pkgset.date_created

        # List all the source packages
        report += "\nPackages:\n"
        for pkg in sorted(list(pkgset.getSourcesIncluded())):
            report += " - %s\n" % str(pkg)

        # List all the sub-package sets
        report += "\nSub-package sets:\n"
        for child in sorted(list(pkgset.setsIncluded(direct_inclusion=True))):
            report += " - %s\n" % child.name

        # List all the uploaders, when it's a team, show the members count
        report += "\nUploaders:\n"
        for archive in ubuntu.archives:
            for uploader in sorted(list(archive.getUploadersForPackageset(
                    packageset=pkgset)),
                    key=lambda uploader: uploader.person.display_name):

                if uploader.person.is_team:
                    if not uploader.person.name in teams:
                        team = uploader.person
                        teams[uploader.person.name] = team
                    else:
                        team = teams[uploader.person.name]

                    report += " - %s (%s) (%s) (%s) (%s members)\n" % \
                              (team.display_name,
                               team.name,
                               uploader.permission,
                               archive.displayname,
                               len(team.members))
                    for member in sorted(list(team.members),
                                         key=lambda person: person.name):
                        report += "   - %s (%s)\n" % (member.display_name,
                                                      member.name)
                else:
                    report += " - %s (%s) (%s)\n" % \
                              (uploader.person.name,
                               uploader.person.display_name,
                               uploader.permission)

        report += "\nGenerated at: %s\n" % time.asctime()
        with open(os.path.join(args.target, series_name, pkgset.name),
                  "w+", encoding="utf-8") as fd:
            fd.write(report)