comparison pylons_app/model/hg_model.py @ 73:55d7f2502dfb

Updated model with never vcs implementation using MercurialRepo class
author Marcin Kuzminski <marcin@python-blog.com>
date Sun, 11 Apr 2010 22:57:16 +0200
parents 9f956354807b
children cdf4fda66dd9
comparison
equal deleted inserted replaced
72:596eb21f61d5 73:55d7f2502dfb
13 from pylons.controllers.util import abort 13 from pylons.controllers.util import abort
14 try: 14 try:
15 from vcs.backends.hg import get_repositories 15 from vcs.backends.hg import get_repositories
16 except ImportError: 16 except ImportError:
17 print 'You have to import vcs module' 17 print 'You have to import vcs module'
18 from mercurial.util import matchdate, Abort, makedate
19 from mercurial.hgweb.common import get_contact
20 from mercurial.templatefilters import age 18 from mercurial.templatefilters import age
21 19
22 class HgModel(object): 20 class HgModel(object):
23 """ 21 """
24 Mercurial Model 22 Mercurial Model
27 25
28 def __init__(self): 26 def __init__(self):
29 """ 27 """
30 Constructor 28 Constructor
31 """ 29 """
32 30 pass
33
34 def get_mtime(self, spath):
35 cl_path = os.path.join(spath, "00changelog.i")
36 if os.path.exists(cl_path):
37 return os.stat(cl_path).st_mtime
38 else:
39 return os.stat(spath).st_mtime
40
41 def archivelist(self, ui, nodeid, url):
42 allowed = g.baseui.configlist("web", "allow_archive", untrusted=True)
43 for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]:
44 if i[0] in allowed or ui.configbool("web", "allow" + i[0],
45 untrusted=True):
46 yield {"type" : i[0], "extension": i[1],
47 "node": nodeid, "url": url}
48 31
49 def get_repos(self): 32 def get_repos(self):
50 for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items(): 33 for mercurial_repo in get_repositories(g.paths[0][0], g.paths[0][1], g.baseui):
51 last_change = (self.get_mtime(r.spath), makedate()[1]) 34
52 tip = r.changectx('tip') 35 if mercurial_repo._get_hidden():
36 #skip hidden web repository
37 continue
38
39 last_change = mercurial_repo.last_change
40 tip = mercurial_repo.repo.changectx('tip')
53 tmp_d = {} 41 tmp_d = {}
54 tmp_d['name'] = name 42 tmp_d['name'] = mercurial_repo.name
55 tmp_d['name_sort'] = tmp_d['name'] 43 tmp_d['name_sort'] = tmp_d['name']
56 tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True) 44 tmp_d['description'] = mercurial_repo.description
57 tmp_d['description_sort'] = tmp_d['description'] 45 tmp_d['description_sort'] = tmp_d['description']
58 tmp_d['last_change'] = age(last_change) 46 tmp_d['last_change'] = age(last_change)
59 tmp_d['last_change_sort'] = last_change[1] - last_change[0] 47 tmp_d['last_change_sort'] = last_change[1] - last_change[0]
60 tmp_d['tip'] = str(tip) 48 tmp_d['tip'] = str(tip)
61 tmp_d['tip_sort'] = tip.rev() 49 tmp_d['tip_sort'] = tip.rev()
62 tmp_d['rev'] = tip.rev() 50 tmp_d['rev'] = tip.rev()
63 tmp_d['contact'] = get_contact(r.ui.config) or 'unknown' 51 tmp_d['contact'] = mercurial_repo.contact
64 tmp_d['contact_sort'] = get_contact(r.ui.config) 52 tmp_d['contact_sort'] = tmp_d['contact']
65 tmp_d['repo_archives'] = self.archivelist(r.ui, "tip", 'sa') 53 tmp_d['repo_archives'] = mercurial_repo._get_archive_list()
66 54
67 yield tmp_d 55 yield tmp_d