~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.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 \
14104.6.23 by Robert Collins
Nuke setOopsToken unneeded in a concurrency safe world.
15
                                branch_type 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
6999.4.51 by Jonathan Lange
Typo & docstring.
23
  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!
24
      the branch is in.
5343.2.6 by jml at canonical
MOAR DOCSTRINGS
25
"""
26
4966.2.5 by jml at canonical
Reply to most of Andrew's review comments.
27
# This script does not use the standard Launchpad script framework as it is
28
# not intended to be run by itself.
29
30
4898.2.26 by Jonathan Lange
Refactor server-side protocol to be more generic. Restore '_pythonpath' import
31
import _pythonpath
14612.2.7 by William Grant
scripts
32
4898.2.59 by Jonathan Lange
Record OOPSes for unexpected exceptions in the master.
33
from optparse import OptionParser
7675.337.1 by Michael Hudson
so this is a total hack, but it seems to work
34
import os
8545.4.1 by Michael Hudson
well this works
35
import resource
4898.2.4 by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation.
36
import sys
37
4898.2.59 by Jonathan Lange
Record OOPSes for unexpected exceptions in the master.
38
import bzrlib.repository
4898.2.4 by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation.
39
8555.2.11 by Tim Penhey
Move the script imports.
40
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,'
41
from lp.codehosting.puller.worker import (
14612.2.7 by William Grant
scripts
42
    install_worker_ui_factory,
43
    PullerWorker,
44
    PullerWorkerProtocol,
45
    )
14600.2.2 by Curtis Hovey
Moved webapp to lp.services.
46
from lp.services.webapp.errorlog import globalErrorUtility
5899.1.3 by Curtis Hovey
Save the latest changes before a refresh from RF.
47
48
49
branch_type_map = {
50
    BranchType.MIRRORED: 'mirror',
51
    BranchType.IMPORTED: 'import'
52
    }
4898.2.4 by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation.
53
54
55
def shut_up_deprecation_warning():
56
    # XXX DavidAllouche 2006-01-29:
57
    # Quick hack to disable the deprecation warning for old repository
58
    # formats.
59
    bzrlib.repository._deprecation_warning_done = True
60
4898.2.59 by Jonathan Lange
Record OOPSes for unexpected exceptions in the master.
61
4898.2.4 by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation.
62
def force_bzr_to_use_urllib():
63
    # These lines prevent bzr from using pycurl to connect to http: urls.  We
64
    # want this for two reasons:
65
    # 1) pycurl rejects self signed certificates, which prevents a significant
66
    #    number of mirror branchs from updating, and
67
    # 2) the script sometimes hangs inside pycurl, preventing all mirrors from
68
    #    being updated until the script is restarted.
69
    # There is no test for this (it would involve a great number of moving
70
    # parts) but it has been verified to work on production.  Also see
71
    # https://bugs.launchpad.net/bzr/+bug/82086
72
    from bzrlib.transport import register_lazy_transport
73
    register_lazy_transport('http://', 'bzrlib.transport.http._urllib',
74
                            'HttpTransport_urllib')
75
    register_lazy_transport('https://', 'bzrlib.transport.http._urllib',
76
                            'HttpTransport_urllib')
77
78
79
if __name__ == '__main__':
80
    parser = OptionParser()
81
    (options, arguments) = parser.parse_args()
4898.2.59 by Jonathan Lange
Record OOPSes for unexpected exceptions in the master.
82
    (source_url, destination_url, branch_id, unique_name,
14104.6.23 by Robert Collins
Nuke setOopsToken unneeded in a concurrency safe world.
83
     branch_type_name, default_stacked_on_url) = arguments
4898.2.4 by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation.
84
85
    branch_type = BranchType.items[branch_type_name]
7675.337.1 by Michael Hudson
so this is a total hack, but it seems to work
86
    if branch_type == BranchType.IMPORTED and 'http_proxy' in os.environ:
87
        del os.environ['http_proxy']
5899.1.13 by Curtis Hovey
Added the remaining conf keys for oopses.
88
    section_name = 'supermirror_%s_puller' % branch_type_map[branch_type]
89
    globalErrorUtility.configure(section_name)
4898.2.4 by Jonathan Lange
Do the actual mirroring in a subprocess. Very naive implementation.
90
    shut_up_deprecation_warning()
91
    force_bzr_to_use_urllib()
92
7675.224.1 by Michael Hudson
increase the address we allow the puller to have
93
    resource.setrlimit(resource.RLIMIT_AS, (1500000000, 1500000000))
8545.4.1 by Michael Hudson
well this works
94
4966.2.5 by jml at canonical
Reply to most of Andrew's review comments.
95
    protocol = PullerWorkerProtocol(sys.stdout)
5294.2.8 by Michael Hudson
OOMPH!
96
    install_worker_ui_factory(protocol)
4898.2.44 by Jonathan Lange
Fix up a couple of missed renames in scripts, extract config variable for
97
    PullerWorker(
4898.2.15 by Jonathan Lange
Make the protocol a parameter of BranchToMirror
98
        source_url, destination_url, int(branch_id), unique_name, branch_type,
14104.6.23 by Robert Collins
Nuke setOopsToken unneeded in a concurrency safe world.
99
        default_stacked_on_url, protocol).mirror()