Changeset - 55d7f2502dfb
[Not reviewed]
default
0 1 0
Marcin Kuzminski - 16 years ago 2010-04-11 22:57:16
marcin@python-blog.com
Updated model with never vcs implementation using MercurialRepo class
1 file changed with 14 insertions and 26 deletions:
0 comments (0 inline, 0 general)
pylons_app/model/hg_model.py
Show inline comments
 
@@ -15,8 +15,6 @@ 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
 

	
 
class HgModel(object):
 
@@ -29,39 +27,29 @@ class HgModel(object):
 
        """
 
        Constructor
 
        """
 
        
 

	
 
    def get_mtime(self, 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(self, 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}
 
        pass
 

	
 
    def get_repos(self):
 
        for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items():
 
            last_change = (self.get_mtime(r.spath), makedate()[1])
 
            tip = r.changectx('tip')
 
        for mercurial_repo in get_repositories(g.paths[0][0], g.paths[0][1], g.baseui):
 
            
 
            if mercurial_repo._get_hidden():
 
                #skip hidden web repository
 
                continue
 
            
 
            last_change = mercurial_repo.last_change
 
            tip = mercurial_repo.repo.changectx('tip')
 
            tmp_d = {}
 
            tmp_d['name'] = name
 
            tmp_d['name'] = mercurial_repo.name
 
            tmp_d['name_sort'] = tmp_d['name']
 
            tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True)
 
            tmp_d['description'] = mercurial_repo.description
 
            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) or 'unknown'
 
            tmp_d['contact_sort'] = get_contact(r.ui.config)
 
            tmp_d['repo_archives'] = self.archivelist(r.ui, "tip", 'sa')
 
            tmp_d['contact'] = mercurial_repo.contact
 
            tmp_d['contact_sort'] = tmp_d['contact']
 
            tmp_d['repo_archives'] = mercurial_repo._get_archive_list()
 
            
 
            yield tmp_d
0 comments (0 inline, 0 general)