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
13
from canonical.config import config
16
from canonical.launchpad.scripts import (
17
execute_zcml_for_scripts,
21
from canonical.lp import initZopeless
22
14
from lp.app.errors import NotFoundError
23
15
from lp.registry.interfaces.distribution import IDistributionSet
16
from lp.services.scripts.base import LaunchpadScript, LaunchpadScriptFailure
24
17
from lp.soyuz.scripts.initialize_distroseries import (
25
18
InitializationError,
26
19
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.initializedistroseries.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
ids = InitializeDistroSeries(distroseries, arches=arches)
86
log.debug('initializing from parent(s), copying publishing records.')
88
except InitializationError, e:
94
log.debug('Dry-Run mode, transaction aborted.')
97
log.debug('Committing transaction.')
100
log.debug("Releasing lock")
23
class InitializeFromParentScript(LaunchpadScript):
25
usage = "Usage: %prog [options] <SERIES>"
27
def add_my_options(self):
28
self.parser.add_option(
29
"-N", "--dry-run", action="store_true",
30
dest="dryrun", metavar="DRY_RUN", default=False,
31
help="Whether to treat this as a dry-run or not.")
32
self.parser.add_option(
33
"-d", "--distro", dest="distribution",
34
metavar="DISTRO", default="ubuntu", help="Distribution name")
35
self.parser.add_option(
36
"-a", "--arches", dest="arches",
37
help="A comma-seperated list of arches to limit the child "
38
"distroseries to inheriting")
41
if len(self.args) != 1:
42
self.parser.error("SERIES is required")
44
distroseries_name = self.args[0]
47
# 'ubuntu' is the default option.distribution value
48
distribution = getUtility(IDistributionSet)[
49
self.options.distribution]
50
distroseries = distribution[distroseries_name]
51
except NotFoundError, info:
52
raise LaunchpadScriptFailure('%s not found' % info)
56
if self.options.arches is not None:
57
arches = tuple(self.options.arches.split(','))
58
ids = InitializeDistroSeries(distroseries, arches=arches)
59
self.logger.debug("Checking preconditions")
62
"Initializing from parent(s), copying publishing records.")
64
except InitializationError, e:
66
raise LaunchpadScriptFailure(e)
68
if self.options.dryrun:
69
self.logger.debug('Dry-Run mode, transaction aborted.')
72
self.logger.debug('Committing transaction.')
105
76
if __name__ == '__main__':
77
script = InitializeFromParentScript(
78
'initialize-from-parent', config.initializedistroseries.dbuser)