10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.22
by Karl Fogel
Add the copyright header block to the remaining .py files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5821.1.2
by Michael Hudson
the script, with some wibbling |
5 |
|
6092.1.7
by Michael Hudson
mostly lint |
6 |
"""Process a code import described by the command line arguments.
|
7 |
||
8 |
By 'processing a code import' we mean importing or updating code from a
|
|
9 |
remote, non-Bazaar, repository.
|
|
10 |
||
8447.4.1
by Michael Hudson
rename code-import-worker-db.py script to code-import-worker-monitor.py |
11 |
This script is usually run by the code-import-worker-monitor.py script that
|
6092.1.7
by Michael Hudson
mostly lint |
12 |
communicates progress and results to the database.
|
5821.1.10
by Michael Hudson
comments from the review |
13 |
"""
|
5821.1.2
by Michael Hudson
the script, with some wibbling |
14 |
|
15 |
__metaclass__ = type |
|
16 |
||
17 |
||
5821.1.9
by Michael Hudson
fix lint |
18 |
# pylint: disable-msg=W0403
|
5821.1.2
by Michael Hudson
the script, with some wibbling |
19 |
import _pythonpath |
20 |
||
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
21 |
from optparse import OptionParser |
10224.12.7
by Michael Hudson
tests and ugly code for having the workers exit with the right code |
22 |
import sys |
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
23 |
|
8615.12.7
by Michael Hudson
increase parameterization, fails in an interesting way though! |
24 |
from bzrlib.transport import get_transport |
25 |
||
26 |
from canonical.config import config |
|
8426.6.1
by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,' |
27 |
from lp.codehosting import load_optional_plugin |
28 |
from lp.codehosting.codeimport.worker import ( |
|
7675.76.3
by Michael Hudson
* implementation and tests for bzr-svn puller |
29 |
BzrSvnImportWorker, CSCVSImportWorker, CodeImportSourceDetails, |
9905.7.3
by Jelmer Vernooij
Initial work on a HgImportWorker. |
30 |
GitImportWorker, HgImportWorker, get_default_bazaar_branch_store) |
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
31 |
from canonical.launchpad import scripts |
32 |
||
33 |
||
10249.3.1
by Michael Hudson
force bzrlib to use urllib for http transports |
34 |
def force_bzr_to_use_urllib(): |
10249.3.3
by Michael Hudson
stupid typo |
35 |
"""Prevent bzr from using pycurl to connect to http: urls.
|
10249.3.2
by Michael Hudson
comment -> docstring |
36 |
|
37 |
We want this because pycurl rejects self signed certificates, which
|
|
38 |
prevents a significant number of import branchs from updating. Also see
|
|
39 |
https://bugs.edge.launchpad.net/bzr/+bug/516222.
|
|
40 |
"""
|
|
10249.3.1
by Michael Hudson
force bzrlib to use urllib for http transports |
41 |
from bzrlib.transport import register_lazy_transport |
42 |
register_lazy_transport('http://', 'bzrlib.transport.http._urllib', |
|
43 |
'HttpTransport_urllib') |
|
44 |
register_lazy_transport('https://', 'bzrlib.transport.http._urllib', |
|
45 |
'HttpTransport_urllib') |
|
46 |
||
47 |
||
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
48 |
class CodeImportWorker: |
49 |
||
50 |
def __init__(self): |
|
51 |
parser = OptionParser() |
|
52 |
scripts.logger_options(parser) |
|
53 |
options, self.args = parser.parse_args() |
|
54 |
self.logger = scripts.logger(options, 'code-import-worker') |
|
55 |
||
5821.1.2
by Michael Hudson
the script, with some wibbling |
56 |
def main(self): |
10249.3.1
by Michael Hudson
force bzrlib to use urllib for http transports |
57 |
force_bzr_to_use_urllib() |
6015.2.4
by Michael Hudson
docstrings and some renaming |
58 |
source_details = CodeImportSourceDetails.fromArguments(self.args) |
7675.85.2
by Jonathan Lange
Undo revision generated by step 2 of process. |
59 |
if source_details.rcstype == 'git': |
60 |
load_optional_plugin('git') |
|
8615.12.7
by Michael Hudson
increase parameterization, fails in an interesting way though! |
61 |
import_worker_cls = GitImportWorker |
7675.76.2
by Michael Hudson
small refactoring |
62 |
elif source_details.rcstype == 'bzr-svn': |
63 |
load_optional_plugin('svn') |
|
7675.76.4
by Michael Hudson
merge lots of trunk, fixing conflicts |
64 |
import_worker_cls = BzrSvnImportWorker |
9905.7.8
by Jelmer Vernooij
Rely on sqlite support in bzr-hg, build mercurial locally, add mercurial import tests. |
65 |
elif source_details.rcstype == 'hg': |
9905.7.3
by Jelmer Vernooij
Initial work on a HgImportWorker. |
66 |
load_optional_plugin('hg') |
67 |
import_worker_cls = HgImportWorker |
|
13168.11.1
by Jelmer Vernooij
Initial work on supporting FAILURE_INVALID and FAILURE_UNSUPPORTED_FEATURE return types from imports. |
68 |
elif source_details.rcstype in ['cvs', 'svn']: |
69 |
import_worker_cls = CSCVSImportWorker |
|
7675.85.2
by Jonathan Lange
Undo revision generated by step 2 of process. |
70 |
else: |
13168.11.1
by Jelmer Vernooij
Initial work on supporting FAILURE_INVALID and FAILURE_UNSUPPORTED_FEATURE return types from imports. |
71 |
raise AssertionError( |
72 |
'unknown rcstype %r' % source_details.rcstype) |
|
8615.12.7
by Michael Hudson
increase parameterization, fails in an interesting way though! |
73 |
import_worker = import_worker_cls( |
74 |
source_details, |
|
75 |
get_transport(config.codeimport.foreign_tree_store), |
|
76 |
get_default_bazaar_branch_store(), self.logger) |
|
10224.12.7
by Michael Hudson
tests and ugly code for having the workers exit with the right code |
77 |
return import_worker.run() |
5821.1.2
by Michael Hudson
the script, with some wibbling |
78 |
|
5821.1.3
by Michael Hudson
ok, there were config entries already |
79 |
|
5821.1.2
by Michael Hudson
the script, with some wibbling |
80 |
if __name__ == '__main__': |
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
81 |
script = CodeImportWorker() |
10224.12.7
by Michael Hudson
tests and ugly code for having the workers exit with the right code |
82 |
sys.exit(script.main()) |