~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.22 by Karl Fogel
Add the copyright header block to the remaining .py 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).
5
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
6
"""Initialize a new distroseries from its parent series."""
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
7
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
8
from optparse import OptionParser
9
import sys
10
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
11
import _pythonpath
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
12
from contrib.glock import GlobalLock
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
13
from zope.component import getUtility
14
4687.5.18 by Celso Providelo
more review comments, r=salgado.
15
from canonical.config import config
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
16
from canonical.launchpad.scripts import (
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
17
    execute_zcml_for_scripts,
18
    logger,
19
    logger_options,
20
    )
7675.575.1 by William Grant
Move lp.soyuz.interfaces.build.BuildStatus to lp.buildmaster.interfaces.buildbase. Sort various imports along the way.
21
from canonical.lp import initZopeless
11270.1.3 by Tim Penhey
Changed NotFoundError imports - gee there were a lot of them.
22
from lp.app.errors import NotFoundError
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
23
from lp.registry.interfaces.distribution import IDistributionSet
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
24
from lp.soyuz.scripts.initialize_distroseries import (
25
    InitializationError,
26
    InitializeDistroSeries,
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
27
    )
28
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
29
30
def main():
31
    # Parse command-line arguments
32
    parser = OptionParser()
33
    logger_options(parser)
34
35
    parser.add_option("-N", "--dry-run", action="store_true",
36
                      dest="dryrun", metavar="DRY_RUN", default=False,
37
                      help="Whether to treat this as a dry-run or not.")
38
39
    parser.add_option("-d", "--distro", dest="distribution", metavar="DISTRO",
40
                      default="ubuntu",
41
                      help="Distribution name")
42
11393.1.1 by Steve Kowalik
* Limit the number of arches we copy when so instructed.
43
    parser.add_option(
44
        "-a", "--arches", dest="arches",
45
        help="A comma-seperated list of arches to limit the child "
46
        "distroseries to inheriting")
47
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
48
    (options, args) = parser.parse_args()
49
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
50
    log = logger(options, "initialize")
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
51
52
    if len(args) != 1:
53
        log.error("Need to be given exactly one non-option argument. "
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
54
                  "Namely the distroseries to initialize.")
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
55
        return 1
56
4285.2.5 by Mark Shuttleworth
Test fixes for renamed series
57
    distroseries_name = args[0]
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
58
59
    log.debug("Acquiring lock")
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
60
    lock = GlobalLock('/var/lock/launchpad-initialize.lock')
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
61
    lock.acquire(blocking=True)
62
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
63
    log.debug("Initializing connection.")
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
64
5821.5.14 by James Henstridge
Run execute_zcml_for_scripts() before initZopeless() in many tests.
65
    execute_zcml_for_scripts()
13457.4.8 by Raphael Badin
Use initializedistroseries user instead of archivepublisher to run initialize-from-parent.
66
    ztm = initZopeless(dbuser=config.initializedistroseries.dbuser)
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
67
68
    try:
3500.2.20 by Celso Providelo
review comments from kiko
69
        # 'ubuntu' is the default option.distribution value
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
70
        distribution = getUtility(IDistributionSet)[options.distribution]
4285.2.5 by Mark Shuttleworth
Test fixes for renamed series
71
        distroseries = distribution[distroseries_name]
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
72
    except NotFoundError, info:
11258.1.7 by Steve Kowalik
* Remove some more now unused imports from distroseries.
73
        log.error('%s not found' % info)
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
74
        return 1
75
11258.1.3 by Steve Kowalik
* Clean up the test to reflect that the script will now error and then exit,
76
    try:
77
        log.debug('Check empty mutable queues in parentseries')
78
        log.debug('Check for no pending builds in parentseries')
13117.2.1 by Raphael Badin
Fix initseries to support multiple parents as an argument.
79
        log.debug('Copying distroarchseries from parent(s) '
11258.1.3 by Steve Kowalik
* Clean up the test to reflect that the script will now error and then exit,
80
                      'and setting nominatedarchindep.')
11393.1.1 by Steve Kowalik
* Limit the number of arches we copy when so instructed.
81
        arches = ()
82
        if options.arches is not None:
83
            arches = tuple(options.arches.split(','))
13168.13.7 by Raphael Badin
Merge devel.
84
        ids = InitializeDistroSeries(distroseries, arches=arches)
11258.1.10 by Steve Kowalik
* Undo test changes.
85
        ids.check()
13194.2.1 by Gavin Panella
Change all uses of 'initialise' to 'initialize'.
86
        log.debug('initializing from parent(s), copying publishing records.')
87
        ids.initialize()
88
    except InitializationError, e:
13168.12.34 by Raphael Badin
Abort transaction if InitializationError is triggered in initialize-from-parent.py.
89
        ztm.abort()
11258.1.6 by Steve Kowalik
* Remove unneeded import from distroseries, and move it to IDS.
90
        log.error(e)
11258.1.3 by Steve Kowalik
* Clean up the test to reflect that the script will now error and then exit,
91
        return 1
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
92
93
    if options.dryrun:
94
        log.debug('Dry-Run mode, transaction aborted.')
95
        ztm.abort()
96
    else:
97
        log.debug('Committing transaction.')
98
        ztm.commit()
99
100
    log.debug("Releasing lock")
101
    lock.release()
102
    return 0
103
3500.2.12 by Celso Providelo
Improve initialiase-from-parent to set changeslist if required, added a script top-level tast for it. Fix IBuild.can_be_reset to not reset released builds.
104
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
105
if __name__ == '__main__':
106
    sys.exit(main())