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.
34
33
from zope.component import getUtility
36
from contrib.glock import GlobalLock, LockAlreadyAcquired
38
35
from canonical import lp
39
from canonical.lp import initZopeless
40
36
from canonical.config import config
37
from canonical.launchpad.scripts import log
39
from lp.services.scripts.base import LaunchpadCronScript
41
40
from lp.soyuz.interfaces.component import IComponentSet
42
from canonical.launchpad.scripts import (
43
execute_zcml_for_scripts, logger_options, log)
45
41
from lp.soyuz.scripts.gina import ExecutionError
46
42
from lp.soyuz.scripts.gina.katie import Katie
47
43
from lp.soyuz.scripts.gina.archive import (ArchiveComponentItems,
48
44
PackagesMap, MangledArchiveError)
50
45
from lp.soyuz.scripts.gina.handlers import (ImporterHandler,
51
46
MultiplePackageReleaseError, NoSourcePackageError, DataSetupError)
52
47
from lp.soyuz.scripts.gina.packages import (SourcePackageData,
69
execute_zcml_for_scripts()
70
parser = OptionParser("Usage: %prog [OPTIONS] [target ...]")
71
logger_options(parser)
73
parser.add_option("-n", "--dry-run", action="store_true",
74
help="Don't commit changes to the database",
75
dest="dry_run", default=False)
77
parser.add_option("-a", "--all", action="store_true",
78
help="Run all sections defined in launchpad.conf (in order)",
79
dest="all", default=False)
81
parser.add_option( "-l", "--lockfile",
82
default="/var/lock/launchpad-gina.lock",
83
help="Ensure only one process is running that locks LOCKFILE",
87
(options, targets) = parser.parse_args()
89
possible_targets = [target.category_and_section_names[1]
90
for target in config.getByCategory('gina_target')]
93
targets = possible_targets[:]
96
parser.error("Must specify at least one target to run, or --all")
98
for target in targets:
99
if target not in possible_targets:
100
parser.error("No Gina target %s in config file" % target)
102
lockfile = GlobalLock(options.lockfile, logger=log)
105
except LockAlreadyAcquired:
106
log.info('Lockfile %s already locked. Exiting.', options.lockfile)
109
ztm = initZopeless(dbuser=config.gina.dbuser)
111
for target in targets:
112
target_section = config['gina_target.%s' % target]
113
run_gina(options, ztm, target_section)
118
63
def run_gina(options, ztm, target_section):
119
64
# Avoid circular imports.
120
65
from lp.registry.interfaces.pocket import PackagePublishingPocket
352
297
importer_handler.commit()
300
class Gina(LaunchpadCronScript):
303
super(Gina, self).__init__(name='gina', dbuser=config.gina.dbuser)
305
def add_my_options(self):
306
self.parser.add_option("-n", "--dry-run", action="store_true",
307
help="Don't commit changes to the database",
308
dest="dry_run", default=False)
309
self.parser.add_option("-a", "--all", action="store_true",
310
help="Run all sections defined in launchpad.conf (in order)",
311
dest="all", default=False)
314
possible_targets = [target.category_and_section_names[1]
315
for target in config.getByCategory('gina_target')]
318
targets = possible_targets[:]
322
"Must specify at least one target to run, or --all")
323
for target in targets:
324
if target not in possible_targets:
326
"No Gina target %s in config file" % target)
328
for target in targets:
329
target_section = config['gina_target.%s' % target]
330
run_gina(self.options, self.txn, target_section)
355
333
if __name__ == "__main__":