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).
|
|
5 |
||
5991.2.1
by Curtis Hovey
Added appendToOopsPrefix() to GlobalErrorLog to permit external processes to log themselves as the source of an error. |
6 |
# This script uses relative imports.
|
7 |
# pylint: disable-msg=W0403
|
|
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
8 |
|
5343.2.6
by jml at canonical
MOAR DOCSTRINGS |
9 |
"""Script run by cronscripts/supermirror-pull.py to mirror single branches.
|
10 |
||
11 |
Do NOT run this script yourself unless you really know what you are doing. Use
|
|
12 |
cronscripts/supermirror-pull.py instead.
|
|
13 |
||
14 |
Usage: scripts/mirror-branch.py source_url dest_url branch_id unique_name \
|
|
6999.4.13
by Jonathan Lange
Pass the default stacked on URL through to the worker script. Exciting! |
15 |
branch_type oops_prefix default_stacked_on_url
|
5343.2.6
by jml at canonical
MOAR DOCSTRINGS |
16 |
|
17 |
Where:
|
|
18 |
source_url is the location of the branch to be mirrored.
|
|
19 |
dest_url is the location to mirror the branch to.
|
|
20 |
branch_id is the database ID of the branch.
|
|
21 |
unique_name is the unique name of the branch.
|
|
22 |
branch_type is one of HOSTED, MIRRORED, IMPORTED
|
|
23 |
oops_prefix is the OOPS prefix to use, unique in the set of running
|
|
24 |
instances of this script.
|
|
6999.4.51
by Jonathan Lange
Typo & docstring. |
25 |
default_stacked_on_url is the default stacked-on URL of the product that
|
6999.4.13
by Jonathan Lange
Pass the default stacked on URL through to the worker script. Exciting! |
26 |
the branch is in.
|
5343.2.6
by jml at canonical
MOAR DOCSTRINGS |
27 |
"""
|
28 |
||
4966.2.5
by jml at canonical
Reply to most of Andrew's review comments. |
29 |
# This script does not use the standard Launchpad script framework as it is
|
30 |
# not intended to be run by itself.
|
|
31 |
||
32 |
||
4898.2.26
by Jonathan Lange
Refactor server-side protocol to be more generic. Restore '_pythonpath' import |
33 |
import _pythonpath |
4898.2.59
by Jonathan Lange
Record OOPSes for unexpected exceptions in the master. |
34 |
from optparse import OptionParser |
7675.337.1
by Michael Hudson
so this is a total hack, but it seems to work |
35 |
import os |
8545.4.1
by Michael Hudson
well this works |
36 |
import resource |
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
37 |
import sys |
38 |
||
4898.2.59
by Jonathan Lange
Record OOPSes for unexpected exceptions in the master. |
39 |
import bzrlib.repository |
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
40 |
|
8555.2.11
by Tim Penhey
Move the script imports. |
41 |
from lp.code.enums import BranchType |
8426.6.1
by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,' |
42 |
from lp.codehosting.puller.worker import ( |
5294.2.8
by Michael Hudson
OOMPH! |
43 |
install_worker_ui_factory, PullerWorker, PullerWorkerProtocol) |
5899.1.5
by Curtis Hovey
Added conf files. |
44 |
from canonical.launchpad.webapp.errorlog import globalErrorUtility |
5899.1.3
by Curtis Hovey
Save the latest changes before a refresh from RF. |
45 |
|
46 |
||
47 |
branch_type_map = { |
|
48 |
BranchType.MIRRORED: 'mirror', |
|
49 |
BranchType.IMPORTED: 'import' |
|
50 |
}
|
|
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
51 |
|
52 |
||
53 |
def shut_up_deprecation_warning(): |
|
54 |
# XXX DavidAllouche 2006-01-29:
|
|
55 |
# Quick hack to disable the deprecation warning for old repository
|
|
56 |
# formats.
|
|
57 |
bzrlib.repository._deprecation_warning_done = True |
|
58 |
||
4898.2.59
by Jonathan Lange
Record OOPSes for unexpected exceptions in the master. |
59 |
|
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
60 |
def force_bzr_to_use_urllib(): |
61 |
# These lines prevent bzr from using pycurl to connect to http: urls. We
|
|
62 |
# want this for two reasons:
|
|
63 |
# 1) pycurl rejects self signed certificates, which prevents a significant
|
|
64 |
# number of mirror branchs from updating, and
|
|
65 |
# 2) the script sometimes hangs inside pycurl, preventing all mirrors from
|
|
66 |
# being updated until the script is restarted.
|
|
67 |
# There is no test for this (it would involve a great number of moving
|
|
68 |
# parts) but it has been verified to work on production. Also see
|
|
69 |
# https://bugs.launchpad.net/bzr/+bug/82086
|
|
70 |
from bzrlib.transport import register_lazy_transport |
|
71 |
register_lazy_transport('http://', 'bzrlib.transport.http._urllib', |
|
72 |
'HttpTransport_urllib') |
|
73 |
register_lazy_transport('https://', 'bzrlib.transport.http._urllib', |
|
74 |
'HttpTransport_urllib') |
|
75 |
||
76 |
||
77 |
if __name__ == '__main__': |
|
78 |
parser = OptionParser() |
|
79 |
(options, arguments) = parser.parse_args() |
|
4898.2.59
by Jonathan Lange
Record OOPSes for unexpected exceptions in the master. |
80 |
(source_url, destination_url, branch_id, unique_name, |
6999.4.40
by Jonathan Lange
Small nomenclature cleanups. |
81 |
branch_type_name, oops_prefix, default_stacked_on_url) = arguments |
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
82 |
|
83 |
branch_type = BranchType.items[branch_type_name] |
|
7675.337.1
by Michael Hudson
so this is a total hack, but it seems to work |
84 |
if branch_type == BranchType.IMPORTED and 'http_proxy' in os.environ: |
85 |
del os.environ['http_proxy'] |
|
5899.1.13
by Curtis Hovey
Added the remaining conf keys for oopses. |
86 |
section_name = 'supermirror_%s_puller' % branch_type_map[branch_type] |
87 |
globalErrorUtility.configure(section_name) |
|
4898.2.4
by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation. |
88 |
shut_up_deprecation_warning() |
89 |
force_bzr_to_use_urllib() |
|
90 |
||
7675.224.1
by Michael Hudson
increase the address we allow the puller to have |
91 |
resource.setrlimit(resource.RLIMIT_AS, (1500000000, 1500000000)) |
8545.4.1
by Michael Hudson
well this works |
92 |
|
4966.2.5
by jml at canonical
Reply to most of Andrew's review comments. |
93 |
protocol = PullerWorkerProtocol(sys.stdout) |
5294.2.8
by Michael Hudson
OOMPH! |
94 |
install_worker_ui_factory(protocol) |
4898.2.44
by Jonathan Lange
Fix up a couple of missed renames in scripts, extract config variable for |
95 |
PullerWorker( |
4898.2.15
by Jonathan Lange
Make the protocol a parameter of BranchToMirror |
96 |
source_url, destination_url, int(branch_id), unique_name, branch_type, |
6999.4.40
by Jonathan Lange
Small nomenclature cleanups. |
97 |
default_stacked_on_url, protocol, oops_prefix=oops_prefix).mirror() |