3
# Copyright 2009 Canonical Ltd. This software is licensed under the
3
# Copyright 2009,2010 Canonical Ltd. This software is licensed under the
4
4
# GNU Affero General Public License version 3 (see the file LICENSE).
6
6
# This module uses relative imports.
39
38
from zope.component import getUtility
41
from contrib.glock import GlobalLock, LockAlreadyAcquired
43
40
from canonical import lp
44
from canonical.lp import initZopeless
45
41
from canonical.config import config
42
from canonical.launchpad.scripts import log
44
from lp.services.scripts.base import LaunchpadCronScript
46
45
from lp.soyuz.interfaces.component import IComponentSet
47
from canonical.launchpad.scripts import (
48
execute_zcml_for_scripts, logger_options, log)
50
46
from lp.soyuz.scripts.gina import ExecutionError
51
47
from lp.soyuz.scripts.gina.katie import Katie
52
48
from lp.soyuz.scripts.gina.archive import (ArchiveComponentItems,
53
49
PackagesMap, MangledArchiveError)
55
50
from lp.soyuz.scripts.gina.handlers import (ImporterHandler,
56
51
MultiplePackageReleaseError, NoSourcePackageError, DataSetupError)
57
52
from lp.soyuz.scripts.gina.packages import (SourcePackageData,
74
execute_zcml_for_scripts()
75
parser = OptionParser("Usage: %prog [OPTIONS] [target ...]")
76
logger_options(parser)
78
parser.add_option("-n", "--dry-run", action="store_true",
79
help="Don't commit changes to the database",
80
dest="dry_run", default=False)
82
parser.add_option("-a", "--all", action="store_true",
83
help="Run all sections defined in launchpad.conf (in order)",
84
dest="all", default=False)
86
parser.add_option( "-l", "--lockfile",
87
default="/var/lock/launchpad-gina.lock",
88
help="Ensure only one process is running that locks LOCKFILE",
92
(options, targets) = parser.parse_args()
94
possible_targets = [target.category_and_section_names[1]
95
for target in config.getByCategory('gina_target')]
98
targets = possible_targets[:]
101
parser.error("Must specify at least one target to run, or --all")
103
for target in targets:
104
if target not in possible_targets:
105
parser.error("No Gina target %s in config file" % target)
107
lockfile = GlobalLock(options.lockfile, logger=log)
110
except LockAlreadyAcquired:
111
log.info('Lockfile %s already locked. Exiting.', options.lockfile)
114
ztm = initZopeless(dbuser=config.gina.dbuser)
116
for target in targets:
117
target_section = config['gina_target.%s' % target]
118
run_gina(options, ztm, target_section)
123
68
def run_gina(options, ztm, target_section):
124
69
# Avoid circular imports.
125
70
from lp.registry.interfaces.pocket import PackagePublishingPocket
357
302
importer_handler.commit()
305
class Gina(LaunchpadCronScript):
308
super(Gina, self).__init__(name='gina', dbuser=config.gina.dbuser)
310
def add_my_options(self):
311
self.parser.add_option("-n", "--dry-run", action="store_true",
312
help="Don't commit changes to the database",
313
dest="dry_run", default=False)
314
self.parser.add_option("-a", "--all", action="store_true",
315
help="Run all sections defined in launchpad.conf (in order)",
316
dest="all", default=False)
319
possible_targets = [target.category_and_section_names[1]
320
for target in config.getByCategory('gina_target')]
323
targets = possible_targets[:]
327
"Must specify at least one target to run, or --all")
328
for target in targets:
329
if target not in possible_targets:
331
"No Gina target %s in config file" % target)
333
for target in targets:
334
target_section = config['gina_target.%s' % target]
335
run_gina(self.options, self.txn, target_section)
360
338
if __name__ == "__main__":