8687.15.6
by Karl Fogel
Add the copyright header block to another file. |
1 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
2 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
3 |
|
4277.4.22
by Jonathan Lange
A tonne of docstrings and comments. |
4 |
"""Bazaar plugin to run the smart server on Launchpad.
|
5 |
||
6 |
Cribbed from bzrlib.builtins.cmd_serve from Bazaar 0.16.
|
|
7 |
"""
|
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
8 |
|
9 |
__metaclass__ = type |
|
10 |
||
11 |
__all__ = ['cmd_launchpad_server'] |
|
12 |
||
13 |
||
7675.578.1
by Michael Hudson
limit lp-serve processes to 4 (decimal) gigabytes |
14 |
import resource |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
15 |
import sys |
16 |
||
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
17 |
from bzrlib.commands import Command, register_command |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
18 |
from bzrlib.option import Option |
8447.1.1
by Jonathan Lange
Clean up all of the pyflakes that we can find. |
19 |
from bzrlib import lockdir, ui |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
20 |
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
21 |
from bzrlib.smart import medium, server |
8496.2.1
by Jonathan Lange
BZR_DEFAULT_* lives in medium, not transport.remote. |
22 |
from bzrlib.transport import get_transport |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
23 |
|
24 |
||
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
25 |
class cmd_launchpad_server(Command): |
26 |
"""Run a Bazaar server that maps Launchpad branch URLs to the internal
|
|
27 |
file-system format.
|
|
28 |
"""
|
|
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
29 |
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
30 |
aliases = ['lp-serve'] |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
31 |
|
32 |
takes_options = [ |
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
33 |
Option('inet', |
34 |
help='serve on stdin/out for use from inetd or sshd'), |
|
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
35 |
Option('port', |
36 |
help='listen for connections on nominated port of the form ' |
|
5520.1.4
by Aaron Bentley
Cleanup |
37 |
'[hostname:]portnumber. Passing 0 as the port number will'
|
38 |
' result in a dynamically allocated port. Default port is'
|
|
39 |
' 4155.', |
|
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
40 |
type=str), |
4330.4.36
by Jonathan Lange
Add a mirror_root parameter the rest of the way up the stack. |
41 |
Option('upload-directory', |
42 |
help='upload branches to this directory. Defaults to ' |
|
7732.1.2
by Jonathan Lange
Change the name of the config variable for the hosted area from |
43 |
'config.codehosting.hosted_branches_root.', |
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
44 |
type=unicode), |
4330.4.36
by Jonathan Lange
Add a mirror_root parameter the rest of the way up the stack. |
45 |
Option('mirror-directory', |
46 |
help='serve branches from this directory. Defaults to ' |
|
7732.1.3
by Jonathan Lange
Get rid of the branchesdest config variable. |
47 |
'config.codehosting.mirrored_branches_root.'), |
9590.1.48
by Michael Hudson
a start at combining the puller and filesystem endpoints |
48 |
Option('codehosting-endpoint', |
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
49 |
help='the url of the internal XML-RPC server. Defaults to ' |
9590.1.48
by Michael Hudson
a start at combining the puller and filesystem endpoints |
50 |
'config.codehosting.codehosting_endpoint.', |
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
51 |
type=unicode), |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
52 |
]
|
53 |
||
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
54 |
takes_args = ['user_id'] |
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
55 |
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
56 |
def get_smart_server(self, transport, port, inet): |
4277.4.39
by Jonathan Lange
Docstrings. |
57 |
"""Construct a smart server."""
|
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
58 |
if inet: |
59 |
smart_server = medium.SmartServerPipeStreamMedium( |
|
60 |
sys.stdin, sys.stdout, transport) |
|
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
61 |
else: |
8496.2.1
by Jonathan Lange
BZR_DEFAULT_* lives in medium, not transport.remote. |
62 |
host = medium.BZR_DEFAULT_INTERFACE |
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
63 |
if port is None: |
8496.2.1
by Jonathan Lange
BZR_DEFAULT_* lives in medium, not transport.remote. |
64 |
port = medium.BZR_DEFAULT_PORT |
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
65 |
else: |
66 |
if ':' in port: |
|
67 |
host, port = port.split(':') |
|
68 |
port = int(port) |
|
69 |
smart_server = server.SmartTCPServer( |
|
70 |
transport, host=host, port=port) |
|
71 |
print 'listening on port: ', smart_server.port |
|
72 |
sys.stdout.flush() |
|
73 |
return smart_server |
|
74 |
||
75 |
def run_server(self, smart_server): |
|
4277.4.39
by Jonathan Lange
Docstrings. |
76 |
"""Run the given smart server."""
|
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
77 |
# for the duration of this server, no UI output is permitted.
|
78 |
# note that this may cause problems with blackbox tests. This should
|
|
5520.1.4
by Aaron Bentley
Cleanup |
79 |
# be changed with care though, as we dont want to use bandwidth
|
80 |
# sending progress over stderr to smart server clients!
|
|
4277.4.7
by Jonathan Lange
Add a sucky implementation of launchpad serving command. |
81 |
old_factory = ui.ui_factory |
82 |
try: |
|
83 |
ui.ui_factory = ui.SilentUIFactory() |
|
84 |
smart_server.serve() |
|
85 |
finally: |
|
86 |
ui.ui_factory = old_factory |
|
87 |
||
9590.1.7
by Michael Hudson
trivial fixes |
88 |
def run(self, user_id, port=None, branch_directory=None, |
9590.1.48
by Michael Hudson
a start at combining the puller and filesystem endpoints |
89 |
codehosting_endpoint_url=None, inet=False): |
7675.240.18
by Jonathan Lange
Actually hook everything up, making sure that OOPSes are logged for Bazaar errors. |
90 |
from lp.codehosting.bzrutils import install_oops_handler |
10547.1.8
by Michael Hudson
gah, fix import |
91 |
from lp.codehosting.vfs import get_lp_server, hooks |
7675.240.18
by Jonathan Lange
Actually hook everything up, making sure that OOPSes are logged for Bazaar errors. |
92 |
install_oops_handler(user_id) |
7675.578.2
by Michael Hudson
easier to read |
93 |
four_gig = int(4e9) |
94 |
resource.setrlimit(resource.RLIMIT_AS, (four_gig, four_gig)) |
|
10547.1.8
by Michael Hudson
gah, fix import |
95 |
seen_new_branch = hooks.SetProcTitleHook() |
7167.9.14
by Michael Hudson
dear holy crap, an acceptance test for bug #297205! |
96 |
lp_server = get_lp_server( |
9590.1.48
by Michael Hudson
a start at combining the puller and filesystem endpoints |
97 |
int(user_id), codehosting_endpoint_url, branch_directory, |
9590.1.14
by Michael Hudson
merge trunk, fixing conflicts |
98 |
seen_new_branch.seen) |
10197.5.7
by Michael Hudson
fix some more stuff |
99 |
lp_server.start_server() |
4292.1.72
by Jonathan Lange
Do our best to clean up everything when we get SIGHUPd |
100 |
|
6266.3.1
by Jonathan Lange
Fix up locking on the smartserver. |
101 |
old_lockdir_timeout = lockdir._DEFAULT_TIMEOUT_SECONDS |
4292.1.70
by Jonathan Lange
Simplistic support for marking branches as needing a mirror if they've been |
102 |
try: |
4816.1.4
by Jonathan Lange
Logging for the smart server transport. Not everything yet, but most things. |
103 |
lp_transport = get_transport(lp_server.get_url()) |
104 |
smart_server = self.get_smart_server(lp_transport, port, inet) |
|
6266.3.1
by Jonathan Lange
Fix up locking on the smartserver. |
105 |
lockdir._DEFAULT_TIMEOUT_SECONDS = 0 |
4292.1.70
by Jonathan Lange
Simplistic support for marking branches as needing a mirror if they've been |
106 |
self.run_server(smart_server) |
107 |
finally: |
|
6266.3.1
by Jonathan Lange
Fix up locking on the smartserver. |
108 |
lockdir._DEFAULT_TIMEOUT_SECONDS = old_lockdir_timeout |
10197.5.7
by Michael Hudson
fix some more stuff |
109 |
lp_server.stop_server() |
4277.4.12
by Jonathan Lange
Shift Launchpad server plugin around. Still no tests :( |
110 |
|
111 |
||
112 |
register_command(cmd_launchpad_server) |