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