6
6
from pprint import pprint
9
from datetime import date
9
15
from launchpadlib.launchpad import Launchpad
13
17
DEBUGLEVEL = logging.DEBUG
18
DEFAULT_DB = 'errors.sqlite'
21
RELEASE_NAME = distro_info.UbuntuDistroInfo().devel(result='codename')
23
distro_info.UbuntuDistroInfo().devel(result='release').split(' ')[0]
24
except distro_info.DistroDataOutdated:
25
RELEASE_NAME = 'bionic'
15
29
# Launchpad credentials
20
components = ('main', 'restricted', 'universe', 'multiverse')
23
RELEASE_NAME = 'bionic'
34
COMPONENTS = ('main', 'restricted', 'universe', 'multiverse')
37
SQLTABLE_PUBLICATIONS = """
27
38
CREATE TABLE publications(
32
43
time_to_release FLOAT
46
SQLINDEX_PK_PUBLICATIONS = """
35
47
CREATE INDEX pk_publications ON publications(
43
54
# def strip_epoch(verstr):
61
def set_logging(debugmode=False):
62
"""Initialize logging"""
64
level=logging.DEBUG if debugmode else logging.INFO,
65
format="%(asctime)s %(levelname)s %(message)s")
66
logging.debug('Debug mode enabled')
69
def create_db(path, delete=False):
70
"""Create bugs database
72
:param path: path to sqlite database
74
if os.path.exists(path):
76
logging.info('Deleting database as requested')
79
logging.debug('db %s already exists, skipping creation', path)
82
logging.debug('Creating db %s', path)
83
conn = sqlite3.connect(path)
85
logging.debug("Creating table publications ...")
86
cur.execute(SQLTABLE_PUBLICATIONS)
87
logging.debug("Creating primary index on publications ...")
88
cur.execute(SQLINDEX_PK_PUBLICATIONS)
93
def _parse_arguments():
94
"""Parse command-line args, returning an argparse dict."""
96
parser = argparse.ArgumentParser("Export number of crash reports for a "
98
parser.add_argument('-d', '--debug', action='store_true',
99
default=False, help='enable debug mode')
100
parser.add_argument('-D', '--dbname', default=DEFAULT_DB,
101
help='Name of the database to store results (default: '
102
'{})'.format(DEFAULT_DB))
103
parser.add_argument('--delete', action='store_true',
104
default=False, help='Delete the database if it exists')
105
return parser.parse_args()
51
108
def load_packageset(distroname, name):
52
109
""" List packages in a packageset """
53
logging.debug("Fetching packageset for %s/%s" % (distroname,
55
pkgset = lp.packagesets.getByName(distroseries=distros[distroname], name=name)
110
logging.debug("Fetching packageset for %s/%s", distroname, name)
111
pkgset = LP.packagesets.getByName(distroseries=DISTROS[distroname], name=name)
56
112
srcs = pkgset.getSourcesIncluded()
60
def write_packageset(srcs, format='text'):
116
def write_packageset(srcs, output_fmt='text'):
61
117
""" Dump package set to file """
62
with open('desktop.pkgset', 'w') as outfile:
118
with open('desktop.pkgset.%s' % date.today().strftime('%Y%m%d'), 'w') \
120
if output_fmt == 'text':
65
122
outfile.write(src + '\n')
66
elif format == 'json':
67
json.dump(srcs, outfile)
123
elif output_fmt == 'json':
124
json.dump(srcs, outfile)
69
126
logging.error('Unsupported format: %s', format)
72
129
def publishing_history(distroname, sourcename):
73
130
''' Load publishing history from LP'''
74
global archive, distros
75
logging.debug("Fetching publishing history for %s/%s" % (distroname, sourcename))
76
pubs = archive.getPublishedSources(source_name=sourcename, exact_match=True, distro_series=distros[distroname])
131
global ARCHIVE, DISTROS
132
logging.debug("Fetching publishing history for %s/%s", distroname, sourcename)
133
pubs = ARCHIVE.getPublishedSources(source_name=sourcename,
135
distro_series=DISTROS[distroname])
79
138
if pub.source_package_version not in records:
85
144
records[pub.source_package_version][pub.pocket.lower()] = pub.date_published
86
145
if records[pub.source_package_version]['release'] and \
87
146
records[pub.source_package_version]['proposed']:
88
records[pub.source_package_version]['delta'] = records[pub.source_package_version]['release'] - records[pub.source_package_version]['proposed']
147
records[pub.source_package_version]['delta'] = \
148
records[pub.source_package_version]['release'] -\
149
records[pub.source_package_version]['proposed']
94
155
''' Init LP credentials, archive and distro list '''
95
global lp, ubuntu, archive, distros, suites
156
global LP, UBUNTU, ARCHIVE, DISTROS, SUITES
96
157
logging.debug("Initializing LP Credentials")
97
lp = Launchpad.login_anonymously('sru-report', 'production')
98
ubuntu = lp.distributions['ubuntu']
99
archive = ubuntu.getArchive(name='primary')
100
for serie in ubuntu.series:
158
LP = Launchpad.login_anonymously('sru-report', 'production')
159
UBUNTU = LP.distributions['ubuntu']
160
ARCHIVE = UBUNTU.getArchive(name='primary')
161
for serie in UBUNTU.series:
102
suites.append(serie.name)
103
distros[serie.name] = serie
104
logging.debug("Active releases found: %s" % " ".join(suites))
163
SUITES.append(serie.name)
164
DISTROS[serie.name] = serie
165
logging.debug("Active releases found: %s", " ".join(SUITES))
108
logging.basicConfig(level=logging.DEBUG,
109
format="%(asctime)s - %(levelname)s - %(message)s")
170
args = _parse_arguments()
171
set_logging(args.debug)
112
177
pkgs = load_packageset(RELEASE_NAME, 'ubuntu-desktop')
113
178
write_packageset(pkgs)
115
conn = sqlite3.connect("errors.sqlite")
180
create_db(args.dbname, args.delete)
181
conn = sqlite3.connect(args.dbname)
116
183
cur = conn.cursor()
135
'Ubuntu %s' % RELEASE_VER,
138
v['release'].strftime('%Y-%m-%d'),
139
v['delta'].total_seconds()])
200
VALUES(?,?,?,?,?)""",
202
'Ubuntu %s' % RELEASE_VER,
205
v['release'].strftime('%Y-%m-%d'),
206
v['delta'].total_seconds()
141
209
print('%s,%s,%s,%s,%s' % (