##// END OF EJS Templates
Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
marcink -
r136:36102488 default
parent child Browse files
Show More
@@ -1,94 +1,106 b''
1 import os
1 import os
2 import logging
2 import logging
3 from mercurial import ui, config, hg
3 from mercurial import ui, config, hg
4 from mercurial.error import RepoError
4 from mercurial.error import RepoError
5 log = logging.getLogger(__name__)
5 log = logging.getLogger(__name__)
6
6
7
7
8 def get_repo_slug(request):
8 def get_repo_slug(request):
9 path_info = request.environ.get('PATH_INFO')
9 path_info = request.environ.get('PATH_INFO')
10 uri_lst = path_info.split('/')
10 uri_lst = path_info.split('/')
11 repo_name = uri_lst[1]
11 repo_name = uri_lst[1]
12 return repo_name
12 return repo_name
13
13
14 def is_mercurial(environ):
14 def is_mercurial(environ):
15 """
15 """
16 Returns True if request's target is mercurial server - header
16 Returns True if request's target is mercurial server - header
17 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
17 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
18 """
18 """
19 http_accept = environ.get('HTTP_ACCEPT')
19 http_accept = environ.get('HTTP_ACCEPT')
20 if http_accept and http_accept.startswith('application/mercurial'):
20 if http_accept and http_accept.startswith('application/mercurial'):
21 return True
21 return True
22 return False
22 return False
23
23
24 def check_repo_dir(paths):
24 def check_repo_dir(paths):
25 repos_path = paths[0][1].split('/')
25 repos_path = paths[0][1].split('/')
26 if repos_path[-1] in ['*', '**']:
26 if repos_path[-1] in ['*', '**']:
27 repos_path = repos_path[:-1]
27 repos_path = repos_path[:-1]
28 if repos_path[0] != '/':
28 if repos_path[0] != '/':
29 repos_path[0] = '/'
29 repos_path[0] = '/'
30 if not os.path.isdir(os.path.join(*repos_path)):
30 if not os.path.isdir(os.path.join(*repos_path)):
31 raise Exception('Not a valid repository in %s' % paths[0][1])
31 raise Exception('Not a valid repository in %s' % paths[0][1])
32
32
33 def check_repo(repo_name, base_path):
33 def check_repo(repo_name, base_path):
34
34
35 repo_path = os.path.join(base_path, repo_name)
35 repo_path = os.path.join(base_path, repo_name)
36
36
37 try:
37 try:
38 r = hg.repository(ui.ui(), repo_path)
38 r = hg.repository(ui.ui(), repo_path)
39 hg.verify(r)
39 hg.verify(r)
40 #here we hnow that repo exists it was verified
40 #here we hnow that repo exists it was verified
41 log.info('%s repo is already created', repo_name)
41 log.info('%s repo is already created', repo_name)
42 return False
42 return False
43 #raise Exception('Repo exists')
43 #raise Exception('Repo exists')
44 except RepoError:
44 except RepoError:
45 log.info('%s repo is free for creation', repo_name)
45 log.info('%s repo is free for creation', repo_name)
46 #it means that there is no valid repo there...
46 #it means that there is no valid repo there...
47 return True
47 return True
48
48
49 def make_ui(path='hgwebdir.config', checkpaths=True):
49 def make_ui(path='hgwebdir.config', checkpaths=True):
50 """
50 """
51 A funcion that will read python rc files and make an ui from read options
51 A funcion that will read python rc files and make an ui from read options
52
52
53 @param path: path to mercurial config file
53 @param path: path to mercurial config file
54 """
54 """
55 if not os.path.isfile(path):
55 if not os.path.isfile(path):
56 log.error('Unable to read config file %s' % path)
56 log.error('Unable to read config file %s' % path)
57 return False
57 return False
58 #propagated from mercurial documentation
58 #propagated from mercurial documentation
59 sections = [
59 sections = [
60 'alias',
60 'alias',
61 'auth',
61 'auth',
62 'decode/encode',
62 'decode/encode',
63 'defaults',
63 'defaults',
64 'diff',
64 'diff',
65 'email',
65 'email',
66 'extensions',
66 'extensions',
67 'format',
67 'format',
68 'merge-patterns',
68 'merge-patterns',
69 'merge-tools',
69 'merge-tools',
70 'hooks',
70 'hooks',
71 'http_proxy',
71 'http_proxy',
72 'smtp',
72 'smtp',
73 'patch',
73 'patch',
74 'paths',
74 'paths',
75 'profiling',
75 'profiling',
76 'server',
76 'server',
77 'trusted',
77 'trusted',
78 'ui',
78 'ui',
79 'web',
79 'web',
80 ]
80 ]
81
81
82 baseui = ui.ui()
82 baseui = ui.ui()
83 cfg = config.config()
83 cfg = config.config()
84 cfg.read(path)
84 cfg.read(path)
85 if checkpaths:check_repo_dir(cfg.items('paths'))
85 if checkpaths:check_repo_dir(cfg.items('paths'))
86
86
87 for section in sections:
87 for section in sections:
88 for k, v in cfg.items(section):
88 for k, v in cfg.items(section):
89 baseui.setconfig(section, k, v)
89 baseui.setconfig(section, k, v)
90
90
91 return baseui
91 return baseui
92
92
93 from vcs.backends.base import BaseChangeset
94 from vcs.utils.lazy import LazyProperty
95 class EmptyChangeset(BaseChangeset):
96
97 revision = -1
93
98
99 @LazyProperty
100 def raw_id(self):
101 """
102 Returns raw string identifing this changeset, useful for web
103 representation.
104 """
105 return '0' * 12
94
106
@@ -1,61 +1,66 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # encoding: utf-8
2 # encoding: utf-8
3 #
3 #
4 # Copyright (c) 2010 marcink. All rights reserved.
4 # Copyright (c) 2010 marcink. All rights reserved.
5 #
5 #
6 from vcs.exceptions import RepositoryError
6 '''
7 '''
7 Created on Apr 9, 2010
8 Created on Apr 9, 2010
8
9
9 @author: marcink
10 @author: marcink
10 '''
11 '''
11 import os
12 import os
12 from pylons import tmpl_context as c, app_globals as g, session, request, config
13 from pylons import tmpl_context as c, app_globals as g, session, request, config
13 from pylons.controllers.util import abort
14 from pylons.controllers.util import abort
14 try:
15 try:
15 from vcs.backends.hg import get_repositories, MercurialRepository
16 from vcs.backends.hg import get_repositories, MercurialRepository
16 except ImportError:
17 except ImportError:
17 print 'You have to import vcs module'
18 print 'You have to import vcs module'
18 raise Exception('Unable to import vcs')
19 raise Exception('Unable to import vcs')
19
20
20 class HgModel(object):
21 class HgModel(object):
21 """
22 """
22 Mercurial Model
23 Mercurial Model
23 """
24 """
24
25
25
26
26 def __init__(self):
27 def __init__(self):
27 """
28 """
28 Constructor
29 Constructor
29 """
30 """
30 pass
31 pass
31
32
32 def get_repos(self):
33 def get_repos(self):
33 for mercurial_repo in get_repositories(g.paths[0][0], g.paths[0][1], g.baseui):
34 for mercurial_repo in get_repositories(g.paths[0][0], g.paths[0][1], g.baseui):
34
35
35 if mercurial_repo._get_hidden():
36 if mercurial_repo._get_hidden():
36 #skip hidden web repository
37 #skip hidden web repository
37 continue
38 continue
38
39
39 last_change = mercurial_repo.last_change
40 last_change = mercurial_repo.last_change
40 tip_rev = mercurial_repo._get_revision('tip')
41 try:
41 tip = mercurial_repo.get_changeset(tip_rev)
42 tip = mercurial_repo.get_changeset('tip')
43 except RepositoryError:
44 from pylons_app.lib.utils import EmptyChangeset
45 tip = EmptyChangeset()
46
42 tmp_d = {}
47 tmp_d = {}
43 tmp_d['name'] = mercurial_repo.name
48 tmp_d['name'] = mercurial_repo.name
44 tmp_d['name_sort'] = tmp_d['name']
49 tmp_d['name_sort'] = tmp_d['name']
45 tmp_d['description'] = mercurial_repo.description
50 tmp_d['description'] = mercurial_repo.description
46 tmp_d['description_sort'] = tmp_d['description']
51 tmp_d['description_sort'] = tmp_d['description']
47 tmp_d['last_change'] = last_change
52 tmp_d['last_change'] = last_change
48 tmp_d['last_change_sort'] = last_change[1] - last_change[0]
53 tmp_d['last_change_sort'] = last_change[1] - last_change[0]
49 tmp_d['tip'] = tip._short
54 tmp_d['tip'] = tip.raw_id
50 tmp_d['tip_sort'] = tip_rev
55 tmp_d['tip_sort'] = tip.revision
51 tmp_d['rev'] = tip_rev
56 tmp_d['rev'] = tip.revision
52 tmp_d['contact'] = mercurial_repo.contact
57 tmp_d['contact'] = mercurial_repo.contact
53 tmp_d['contact_sort'] = tmp_d['contact']
58 tmp_d['contact_sort'] = tmp_d['contact']
54 tmp_d['repo_archives'] = list(mercurial_repo._get_archives())
59 tmp_d['repo_archives'] = list(mercurial_repo._get_archives())
55
60
56 yield tmp_d
61 yield tmp_d
57
62
58 def get_repo(self, repo_name):
63 def get_repo(self, repo_name):
59 path = g.paths[0][1].replace('*', '')
64 path = g.paths[0][1].replace('*', '')
60 repo = MercurialRepository(os.path.join(path, repo_name), baseui=g.baseui)
65 repo = MercurialRepository(os.path.join(path, repo_name), baseui=g.baseui)
61 return repo
66 return repo
General Comments 0
You need to be logged in to leave comments. Login now