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