3944.1.1
by Francis J. Lacoste
Use system version python2.4 for scripts. |
1 |
#!/usr/bin/python2.4
|
2733
by Canonical.com Patch Queue Manager
Upload processor. r=stevea |
2 |
"""Upload processor.
|
3 |
||
4 |
Given a bunch of context information and a bunch of files, process them as
|
|
5 |
an upload to a distro/whatever within the launchpad.
|
|
6 |
"""
|
|
7 |
||
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
8 |
import os |
3691.96.1
by Malcolm Cleaton
Replace missing import _pythonpath (doh!) |
9 |
import _pythonpath |
10 |
||
4197.1.1
by Christian Reis
Break apart upload code into canonical/archiveuploader |
11 |
from canonical.archiveuploader.uploadpolicy import policy_options |
12 |
from canonical.archiveuploader.uploadprocessor import UploadProcessor |
|
2733
by Canonical.com Patch Queue Manager
Upload processor. r=stevea |
13 |
from canonical.config import config |
3691.428.5
by Celso Providelo
more review comments. |
14 |
from canonical.launchpad.scripts.base import ( |
15 |
LaunchpadScript, LaunchpadScriptFailure) |
|
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
16 |
|
17 |
||
18 |
class ProcessUpload(LaunchpadScript): |
|
3691.428.2
by Celso Providelo
merge kiko's work on LPScript. |
19 |
|
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
20 |
def add_my_options(self): |
3691.428.2
by Celso Providelo
merge kiko's work on LPScript. |
21 |
self.parser.add_option( |
22 |
"-n", "--dry-run", action="store_true", |
|
23 |
dest="dryrun", metavar="DRY_RUN", default=False, |
|
3691.428.7
by Celso Providelo
applying last review comments. |
24 |
help=("Whether to treat this as a dry-run or not." |
25 |
"Also implies -KM.")) |
|
3691.428.2
by Celso Providelo
merge kiko's work on LPScript. |
26 |
|
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.") |
|
31 |
||
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.") |
|
36 |
||
37 |
self.parser.add_option( |
|
38 |
"-J", "--just-leaf", action="store", dest="leafname", |
|
39 |
default=None, help="A specific leaf dir to limit to.", |
|
40 |
metavar = "LEAF") |
|
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
41 |
policy_options(self.parser) |
42 |
||
43 |
def main(self): |
|
44 |
if not self.args: |
|
3691.428.2
by Celso Providelo
merge kiko's work on LPScript. |
45 |
raise LaunchpadScriptFailure( |
46 |
"Need to be given exactly one non-option "
|
|
47 |
"argument, namely the fsroot for the upload.") |
|
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
48 |
|
49 |
self.options.base_fsroot = os.path.abspath(self.args[0]) |
|
50 |
||
51 |
if not os.path.isdir(self.options.base_fsroot): |
|
3691.428.2
by Celso Providelo
merge kiko's work on LPScript. |
52 |
raise LaunchpadScriptFailure( |
53 |
"%s is not a directory" % self.options.base_fsroot) |
|
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
54 |
|
55 |
self.logger.debug("Initialising connection.") |
|
3691.428.7
by Celso Providelo
applying last review comments. |
56 |
UploadProcessor( |
57 |
self.options, self.txn, self.logger).processUploadQueue() |
|
3673.6.1
by Malcolm Cleaton
Tidying process-upload script and tests |
58 |
|
3691.428.5
by Celso Providelo
more review comments. |
59 |
@property
|
60 |
def lockfilename(self): |
|
61 |
"""Return specific lockfilename according the policy used.
|
|
62 |
||
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
|
|
65 |
of each other.
|
|
66 |
"""
|
|
67 |
return "process-upload-%s.lock" % self.options.context |
|
3023.4.1
by Christian Reis
Handle review comments from Salgado and Spiv |
68 |
|
2733
by Canonical.com Patch Queue Manager
Upload processor. r=stevea |
69 |
if __name__ == '__main__': |
3691.348.26
by kiko
Convert process-upload.py to use a lockfile that varies according to which upload policy is being used. |
70 |
script = ProcessUpload('process-upload', dbuser=config.uploader.dbuser) |
71 |
script.lock_and_run() |
|
72 |