diff pylons_app/controllers/hg.py @ 58:8fb1abd4178a

Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
author Marcin Kuzminski <marcin@python-blog.com>
date Fri, 09 Apr 2010 03:00:20 +0200
parents e96bc5a01490
children cdf4fda66dd9
line wrap: on
line diff
--- a/pylons_app/controllers/hg.py	Fri Apr 09 01:42:48 2010 +0200
+++ b/pylons_app/controllers/hg.py	Fri Apr 09 03:00:20 2010 +0200
@@ -8,14 +8,9 @@
 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
-from mercurial.templatefilters import age
 from operator import itemgetter
+
+from pylons_app.model.hg_model import HgModel
 log = logging.getLogger(__name__)
 
 class HgController(BaseController):
@@ -25,43 +20,10 @@
         c.staticurl = g.statics
 
     def index(self):
-        c.repos_list = []
+        hg_model = HgModel()
+        c.repos_list = list(hg_model.get_repos())
         c.current_sort = request.GET.get('sort', 'name')
         
-        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   
-        
-        def archivelist(ui, nodeid, url):
-            allowed = g.baseui.configlist("web", "allow_archive", untrusted=True)
-            for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
-                if i[0] in allowed or ui.configbool("web", "allow" + i[0],
-                                                    untrusted=True):
-                    yield {"type" : i[0], "extension": i[1],
-                           "node": nodeid, "url": url}
-
-        for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items():
-            last_change = (get_mtime(r.spath), makedate()[1])
-            tip = r.changectx('tip')
-            tmp_d = {}
-            tmp_d['name'] = name
-            tmp_d['name_sort'] = tmp_d['name']
-            tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
-            tmp_d['description_sort'] = tmp_d['description']
-            tmp_d['last_change'] = age(last_change)
-            tmp_d['last_change_sort'] = last_change[1] - last_change[0]
-            tmp_d['tip'] = str(tip)
-            tmp_d['tip_sort'] = tip.rev()
-            tmp_d['rev'] = tip.rev()
-            tmp_d['contact'] = get_contact(r.ui.config)
-            tmp_d['contact_sort'] = get_contact(r.ui.config)
-            tmp_d['repo_archives'] = archivelist(r.ui, "tip", 'sa')
-            
-            c.repos_list.append(tmp_d)
-        
         cs = c.current_sort
         c.cs_slug = cs.replace('-', '')
         sortables = ['name', 'description', 'last_change', 'tip', 'contact']