3944.1.1
by Francis J. Lacoste
Use system version python2.4 for scripts. |
1 |
#!/usr/bin/python2.4
|
2902.2.12
by Andrew Bennetts
Changes requested by Robert's review. |
2 |
# Copyright 2005 Canonical Ltd. All rights reserved.
|
4935.3.7
by Curtis Hovey
Added bad name suppression to cronscripts. |
3 |
# pylint: disable-msg=C0103,W0403
|
2902.2.1
by Andrew Bennetts
Initial commit of supermirror_rewritemap.py script. |
4 |
|
5 |
"""Generate a file mapping ~user/product/branch to on-disk paths, suitable for
|
|
6 |
use with Apache's RewriteMap directive.
|
|
2902.2.2
by Andrew Bennetts
Correct local paths for branches, and add some notes about Apache config directives. |
7 |
|
8 |
Apache config notes:
|
|
9 |
||
10 |
- magic incantation::
|
|
11 |
|
|
12 |
RewriteMap branch-list txt:/path/to/map-file.txt
|
|
13 |
...
|
|
14 |
RewriteEngine On
|
|
15 |
# Assume branch dirs are kept in a directory 'branches' under the
|
|
16 |
# DocumentRoot
|
|
2902.2.12
by Andrew Bennetts
Changes requested by Robert's review. |
17 |
RewriteRule ^/(~[^/]+/[^/]+/[^/]+)/(.*)$ branches/${branch-list:$1}/$2 [L]
|
2902.2.2
by Andrew Bennetts
Correct local paths for branches, and add some notes about Apache config directives. |
18 |
|
19 |
- UserDir directive must not be in effect if you want to be able to rewrite
|
|
20 |
top-level ~user paths.
|
|
2902.2.1
by Andrew Bennetts
Initial commit of supermirror_rewritemap.py script. |
21 |
"""
|
22 |
||
23 |
__metaclass__ = type |
|
24 |
||
25 |
import _pythonpath |
|
2902.2.10
by Andrew Bennetts
Bump default log level up to WARNING, so that normally the rewritemap cronscript will be silent. |
26 |
import logging |
2902.2.1
by Andrew Bennetts
Initial commit of supermirror_rewritemap.py script. |
27 |
|
5121.1.2
by jml at canonical
Move the rewritemap script into codehosting. |
28 |
from canonical.codehosting import rewritemap |
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
29 |
from canonical.launchpad.scripts.base import (LaunchpadCronScript, |
3691.348.19
by kiko
Two more scripts converted. |
30 |
LaunchpadScriptFailure) |
2902.2.1
by Andrew Bennetts
Initial commit of supermirror_rewritemap.py script. |
31 |
from canonical.config import config |
32 |
||
3691.348.19
by kiko
Two more scripts converted. |
33 |
|
4264.2.1
by James Henstridge
add a LaunchpadCronScript subclass, and make cronscripts/*.py use it |
34 |
class SupermirrorRewriteMap(LaunchpadCronScript): |
3691.348.19
by kiko
Two more scripts converted. |
35 |
loglevel = logging.WARNING |
36 |
def main(self): |
|
37 |
if len(self.args) != 1: |
|
38 |
raise LaunchpadScriptFailure('expected a filename argument') |
|
39 |
||
40 |
filename = self.args[0] |
|
41 |
self.txn.begin() |
|
2902.2.1
by Andrew Bennetts
Initial commit of supermirror_rewritemap.py script. |
42 |
outfile = open(filename, 'wb') |
5121.1.2
by jml at canonical
Move the rewritemap script into codehosting. |
43 |
rewritemap.write_map(outfile) |
2902.2.12
by Andrew Bennetts
Changes requested by Robert's review. |
44 |
outfile.close() |
3691.348.19
by kiko
Two more scripts converted. |
45 |
self.txn.abort() |
2902.2.1
by Andrew Bennetts
Initial commit of supermirror_rewritemap.py script. |
46 |
|
47 |
||
48 |
if __name__ == '__main__': |
|
3691.348.19
by kiko
Two more scripts converted. |
49 |
script = SupermirrorRewriteMap('supermirror-rewritemap', |
50 |
dbuser=config.supermirror.dbuser) |
|
51 |
script.lock_and_run(implicit_begin=False) |
|
52 |