annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
1 #!/usr/bin/env python
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
2 # encoding: utf-8
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
3 #
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
4 # Copyright (c) 2010 marcink. All rights reserved.
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
5 #
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
6 '''
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
7 Created on Apr 9, 2010
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
8
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
9 @author: marcink
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
10 '''
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
11 import os
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
12 from pylons import tmpl_context as c, app_globals as g, session, request, config
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
13 from pylons.controllers.util import abort
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
14 try:
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
15 from vcs.backends.hg import get_repositories
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
16 except ImportError:
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
17 print 'You have to import vcs module'
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
18 from mercurial.templatefilters import age
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
19
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
20 class HgModel(object):
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
21 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
22 Mercurial Model
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
23 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
24
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
25
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
26 def __init__(self):
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
27 """
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
28 Constructor
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
29 """
73
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
30 pass
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
31
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
32 def get_repos(self):
73
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
33 for mercurial_repo in get_repositories(g.paths[0][0], g.paths[0][1], g.baseui):
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
34
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
35 if mercurial_repo._get_hidden():
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
36 #skip hidden web repository
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
37 continue
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
38
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
39 last_change = mercurial_repo.last_change
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
40 tip = mercurial_repo.repo.changectx('tip')
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
41 tmp_d = {}
73
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
42 tmp_d['name'] = mercurial_repo.name
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
43 tmp_d['name_sort'] = tmp_d['name']
73
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
44 tmp_d['description'] = mercurial_repo.description
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
45 tmp_d['description_sort'] = tmp_d['description']
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
46 tmp_d['last_change'] = age(last_change)
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
47 tmp_d['last_change_sort'] = last_change[1] - last_change[0]
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
48 tmp_d['tip'] = str(tip)
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
49 tmp_d['tip_sort'] = tip.rev()
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
50 tmp_d['rev'] = tip.rev()
73
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
51 tmp_d['contact'] = mercurial_repo.contact
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
52 tmp_d['contact_sort'] = tmp_d['contact']
55d7f2502dfb Updated model with never vcs implementation using MercurialRepo class
Marcin Kuzminski <marcin@python-blog.com>
parents: 68
diff changeset
53 tmp_d['repo_archives'] = mercurial_repo._get_archive_list()
58
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
54
8fb1abd4178a Added hg model,implemented removal of repos, added HgModel for fetching repos(with generator)
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
55 yield tmp_d