6
6
"""Initialize a new distroseries from its parent series."""
8
from optparse import OptionParser
12
from contrib.glock import GlobalLock
13
11
from zope.component import getUtility
15
from canonical.config import config
16
from canonical.launchpad.scripts import (
17
execute_zcml_for_scripts,
21
from canonical.lp import initZopeless
22
13
from lp.app.errors import NotFoundError
23
14
from lp.registry.interfaces.distribution import IDistributionSet
15
from lp.services.config import config
16
from lp.services.scripts.base import (
18
LaunchpadScriptFailure,
24
20
from lp.soyuz.scripts.initialize_distroseries import (
25
21
InitializationError,
26
22
InitializeDistroSeries,
31
# Parse command-line arguments
32
parser = OptionParser()
33
logger_options(parser)
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.")
39
parser.add_option("-d", "--distro", dest="distribution", metavar="DISTRO",
41
help="Distribution name")
44
"-a", "--arches", dest="arches",
45
help="A comma-seperated list of arches to limit the child "
46
"distroseries to inheriting")
48
(options, args) = parser.parse_args()
50
log = logger(options, "initialize")
53
log.error("Need to be given exactly one non-option argument. "
54
"Namely the distroseries to initialize.")
57
distroseries_name = args[0]
59
log.debug("Acquiring lock")
60
lock = GlobalLock('/var/lock/launchpad-initialize.lock')
61
lock.acquire(blocking=True)
63
log.debug("Initializing connection.")
65
execute_zcml_for_scripts()
66
ztm = initZopeless(dbuser=config.archivepublisher.dbuser)
69
# 'ubuntu' is the default option.distribution value
70
distribution = getUtility(IDistributionSet)[options.distribution]
71
distroseries = distribution[distroseries_name]
72
except NotFoundError, info:
73
log.error('%s not found' % info)
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(s) '
80
'and setting nominatedarchindep.')
82
if options.arches is not None:
83
arches = tuple(options.arches.split(','))
84
# InitializeDistroSeries 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 InitializeDistroSeriesJob is
87
# good, at which point this script will be obsolete.
88
parent, distroseries.previous_series = (
89
distroseries.previous_series, None)
90
ids = InitializeDistroSeries(distroseries, [parent.id], arches)
92
log.debug('initializing from parent(s), copying publishing records.')
94
except InitializationError, e:
99
log.debug('Dry-Run mode, transaction aborted.')
102
log.debug('Committing transaction.')
105
log.debug("Releasing lock")
26
class InitializeFromParentScript(LaunchpadScript):
28
usage = "Usage: %prog [options] <SERIES>"
30
def add_my_options(self):
31
self.parser.add_option(
32
"-N", "--dry-run", action="store_true",
33
dest="dryrun", metavar="DRY_RUN", default=False,
34
help="Whether to treat this as a dry-run or not.")
35
self.parser.add_option(
36
"-d", "--distro", dest="distribution",
37
metavar="DISTRO", default="ubuntu", help="Distribution name")
38
self.parser.add_option(
39
"-a", "--arches", dest="arches",
40
help="A comma-separated list of arches to limit the child "
41
"distroseries to inheriting")
44
if len(self.args) != 1:
45
self.parser.error("SERIES is required")
47
distroseries_name = self.args[0]
50
# 'ubuntu' is the default option.distribution value
51
distribution = getUtility(IDistributionSet)[
52
self.options.distribution]
53
distroseries = distribution[distroseries_name]
54
except NotFoundError, info:
55
raise LaunchpadScriptFailure('%s not found' % info)
59
if self.options.arches is not None:
60
arches = tuple(self.options.arches.split(','))
61
ids = InitializeDistroSeries(distroseries, arches=arches)
62
self.logger.debug("Checking preconditions")
65
"Initializing from parent(s), copying publishing records.")
67
except InitializationError, e:
69
raise LaunchpadScriptFailure(e)
71
if self.options.dryrun:
72
self.logger.debug('Dry-Run mode, transaction aborted.')
75
self.logger.debug('Committing transaction.')
110
79
if __name__ == '__main__':
80
script = InitializeFromParentScript(
81
'initialize-from-parent', config.initializedistroseries.dbuser)