diff pylons_app/controllers/hg.py @ 55:e00dccb6f211

Implemented index page using vcs
author Marcin Kuzminski <marcin@python-blog.com>
date Thu, 08 Apr 2010 22:59:49 +0200
parents 2e1247e62c5b
children bf1b64046c79
line wrap: on
line diff
--- a/pylons_app/controllers/hg.py	Thu Apr 08 18:17:28 2010 +0200
+++ b/pylons_app/controllers/hg.py	Thu Apr 08 22:59:49 2010 +0200
@@ -1,11 +1,19 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 import logging
+import os
 from pylons_app.lib.base import BaseController
 from pylons import tmpl_context as c, app_globals as g, session, request, config
 from pylons_app.lib import helpers as h
 from mako.template import Template
 from pylons.controllers.util import abort
+from pylons_app.lib.base import BaseController, render
+try:
+    from vcs.backends.hg import get_repositories
+except ImportError:
+    print 'You have to import vcs module'
+from mercurial.util import matchdate, Abort, makedate
+from mercurial.hgweb.common import get_contact
 
 log = logging.getLogger(__name__)
 
@@ -13,8 +21,33 @@
 
     def __before__(self):
         c.repos_prefix = config['repos_name']
+        c.staticurl = g.statics
+
+    def index(self):
+        c.repos_list = []
+        
+        def get_mtime(spath):
+            cl_path = os.path.join(spath, "00changelog.i")
+            if os.path.exists(cl_path):
+                return os.stat(cl_path).st_mtime
+            else:
+                return os.stat(spath).st_mtime   
+                
+        for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items():
+            last_change = (get_mtime(r.spath), makedate()[1])
+            tmp = {}
+            tmp['name'] = name
+            tmp['desc'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
+            tmp['last_change'] = last_change,
+            tip = r.changectx('tip')
+            tmp['tip'] = tip.__str__(),
+            tmp['rev'] = tip.rev()
+            tmp['contact'] = get_contact(r.ui.config)
+            c.repos_list.append(tmp)
+        return render('/index.html')
 
     def view(self, *args, **kwargs):
+        #TODO: reimplement this not tu use hgwebdir
         response = g.hgapp(request.environ, self.start_response)
         
         http_accept = request.environ.get('HTTP_ACCEPT', False)