5
5
an upload to a distro/whatever within the launchpad.
12
from optparse import OptionParser
14
from contrib.glock import GlobalLock, LockAlreadyAcquired
16
11
from canonical.archivepublisher.uploadpolicy import policy_options
17
12
from canonical.archivepublisher.uploadprocessor import UploadProcessor
18
13
from canonical.config import config
19
from canonical.launchpad.scripts import (
20
execute_zcml_for_scripts, logger, logger_options)
21
from canonical.lp import initZopeless
24
_default_lockfile = '/var/lock/process-upload.lock'
28
options = readOptions()
29
log = logger(options, "process-upload")
31
locker = GlobalLock(_default_lockfile, logger=log)
34
except LockAlreadyAcquired:
35
log.error("Cannot acquire lock.")
38
log.debug("Initialising connection.")
39
ztm = initZopeless(dbuser=config.uploader.dbuser)
40
execute_zcml_for_scripts()
43
UploadProcessor(options, ztm, log).processUploadQueue()
51
"""Read the command-line options and return an options object."""
52
parser = OptionParser()
53
logger_options(parser)
54
policy_options(parser)
56
parser.add_option("-N", "--dry-run", action="store_true",
57
dest="dryrun", metavar="DRY_RUN", default=False,
58
help=("Whether to treat this as a dry-run or not. "
59
"Implicitly set -KM."))
61
parser.add_option("-K", "--keep", action="store_true",
62
dest="keep", metavar="KEEP", default=False,
63
help="Whether to keep or not the uploads directory.")
65
parser.add_option("-M", "--no-mails", action="store_true",
66
dest="nomails", default=False,
67
help="Whether to suppress the sending of mails or not.")
69
parser.add_option("-J", "--just-leaf", action="store", dest="leafname",
70
default=None, help="A specific leaf dir to limit to.",
73
(options, args) = parser.parse_args()
76
raise ValueError("Need to be given exactly one non-option "
77
"argument, namely the fsroot for the upload.")
78
options.base_fsroot = os.path.abspath(args[0])
80
if not os.path.isdir(options.base_fsroot):
81
raise ValueError("%s is not a directory" % options.base_fsroot)
14
from canonical.launchpad.scripts.base import (
15
LaunchpadScript, LaunchpadScriptFailure)
18
class ProcessUpload(LaunchpadScript):
20
def add_my_options(self):
21
self.parser.add_option(
22
"-n", "--dry-run", action="store_true",
23
dest="dryrun", metavar="DRY_RUN", default=False,
24
help=("Whether to treat this as a dry-run or not."
27
self.parser.add_option(
28
"-K", "--keep", action="store_true",
29
dest="keep", metavar="KEEP", default=False,
30
help="Whether to keep or not the uploads directory.")
32
self.parser.add_option(
33
"-M", "--no-mails", action="store_true",
34
dest="nomails", default=False,
35
help="Whether to suppress the sending of mails or not.")
37
self.parser.add_option(
38
"-J", "--just-leaf", action="store", dest="leafname",
39
default=None, help="A specific leaf dir to limit to.",
41
policy_options(self.parser)
45
raise LaunchpadScriptFailure(
46
"Need to be given exactly one non-option "
47
"argument, namely the fsroot for the upload.")
49
self.options.base_fsroot = os.path.abspath(self.args[0])
51
if not os.path.isdir(self.options.base_fsroot):
52
raise LaunchpadScriptFailure(
53
"%s is not a directory" % self.options.base_fsroot)
55
self.logger.debug("Initialising connection.")
57
self.options, self.txn, self.logger).processUploadQueue()
60
def lockfilename(self):
61
"""Return specific lockfilename according the policy used.
63
Each different p-u policy requires and uses a different lockfile.
64
This is because they are run by different users and are independent
67
return "process-upload-%s.lock" % self.options.context
86
69
if __name__ == '__main__':
70
script = ProcessUpload('process-upload', dbuser=config.uploader.dbuser)