~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
5
4935.3.7 by Curtis Hovey
Added bad name suppression to cronscripts.
6
# pylint: disable-msg=C0103,W0403
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
7
8
# This script aims to ensure that there is a Malone watch on Debian bugs
9
# that meet certain criteria. The Malone watch will be linked to a BugTask
10
# on Debian for that bug. The business of syncing is handled separately.
11
12
__metaclass__ = type
1240 by Canonical.com Patch Queue Manager
eliminate bugassignments in favour of bugtasks
13
9641.1.4 by Gary Poster
more updates for _pythonpath. Still need to update all subprocess calls to python to use -S; still need to update z3c.recipe.filetemplate to provide sys.modules from -S run.
14
import _pythonpath
2450 by Canonical.com Patch Queue Manager
[r=jamesh] rework cve structure, and general polish
15
import os
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
16
import logging
3691.348.1 by kiko
Remove the original lockfile class and use our contributed GlobalLock everywhere to avoid stale locks making our scripts stop to run. Update a bunch of scripts to use it. Hopefully backwards-compatible enough to survive tests.
17
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
18
# zope bits
19
from zope.component import getUtility
1382 by Canonical.com Patch Queue Manager
new page layout
20
21
# canonical launchpad modules
8356.1.1 by Leonard Richardson
Partial move.
22
from lp.services.scripts.base import (
4264.2.1 by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it
23
    LaunchpadCronScript, LaunchpadScriptFailure)
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
24
from canonical.launchpad.scripts.debsync import do_import
2450 by Canonical.com Patch Queue Manager
[r=jamesh] rework cve structure, and general polish
25
from canonical.launchpad.interfaces import ILaunchpadCelebrities
1149 by Canonical.com Patch Queue Manager
malone debbugs integration
26
27
28
# setup core values and defaults
2450 by Canonical.com Patch Queue Manager
[r=jamesh] rework cve structure, and general polish
29
debbugs_location_default = '/srv/bugs-mirror.debian.org/'
30
debbugs_pl = '../lib/canonical/launchpad/scripts/debbugs-log.pl'
2048 by Canonical.com Patch Queue Manager
debbugssync, hct enabling, and ui fixes. r=jamesh
31
32
# the minimum age, in days, of a debbugs bug before we will import it
33
MIN_AGE = 7
34
35
4264.2.1 by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it
36
class CreateDebWatches(LaunchpadCronScript):
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
37
    description = """
38
    This script syncs debbugs from http://bugs.debian.org/ into Malone.
39
    It selects interesting bugs in debian and makes sure that there is a
40
    Malone bug for each of them. See debwatchsync for a tool that
41
    syncronises the bugs in Malone and debbugs, too.
42
    """
43
    loglevel = logging.WARNING
44
    def add_my_options(self):
45
        self.parser.set_defaults(max=None, debbugs=debbugs_location_default)
46
        self.parser.add_option('--debbugs', action='store', type='string',
47
            dest='debbugs',
48
            help="The location of your debbugs database.")
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
49
        self.parser.add_option(
50
            '--max', action='store', type='int', dest='max',
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
51
            help="The maximum number of bugs to create.")
52
        self.parser.add_option('--package', action='append', type='string',
53
            help="A list of packages for which we should import bugs.",
54
            dest="packages", default=[])
55
56
    def main(self):
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
57
        index_db_path = os.path.join(self.options.debbugs, 'index/index.db')
58
        if not os.path.exists(index_db_path):
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
59
            # make sure the debbugs location looks sane
60
            raise LaunchpadScriptFailure('%s is not a debbugs db.'
61
                                         % self.options.debbugs)
62
63
        # Make sure we import any Debian bugs specified on the command line
64
        target_bugs = set()
65
        for arg in self.args:
66
            try:
67
                target_bug = int(arg)
68
            except ValueError:
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
69
                self.logger.error(
70
                    '%s is not a valid debian bug number.' % arg)
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
71
            target_bugs.add(target_bug)
72
73
        target_package_set = set()
74
        previousimportset = set()
75
76
        self.logger.info('Calculating target package set...')
77
78
        # first find all the published ubuntu packages
79
        ubuntu = getUtility(ILaunchpadCelebrities).ubuntu
7675.771.2 by William Grant
Port create-debwatches.py away from IDS.publishedBinaryPackages(). The script didn't work anyway, so I'm just going to pretend that I haven't broken it more.
80
        for p in ubuntu.currentrelease.getAllPublishedBinaries():
81
            target_package_set.add(
82
                p.binarypackagerelease.binarypackagename.name)
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
83
        # then add packages passed on the command line
84
        for package in self.options.packages:
85
            target_package_set.add(package)
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
86
        self.logger.info(
87
            '%d binary packages targeted.' % len(target_package_set))
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
88
89
        self.txn.abort()
90
        self.txn.begin()
91
        do_import(self.logger, self.options.max, self.options.debbugs,
92
            target_bugs, target_package_set, previousimportset, MIN_AGE,
93
            debbugs_pl)
94
        self.txn.commit()
95
96
        self.logger.info('Done!')
1149 by Canonical.com Patch Queue Manager
malone debbugs integration
97
8447.1.2 by Jonathan Lange
Fix up lots of lint, including removing code that's been disabled forever.
98
1149 by Canonical.com Patch Queue Manager
malone debbugs integration
99
if __name__ == '__main__':
3691.348.13 by kiko
Convert a couple of cronscripts over to LaunchpadScript
100
    script = CreateDebWatches("debbugs-mkwatch")
101
    script.lock_and_run()
1149 by Canonical.com Patch Queue Manager
malone debbugs integration
102