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
|
#!/usr/bin/python -S
#
# Copyright 2009 Canonical Ltd. This software is licensed under the
# GNU Affero General Public License version 3 (see the file LICENSE).
# pylint: disable-msg=C0103,W0403
# This script aims to ensure that there is a Malone watch on Debian bugs
# that meet certain criteria. The Malone watch will be linked to a BugTask
# on Debian for that bug. The business of syncing is handled separately.
__metaclass__ = type
import _pythonpath
import os
import logging
# zope bits
from zope.component import getUtility
# canonical launchpad modules
from lp.services.scripts.base import (
LaunchpadCronScript, LaunchpadScriptFailure)
from canonical.launchpad.scripts.debsync import do_import
from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
# setup core values and defaults
debbugs_location_default = '/srv/bugs-mirror.debian.org/'
debbugs_pl = '../lib/canonical/launchpad/scripts/debbugs-log.pl'
# the minimum age, in days, of a debbugs bug before we will import it
MIN_AGE = 7
class CreateDebWatches(LaunchpadCronScript):
description = """
This script syncs debbugs from http://bugs.debian.org/ into Malone.
It selects interesting bugs in debian and makes sure that there is a
Malone bug for each of them. See debwatchsync for a tool that
syncronises the bugs in Malone and debbugs, too.
"""
loglevel = logging.WARNING
def add_my_options(self):
self.parser.set_defaults(max=None, debbugs=debbugs_location_default)
self.parser.add_option('--debbugs', action='store', type='string',
dest='debbugs',
help="The location of your debbugs database.")
self.parser.add_option(
'--max', action='store', type='int', dest='max',
help="The maximum number of bugs to create.")
self.parser.add_option('--package', action='append', type='string',
help="A list of packages for which we should import bugs.",
dest="packages", default=[])
def main(self):
index_db_path = os.path.join(self.options.debbugs, 'index/index.db')
if not os.path.exists(index_db_path):
# make sure the debbugs location looks sane
raise LaunchpadScriptFailure('%s is not a debbugs db.'
% self.options.debbugs)
# Make sure we import any Debian bugs specified on the command line
target_bugs = set()
for arg in self.args:
try:
target_bug = int(arg)
except ValueError:
self.logger.error(
'%s is not a valid debian bug number.' % arg)
target_bugs.add(target_bug)
target_package_set = set()
previousimportset = set()
self.logger.info('Calculating target package set...')
# first find all the published ubuntu packages
ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
for p in ubuntu.currentrelease.getAllPublishedBinaries():
target_package_set.add(
p.binarypackagerelease.binarypackagename.name)
# then add packages passed on the command line
for package in self.options.packages:
target_package_set.add(package)
self.logger.info(
'%d binary packages targeted.' % len(target_package_set))
self.txn.abort()
self.txn.begin()
do_import(self.logger, self.options.max, self.options.debbugs,
target_bugs, target_package_set, previousimportset, MIN_AGE,
debbugs_pl)
self.txn.commit()
self.logger.info('Done!')
if __name__ == '__main__':
script = CreateDebWatches("debbugs-mkwatch")
script.lock_and_run()
|