~launchpad-pqm/launchpad/devel

10637.3.1 by Guilherme Salgado
Use the default python version instead of a hard-coded version
1
#!/usr/bin/python -S
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
2
#
14564.3.1 by Jeroen Vermeulen
Lint.
3
# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.7 by Karl Fogel
Add the copyright header block to more files.
4
# GNU Affero General Public License version 3 (see the file LICENSE).
5
4935.3.7 by Curtis Hovey
Added bad name suppression to cronscripts.
6
# pylint: disable-msg=C0103,W0403
2770.1.56 by Guilherme Salgado
Cleanup loads of code, improved some tests and got all of them to work.
7
14612.2.8 by William Grant
cronscripts
8
import _pythonpath
9
14564.3.1 by Jeroen Vermeulen
Lint.
10
from optparse import OptionParser
11
12
from twisted.internet import (
13
    defer,
14
    reactor,
15
    )
6108.1.1 by Michael Hudson
the fix :(
16
from twisted.python import log as tplog
4898.2.7 by Jonathan Lange
Mirror multiple branches in subprocesses, limited by a semaphore
17
14564.3.1 by Jeroen Vermeulen
Lint.
18
from lp.codehosting.puller import (
19
    mirror,
20
    scheduler,
21
    )
14612.2.8 by William Grant
cronscripts
22
from lp.services.config import config
14565.2.15 by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts.
23
from lp.services.scripts import logger_options
10548.1.1 by Jonathan Lange
Move twistedsupport to lp.services
24
from lp.services.twistedsupport.loggingsupport import (
14564.3.1 by Jeroen Vermeulen
Lint.
25
    LoggingProxy,
26
    set_up_logging_for_script,
27
    )
28
2770.1.56 by Guilherme Salgado
Cleanup loads of code, improved some tests and got all of them to work.
29
4898.2.49 by Jonathan Lange
Make the scripts pass on errors more reliably and fix a bunch of them.
30
def clean_shutdown(ignored):
31
    reactor.stop()
32
33
34
def shutdown_with_errors(failure):
6108.1.1 by Michael Hudson
the fix :(
35
    tplog.err(failure)
4898.2.49 by Jonathan Lange
Make the scripts pass on errors more reliably and fix a bunch of them.
36
    failure.printTraceback()
37
    reactor.stop()
38
39
4898.2.7 by Jonathan Lange
Mirror multiple branches in subprocesses, limited by a semaphore
40
def run_mirror(log, manager):
4898.2.49 by Jonathan Lange
Make the scripts pass on errors more reliably and fix a bunch of them.
41
    # It's conceivable that mirror() might raise an exception before it
42
    # returns a Deferred -- maybeDeferred means we don't have to worry.
43
    deferred = defer.maybeDeferred(mirror, log, manager)
44
    deferred.addCallback(clean_shutdown)
45
    deferred.addErrback(shutdown_with_errors)
4898.2.7 by Jonathan Lange
Mirror multiple branches in subprocesses, limited by a semaphore
46
47
2770.1.56 by Guilherme Salgado
Cleanup loads of code, improved some tests and got all of them to work.
48
if __name__ == '__main__':
49
    parser = OptionParser()
50
    logger_options(parser)
10379.2.4 by Michael Hudson
puller-side changes
51
    parser.add_option('--branch-type', action='append', default=[])
2770.1.56 by Guilherme Salgado
Cleanup loads of code, improved some tests and got all of them to work.
52
    (options, arguments) = parser.parse_args()
53
    if arguments:
54
        parser.error("Unhandled arguments %s" % repr(arguments))
14564.3.1 by Jeroen Vermeulen
Lint.
55
    log = set_up_logging_for_script(
56
        options, 'supermirror_puller', options.log_file)
4898.2.49 by Jonathan Lange
Make the scripts pass on errors more reliably and fix a bunch of them.
57
    manager = scheduler.JobScheduler(
9590.1.49 by Michael Hudson
more combining the puller and filesystem endpoints
58
        LoggingProxy(config.codehosting.codehosting_endpoint, log), log,
10379.2.5 by Michael Hudson
integration test and implied fixes
59
        options.branch_type)
2770.1.62 by Guilherme Salgado
Huge cleanup done on a pair programming session with Rob.
60
4898.2.7 by Jonathan Lange
Mirror multiple branches in subprocesses, limited by a semaphore
61
    reactor.callWhenRunning(run_mirror, log, manager)
62
    reactor.run()