~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
11258.1.9 by Steve Kowalik
Add a docstring to InitialiseDistroSeries, and correct slight thinko with the script's docstring
6
"""Initialise 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
11258.1.3 by Steve Kowalik
* Clean up the test to reflect that the script will now error and then exit,
24
from lp.soyuz.scripts.initialise_distroseries import (
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
25
    InitialisationError,
26
    InitialiseDistroSeries,
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
3500.3.40 by Celso Providelo
unrelated typo fixes in i-f-p.
50
    log = logger(options, "initialise")
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. "
4285.2.5 by Mark Shuttleworth
Test fixes for renamed series
54
                  "Namely the distroseries to initialise.")
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")
3500.3.40 by Celso Providelo
unrelated typo fixes in i-f-p.
60
    lock = GlobalLock('/var/lock/launchpad-initialise.lock')
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
61
    lock.acquire(blocking=True)
62
63
    log.debug("Initialising connection.")
64
5821.5.14 by James Henstridge
Run execute_zcml_for_scripts() before initZopeless() in many tests.
65
    execute_zcml_for_scripts()
4687.5.18 by Celso Providelo
more review comments, r=salgado.
66
    ztm = initZopeless(dbuser=config.archivepublisher.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')
79
        log.debug('Copying distroarchseries from parent '
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(','))
12494.1.87 by Gavin Panella
Update the initialise-from-parent tests.
84
        # InitialiseDistroSeries does not like it if the parent series is
85
        # specified on the child, so we must unset it and pass it in. This is
86
        # a temporary hack until confidence in InitialiseDistroSeriesJob is
87
        # good, at which point this script will be obsolete.
88
        parent, distroseries.parent_series = distroseries.parent_series, None
89
        ids = InitialiseDistroSeries(parent, distroseries, arches)
11258.1.10 by Steve Kowalik
* Undo test changes.
90
        ids.check()
11258.1.3 by Steve Kowalik
* Clean up the test to reflect that the script will now error and then exit,
91
        log.debug('initialising from parent, copying publishing records.')
92
        ids.initialise()
11258.1.6 by Steve Kowalik
* Remove unneeded import from distroseries, and move it to IDS.
93
    except InitialisationError, e:
94
        log.error(e)
11258.1.3 by Steve Kowalik
* Clean up the test to reflect that the script will now error and then exit,
95
        return 1
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
96
97
    if options.dryrun:
98
        log.debug('Dry-Run mode, transaction aborted.')
99
        ztm.abort()
100
    else:
101
        log.debug('Committing transaction.')
102
        ztm.commit()
103
104
    log.debug("Releasing lock")
105
    lock.release()
106
    return 0
107
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.
108
3500.2.11 by Celso Providelo
Experimental script to execute initialiseFromParent.
109
if __name__ == '__main__':
110
    sys.exit(main())