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.codeimport.worker import ( |
13756.4.1
by Jelmer Vernooij
Re-import bzr code imports. |
28 |
BzrImportWorker, BzrSvnImportWorker, CSCVSImportWorker, |
29 |
CodeImportBranchOpenPolicy, CodeImportSourceDetails, GitImportWorker, |
|
30 |
HgImportWorker, get_default_bazaar_branch_store) |
|
13756.3.9
by Jelmer Vernooij
Require specifying branch opener policy. |
31 |
from lp.codehosting.safe_open import AcceptAnythingPolicy |
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
32 |
from canonical.launchpad import scripts |
33 |
||
34 |
||
13756.3.10
by Jelmer Vernooij
Default to default access policy. |
35 |
opener_policies = { |
36 |
"anything": AcceptAnythingPolicy(), |
|
37 |
"default": CodeImportBranchOpenPolicy() |
|
38 |
}
|
|
39 |
||
40 |
||
10249.3.1
by Michael Hudson
force bzrlib to use urllib for http transports |
41 |
def force_bzr_to_use_urllib(): |
10249.3.3
by Michael Hudson
stupid typo |
42 |
"""Prevent bzr from using pycurl to connect to http: urls.
|
10249.3.2
by Michael Hudson
comment -> docstring |
43 |
|
44 |
We want this because pycurl rejects self signed certificates, which
|
|
45 |
prevents a significant number of import branchs from updating. Also see
|
|
13756.3.10
by Jelmer Vernooij
Default to default access policy. |
46 |
https://bugs.launchpad.net/bzr/+bug/516222.
|
10249.3.2
by Michael Hudson
comment -> docstring |
47 |
"""
|
10249.3.1
by Michael Hudson
force bzrlib to use urllib for http transports |
48 |
from bzrlib.transport import register_lazy_transport |
49 |
register_lazy_transport('http://', 'bzrlib.transport.http._urllib', |
|
50 |
'HttpTransport_urllib') |
|
51 |
register_lazy_transport('https://', 'bzrlib.transport.http._urllib', |
|
52 |
'HttpTransport_urllib') |
|
53 |
||
54 |
||
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
55 |
class CodeImportWorker: |
56 |
||
57 |
def __init__(self): |
|
58 |
parser = OptionParser() |
|
59 |
scripts.logger_options(parser) |
|
13756.3.12
by Jelmer Vernooij
Document new options. |
60 |
parser.add_option( |
61 |
"--access-policy", type="choice", metavar="ACCESS_POLICY", |
|
62 |
choices=["anything", "default"], default="default", |
|
63 |
help="Access policy to use when accessing branches to import.") |
|
13756.3.10
by Jelmer Vernooij
Default to default access policy. |
64 |
self.options, self.args = parser.parse_args() |
65 |
self.logger = scripts.logger(self.options, 'code-import-worker') |
|
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
66 |
|
5821.1.2
by Michael Hudson
the script, with some wibbling |
67 |
def main(self): |
10249.3.1
by Michael Hudson
force bzrlib to use urllib for http transports |
68 |
force_bzr_to_use_urllib() |
6015.2.4
by Michael Hudson
docstrings and some renaming |
69 |
source_details = CodeImportSourceDetails.fromArguments(self.args) |
7675.85.2
by Jonathan Lange
Undo revision generated by step 2 of process. |
70 |
if source_details.rcstype == 'git': |
8615.12.7
by Michael Hudson
increase parameterization, fails in an interesting way though! |
71 |
import_worker_cls = GitImportWorker |
7675.76.2
by Michael Hudson
small refactoring |
72 |
elif source_details.rcstype == 'bzr-svn': |
7675.76.4
by Michael Hudson
merge lots of trunk, fixing conflicts |
73 |
import_worker_cls = BzrSvnImportWorker |
9905.7.8
by Jelmer Vernooij
Rely on sqlite support in bzr-hg, build mercurial locally, add mercurial import tests. |
74 |
elif source_details.rcstype == 'hg': |
9905.7.3
by Jelmer Vernooij
Initial work on a HgImportWorker. |
75 |
import_worker_cls = HgImportWorker |
13756.4.1
by Jelmer Vernooij
Re-import bzr code imports. |
76 |
elif source_details.rcstype == 'bzr': |
77 |
import_worker_cls = BzrImportWorker |
|
13168.11.1
by Jelmer Vernooij
Initial work on supporting FAILURE_INVALID and FAILURE_UNSUPPORTED_FEATURE return types from imports. |
78 |
elif source_details.rcstype in ['cvs', 'svn']: |
79 |
import_worker_cls = CSCVSImportWorker |
|
7675.85.2
by Jonathan Lange
Undo revision generated by step 2 of process. |
80 |
else: |
13168.11.1
by Jelmer Vernooij
Initial work on supporting FAILURE_INVALID and FAILURE_UNSUPPORTED_FEATURE return types from imports. |
81 |
raise AssertionError( |
82 |
'unknown rcstype %r' % source_details.rcstype) |
|
8615.12.7
by Michael Hudson
increase parameterization, fails in an interesting way though! |
83 |
import_worker = import_worker_cls( |
84 |
source_details, |
|
85 |
get_transport(config.codeimport.foreign_tree_store), |
|
13756.3.9
by Jelmer Vernooij
Require specifying branch opener policy. |
86 |
get_default_bazaar_branch_store(), self.logger, |
13756.3.10
by Jelmer Vernooij
Default to default access policy. |
87 |
opener_policies[self.options.access_policy]) |
10224.12.7
by Michael Hudson
tests and ugly code for having the workers exit with the right code |
88 |
return import_worker.run() |
5821.1.2
by Michael Hudson
the script, with some wibbling |
89 |
|
5821.1.3
by Michael Hudson
ok, there were config entries already |
90 |
|
5821.1.2
by Michael Hudson
the script, with some wibbling |
91 |
if __name__ == '__main__': |
6015.2.3
by Michael Hudson
move the rest of the worker gubbins over to the non-db style |
92 |
script = CodeImportWorker() |
10224.12.7
by Michael Hudson
tests and ugly code for having the workers exit with the right code |
93 |
sys.exit(script.main()) |