~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python
"""Upload processor.

Given a bunch of context information and a bunch of files, process them as
an upload to a distro/whatever within the launchpad.
"""

import _pythonpath

import os
import sys
from optparse import OptionParser

from canonical.lp import initZopeless
from canonical.config import config
from canonical.launchpad.scripts import (
    execute_zcml_for_scripts, logger, logger_options)

from canonical.archivepublisher.uploadpolicy import policy_options
from canonical.archivepublisher.uploadprocessor import UploadProcessor

def main():
    options = readOptions()
    log = logger(options, "process-upload")
    log.debug("Initialising connection.")
    ztm = initZopeless(dbuser=config.uploader.dbuser)
    execute_zcml_for_scripts()
    UploadProcessor(options, ztm, log).processUploadQueue()
    return 0


def readOptions():
    """Read the command-line options and return an options object."""
    parser = OptionParser()
    logger_options(parser)
    policy_options(parser)

    parser.add_option("-N", "--dry-run", action="store_true",
                      dest="dryrun", metavar="DRY_RUN", default=False,
                      help=("Whether to treat this as a dry-run or not. "
                            "Implicitly set -KM."))
    
    parser.add_option("-K", "--keep", action="store_true",
                      dest="keep", metavar="KEEP", default=False,
                      help="Whether to keep or not the uploads directory.")
    
    parser.add_option("-M", "--no-mails", action="store_true",
                      dest="nomails", default=False,
                      help="Whether to suppress the sending of mails or not.")
    
    parser.add_option("-J", "--just-leaf", action="store", dest="leafname",
                      default=None, help="A specific leaf dir to limit to.",
                      metavar = "LEAF")
    
    (options, args) = parser.parse_args()
    
    if len(args) != 1:
        raise ValueError("Need to be given exactly one non-option"
                         "argument, namely the fsroot for the upload.")
    options.base_fsroot = os.path.abspath(args[0])
    
    if not os.path.isdir(options.base_fsroot):
        raise ValueError("%s is not a directory" % options.base_fsroot)
    
    return options


if __name__ == '__main__':
    sys.exit(main())