~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
9636.4.2 by Michael Hudson
add some boilerplate
2
#
3
# Copyright 2009 Canonical Ltd.  This software is licensed under the
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
6
import _pythonpath
7
9636.4.33 by Michael Hudson
failing scripty tests
8
from lp.codehosting.branchdistro import DistroBrancher
9590.1.82 by Michael Hudson
start fixing the branch-distro tests
9
from lp.codehosting.vfs import get_rw_server
14612.2.7 by William Grant
scripts
10
from lp.services.scripts.base import (
11
    LaunchpadScript,
12
    LaunchpadScriptFailure,
13
    )
9636.4.2 by Michael Hudson
add some boilerplate
14
15
9636.4.10 by Michael Hudson
blah
16
class BranchDistroScript(LaunchpadScript):
9636.4.41 by Michael Hudson
address review comments
17
9636.4.10 by Michael Hudson
blah
18
    usage = "%prog distro old-series new-series"
9636.4.33 by Michael Hudson
failing scripty tests
19
20
    def add_my_options(self):
21
        self.parser.add_option(
22
            '--check', dest="check", action="store_true", default=False,
23
            help=("Check that the new distro series has its official "
24
                  "branches set up correctly."))
25
9636.4.2 by Michael Hudson
add some boilerplate
26
    def main(self):
9636.4.10 by Michael Hudson
blah
27
        if len(self.args) != 3:
28
            self.parser.error("Wrong number of arguments.")
9636.4.33 by Michael Hudson
failing scripty tests
29
        brancher = DistroBrancher.fromNames(self.logger, *self.args)
9590.1.82 by Michael Hudson
start fixing the branch-distro tests
30
        server = get_rw_server(direct_database=True)
10197.5.9 by Michael Hudson
even more
31
        server.start_server()
9636.4.36 by Michael Hudson
er, hooray unit tests
32
        try:
33
            if self.options.check:
34
                if not brancher.checkNewBranches():
35
                    raise LaunchpadScriptFailure("Check failed")
36
            else:
37
                brancher.makeNewBranches()
38
        finally:
10197.5.9 by Michael Hudson
even more
39
            server.stop_server()
9636.4.2 by Michael Hudson
add some boilerplate
40
41
if __name__ == '__main__':
9636.4.10 by Michael Hudson
blah
42
    BranchDistroScript("branch-distro", dbuser='branch-distro').run()