Add support to multiple repositories [PATCH 1/3]

Goffredo Baroncelli kreijack at aliceposta.it
Wed Aug 17 11:40:02 CDT 2005


This patch add the script multiple_index.cgi under the contrib directory.


diff -r 302f83b85054 -r f4e1e30e2d9d contrib/multiple_index.cgi
--- /dev/null   Mon Aug 15 19:46:41 2005
+++ b/contrib/multiple_index.cgi        Wed Aug 17 15:26:36 2005
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+#
+# An example CGI script to index multiple repositories, edit as necessary
+import cgitb, os, sys, stat, cgi, time
+
+# system parameters
+
+# reporitories root
+root = os.getcwd( )
+
+# system-wide mercurial install
+mercurial_path = "/home/ghigo/mercurial/dev-hgweb-index"
+
+# template path
+template_path = mercurial_path + "/templates"
+
+#####################################################
+
+
+cgitb.enable()
+
+sys.path.insert(0, mercurial_path)
+from mercurial import hgweb
+
+#root="/home/ghigo/mercurial"
+
+def getinfo( path ):
+    """this function obtains the info ( author, .... ) from
+    the repositories """
+
+    fname = os.path.join(path,"index.info")
+    map={ "name": path[path.rfind("/")+1:],
+          "description": path[path.rfind("/")+1:],
+          "url" : path[path.rfind("/")+1:],
+          "author" : "...",
+          "lastupdate" : os.stat(os.path.join(path,".hg/00changelog.d")
+                )[stat.ST_MTIME],
+    }
+
+    if os.path.isfile(fname):
+        f = open(fname)
+        for i in f:
+            istripped = i.strip()
+            if len(istripped) == 0 or istripped.startswith("#"): continue
+            (key,value) = i.split("=")
+            map[key.strip()] = value
+        f.close( )
+
+    return map
+
+def inforepositories( **dummy ):
+
+    parity = 0
+    for i in os.listdir(root):
+        path = os.path.join(root, i)
+        if not os.path.isdir(os.path.join(path,".hg")): continue
+        #if not os.path.isfile(os.path.join(path,"index.info")): continue
+
+        map = getinfo( path )
+        yield templ("indexentries", parity = parity, **map )
+        parity = 1 - parity
+
+
+def do_page( ):
+
+    global templ
+
+    def header(**map):
+        yield templ("header", **map)
+
+    def footer(**map):
+        yield templ("footer", **map)
+
+    m = os.path.join(template_path, "map")
+    templ =  hgweb.templater(m, {
+            "escape": cgi.escape,
+            "age": hgweb.age,
+            "date": (lambda x: time.asctime(time.gmtime(x))),
+            "addbreaks": hgweb.nl2br,
+            "obfuscate": hgweb.obfuscate,
+            "short": (lambda x: x[:12]),
+            "firstline": (lambda x: x.splitlines(1)[0]),
+            "permissions": (lambda x: x and "-rwxr-xr-x" or "-rw-r--r--"),
+            "rfc822date": hgweb.rfc822date,
+            },{
+             "header": header,
+             "footer": footer,
+            })
+
+    hgweb.write(templ("multiple_index",
+        entries = inforepositories
+    ))
+
+
+do_page( )
\ No newline at end of file

-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijack @inwind.it>
Key fingerprint = CE3C 7E01 6782 30A3 5B87  87C0 BB86 505C 6B2A CFF9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.selenic.com/pipermail/mercurial/attachments/20050817/d955f59d/attachment.pgp


More information about the Mercurial mailing list