1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/usr/bin/python2.4
# Copyright 2005 Canonical Ltd. All rights reserved.
# pylint: disable-msg=C0103,W0403
"""Generate a file mapping ~user/product/branch to on-disk paths, suitable for
use with Apache's RewriteMap directive.
Apache config notes:
- magic incantation::
RewriteMap branch-list txt:/path/to/map-file.txt
...
RewriteEngine On
# Assume branch dirs are kept in a directory 'branches' under the
# DocumentRoot
RewriteRule ^/(~[^/]+/[^/]+/[^/]+)/(.*)$ branches/${branch-list:$1}/$2 [L]
- UserDir directive must not be in effect if you want to be able to rewrite
top-level ~user paths.
"""
__metaclass__ = type
import _pythonpath
import logging
from canonical.codehosting import rewritemap
from canonical.launchpad.scripts.base import (LaunchpadCronScript,
LaunchpadScriptFailure)
from canonical.config import config
class SupermirrorRewriteMap(LaunchpadCronScript):
loglevel = logging.WARNING
def main(self):
if len(self.args) != 1:
raise LaunchpadScriptFailure('expected a filename argument')
filename = self.args[0]
self.txn.begin()
outfile = open(filename, 'wb')
rewritemap.write_map(outfile)
outfile.close()
self.txn.abort()
if __name__ == '__main__':
script = SupermirrorRewriteMap('supermirror-rewritemap',
dbuser=config.supermirror.dbuser)
script.lock_and_run(implicit_begin=False)
|