|
ds@0
|
1 |
#!/usr/bin/env python |
|
ds@0
|
2 |
# |
|
ds@0
|
3 |
# An example CGI script to export multiple hgweb repos, edit as necessary |
|
ds@0
|
4 |
|
|
ds@0
|
5 |
# adjust python path if not a system-wide install: |
|
ds@0
|
6 |
#import sys |
|
ds@0
|
7 |
#sys.path.insert(0, "/path/to/python/lib") |
|
ds@0
|
8 |
|
|
ds@0
|
9 |
# enable importing on demand to reduce startup time |
|
ds@0
|
10 |
from mercurial import demandimport; demandimport.enable() |
|
ds@0
|
11 |
|
|
ds@0
|
12 |
# Uncomment to send python tracebacks to the browser if an error occurs: |
|
ds@0
|
13 |
import cgitb |
|
ds@0
|
14 |
cgitb.enable() |
|
ds@0
|
15 |
|
|
ds@0
|
16 |
# If you'd like to serve pages with UTF-8 instead of your default |
|
ds@0
|
17 |
# locale charset, you can do so by uncommenting the following lines. |
|
ds@0
|
18 |
# Note that this will cause your .hgrc files to be interpreted in |
|
ds@0
|
19 |
# UTF-8 and all your repo files to be displayed using UTF-8. |
|
ds@0
|
20 |
# |
|
ds@0
|
21 |
import os |
|
ds@0
|
22 |
#os.environ["HGENCODING"] = "UTF-8" |
|
ds@0
|
23 |
|
|
ds@0
|
24 |
from mercurial import extensions |
|
ds@0
|
25 |
from mercurial.hgweb.hgwebdir_mod import hgwebdir |
|
ds@0
|
26 |
import mercurial.hgweb.wsgicgi as wsgicgi |
|
ds@0
|
27 |
|
|
ds@0
|
28 |
# The config file looks like this. You can have paths to individual |
|
ds@0
|
29 |
# repos, collections of repos in a directory tree, or both. |
|
ds@0
|
30 |
# |
|
ds@0
|
31 |
# [paths] |
|
ds@0
|
32 |
# virtual/path1 = /real/path1 |
|
ds@0
|
33 |
# virtual/path2 = /real/path2 |
|
ds@0
|
34 |
# virtual/root = /real/root/* |
|
ds@0
|
35 |
# / = /real/root2/* |
|
ds@0
|
36 |
# virtual/root2 = /real/root2/** |
|
ds@0
|
37 |
# |
|
ds@0
|
38 |
# [collections] |
|
ds@0
|
39 |
# /prefix/to/strip/off = /root/of/tree/full/of/repos |
|
ds@0
|
40 |
# |
|
ds@0
|
41 |
# paths example: |
|
ds@0
|
42 |
# |
|
ds@0
|
43 |
# * First two lines mount one repository into one virtual path, like |
|
ds@0
|
44 |
# '/real/path1' into 'virtual/path1'. |
|
ds@0
|
45 |
# |
|
ds@0
|
46 |
# * The third entry mounts every mercurial repository found in '/real/root' |
|
ds@0
|
47 |
# in 'virtual/root'. This format is preferred over the [collections] one, |
|
ds@0
|
48 |
# since using absolute paths as configuration keys is not supported on every |
|
ds@0
|
49 |
# platform (especially on Windows). |
|
ds@0
|
50 |
# |
|
ds@0
|
51 |
# * The fourth entry is a special case mounting all repositories in |
|
ds@0
|
52 |
# /'real/root2' in the root of the virtual directory. |
|
ds@0
|
53 |
# |
|
ds@0
|
54 |
# * The fifth entry recursively finds all repositories under the real root, |
|
ds@0
|
55 |
# and mounts them using their relative path (to given real root) under the |
|
ds@0
|
56 |
# virtual root. |
|
ds@0
|
57 |
# |
|
ds@0
|
58 |
# collections example: say directory tree /foo contains repos /foo/bar, |
|
ds@0
|
59 |
# /foo/quux/baz. Give this config section: |
|
ds@0
|
60 |
# [collections] |
|
ds@0
|
61 |
# /foo = /foo |
|
ds@0
|
62 |
# Then repos will list as bar and quux/baz. |
|
ds@0
|
63 |
# |
|
ds@0
|
64 |
# Alternatively you can pass a list of ('virtual/path', '/real/path') tuples |
|
ds@0
|
65 |
# or use a dictionary with entries like 'virtual/path': '/real/path' |
|
ds@0
|
66 |
|
|
ds@0
|
67 |
hgroot = '/repo/hg' |
|
ds@0
|
68 |
path = os.environ['SCRIPT_NAME'] |
|
ds@0
|
69 |
repo_list = [] |
|
ds@0
|
70 |
|
|
ds@0
|
71 |
if path is None or path is '': |
|
ds@0
|
72 |
path = hgroot |
|
ds@0
|
73 |
else: |
|
ds@0
|
74 |
path = path.replace('/', hgroot + '/', 1) |
|
ds@0
|
75 |
|
|
ds@0
|
76 |
for item in os.listdir(path): |
|
ds@0
|
77 |
repo_path = os.path.join(path, item) |
|
ds@0
|
78 |
if os.path.isdir(os.path.join(repo_path, '.hg')): |
|
ds@0
|
79 |
repo_list.append(( item, repo_path )) |
|
ds@0
|
80 |
|
|
ds@0
|
81 |
application = hgwebdir(repo_list) |
|
ds@3
|
82 |
application._baseurl = None |
|
ds@0
|
83 |
extensions.loadall(application.ui) |
|
ds@0
|
84 |
wsgicgi.launch(application) |