Show More
@@ -1,53 +1,56 b'' | |||
|
1 | 1 | """Routes configuration |
|
2 | 2 | |
|
3 | 3 | The more specific and detailed routes should be defined first so they |
|
4 | 4 | may take precedent over the more generic routes. For more information |
|
5 | 5 | refer to the routes manual at http://routes.groovie.org/docs/ |
|
6 | 6 | """ |
|
7 | 7 | from routes import Mapper |
|
8 | 8 | |
|
9 | 9 | def make_map(config): |
|
10 | 10 | """Create, configure and return the routes Mapper""" |
|
11 | 11 | map = Mapper(directory=config['pylons.paths']['controllers'], |
|
12 | 12 | always_scan=config['debug']) |
|
13 | 13 | map.minimization = False |
|
14 | 14 | map.explicit = False |
|
15 | 15 | |
|
16 | 16 | # The ErrorController route (handles 404/500 error pages); it should |
|
17 | 17 | # likely stay at the top, ensuring it can always be resolved |
|
18 | 18 | map.connect('/error/{action}', controller='error') |
|
19 | 19 | map.connect('/error/{action}/{id}', controller='error') |
|
20 | 20 | |
|
21 | 21 | # CUSTOM ROUTES HERE |
|
22 | 22 | map.connect('hg_home', '/', controller='hg', action='index') |
|
23 | 23 | |
|
24 | 24 | |
|
25 | 25 | #REST controllers |
|
26 | 26 | map.resource('repo', 'repos', path_prefix='/_admin') |
|
27 | 27 | map.resource('user', 'users', path_prefix='/_admin') |
|
28 | 28 | |
|
29 | 29 | #ADMIN |
|
30 | 30 | with map.submapper(path_prefix='/_admin', controller='admin') as m: |
|
31 | 31 | m.connect('admin_home', '/', action='index')#main page |
|
32 |
m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
|
|
32 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', | |
|
33 | action='add_repo') | |
|
33 | 34 | |
|
34 | 35 | |
|
35 | 36 | map.connect('changeset_home', '/{repo_name}/changeset/{revision}', |
|
36 | 37 | controller='changeset', revision='tip') |
|
37 | 38 | map.connect('summary_home', '/{repo_name}/summary', |
|
38 | 39 | controller='summary') |
|
39 | 40 | map.connect('shortlog_home', '/{repo_name}/shortlog/{revision}', |
|
40 | 41 | controller='shortlog', revision='tip') |
|
41 | 42 | map.connect('branches_home', '/{repo_name}/branches', |
|
42 | 43 | controller='branches') |
|
43 | 44 | map.connect('tags_home', '/{repo_name}/tags', |
|
44 | 45 | controller='tags') |
|
45 | 46 | map.connect('changelog_home', '/{repo_name}/changelog/{revision}', |
|
46 | 47 | controller='changelog', revision='tip') |
|
47 | 48 | map.connect('files_home', '/{repo_name}/files/{revision}/{f_path:.*}', |
|
48 | 49 | controller='files', revision='tip', f_path='') |
|
49 | 50 | map.connect('files_diff_home', '/{repo_name}/diff/{f_path:.*}', |
|
50 | 51 | controller='files', action='diff', revision='tip', f_path='') |
|
51 | 52 | map.connect('files_raw_home', '/{repo_name}/rawfile/{revision}/{f_path:.*}', |
|
52 | 53 | controller='files', action='rawfile', revision='tip', f_path='') |
|
54 | map.connect('files_archive_home', '/{repo_name}/archive/{revision}/{fileformat}', | |
|
55 | controller='files', action='archivefile', revision='tip') | |
|
53 | 56 | return map |
@@ -1,93 +1,108 b'' | |||
|
1 | 1 | import logging |
|
2 | 2 | |
|
3 | 3 | from pylons import request, response, session, tmpl_context as c, url, config, app_globals as g |
|
4 | 4 | from pylons.controllers.util import abort, redirect |
|
5 | 5 | |
|
6 | 6 | from pylons_app.lib.base import BaseController, render |
|
7 | 7 | from pylons_app.lib.utils import get_repo_slug |
|
8 | 8 | from pylons_app.model.hg_model import HgModel |
|
9 | 9 | from difflib import unified_diff |
|
10 | 10 | from pylons_app.lib.differ import render_udiff |
|
11 | 11 | from vcs.exceptions import RepositoryError, ChangesetError |
|
12 | 12 | |
|
13 | 13 | log = logging.getLogger(__name__) |
|
14 | 14 | |
|
15 | 15 | class FilesController(BaseController): |
|
16 | 16 | def __before__(self): |
|
17 | 17 | c.repos_prefix = config['repos_name'] |
|
18 | 18 | c.repo_name = get_repo_slug(request) |
|
19 | 19 | |
|
20 | 20 | def index(self, repo_name, revision, f_path): |
|
21 | 21 | hg_model = HgModel() |
|
22 | 22 | c.repo = repo = hg_model.get_repo(c.repo_name) |
|
23 | revision = request.POST.get('at_rev', None) or revision | |
|
23 | 24 | |
|
24 | revision = request.POST.get('at_rev', None) or revision | |
|
25 | if request.POST.get('view_low'): | |
|
26 | revision = int(revision) - 1 | |
|
27 | if request.POST.get('view_high'): | |
|
28 | revision = int(revision) + 1 | |
|
25 | def get_next_rev(cur): | |
|
29 | 26 | max_rev = len(c.repo.revisions) - 1 |
|
30 | if revision > max_rev: | |
|
31 |
|
|
|
27 | r = cur + 1 | |
|
28 | if r > max_rev: | |
|
29 | r = max_rev | |
|
30 | return r | |
|
31 | ||
|
32 | def get_prev_rev(cur): | |
|
33 | r = cur - 1 | |
|
34 | return r | |
|
32 | 35 | |
|
33 | 36 | c.f_path = f_path |
|
34 | 37 | |
|
35 | 38 | |
|
36 | 39 | try: |
|
37 |
c |
|
|
40 | cur_rev = repo.get_changeset(revision).revision | |
|
41 | prev_rev = repo.get_changeset(get_prev_rev(cur_rev)).raw_id | |
|
42 | next_rev = repo.get_changeset(get_next_rev(cur_rev)).raw_id | |
|
43 | ||
|
44 | c.url_prev = url('files_home', repo_name=c.repo_name, | |
|
45 | revision=prev_rev, f_path=f_path) | |
|
46 | c.url_next = url('files_home', repo_name=c.repo_name, | |
|
47 | revision=next_rev, f_path=f_path) | |
|
48 | ||
|
49 | c.changeset = repo.get_changeset(revision) | |
|
38 | 50 | try: |
|
39 | 51 | c.file_msg = c.changeset.get_file_message(f_path) |
|
40 | 52 | except: |
|
41 | 53 | c.file_msg = None |
|
42 | 54 | |
|
43 | 55 | c.cur_rev = c.changeset.raw_id |
|
44 | 56 | c.rev_nr = c.changeset.revision |
|
45 | 57 | c.files_list = c.changeset.get_node(f_path) |
|
46 | 58 | c.file_history = self._get_history(repo, c.files_list, f_path) |
|
47 | 59 | |
|
48 | 60 | except (RepositoryError, ChangesetError): |
|
49 | 61 | c.files_list = None |
|
50 | 62 | |
|
51 | 63 | return render('files/files.html') |
|
52 | 64 | |
|
53 | 65 | def rawfile(self, repo_name, revision, f_path): |
|
54 | 66 | hg_model = HgModel() |
|
55 | 67 | c.repo = hg_model.get_repo(c.repo_name) |
|
56 | 68 | file_node = c.repo.get_changeset(revision).get_node(f_path) |
|
57 | 69 | response.headers['Content-type'] = file_node.mimetype |
|
58 | 70 | response.headers['Content-disposition'] = 'attachment; filename=%s' \ |
|
59 | 71 | % f_path.split('/')[-1] |
|
60 | 72 | return file_node.content |
|
61 | 73 | |
|
74 | def archivefile(self, repo_name, revision, fileformat): | |
|
75 | return '%s %s %s' % (repo_name, revision, fileformat) | |
|
76 | ||
|
62 | 77 | def diff(self, repo_name, f_path): |
|
63 | 78 | hg_model = HgModel() |
|
64 | 79 | diff1 = request.GET.get('diff1') |
|
65 | 80 | diff2 = request.GET.get('diff2') |
|
66 | 81 | c.no_changes = diff1 == diff2 |
|
67 | 82 | c.f_path = f_path |
|
68 | 83 | c.repo = hg_model.get_repo(c.repo_name) |
|
69 | 84 | c.changeset_1 = c.repo.get_changeset(diff1) |
|
70 | 85 | c.changeset_2 = c.repo.get_changeset(diff2) |
|
71 | 86 | |
|
72 | 87 | c.file_1 = c.changeset_1.get_file_content(f_path) |
|
73 | 88 | c.file_2 = c.changeset_2.get_file_content(f_path) |
|
74 | 89 | c.diff1 = 'r%s:%s' % (c.changeset_1.revision, c.changeset_1._short) |
|
75 | 90 | c.diff2 = 'r%s:%s' % (c.changeset_2.revision, c.changeset_2._short) |
|
76 | 91 | |
|
77 | 92 | d2 = unified_diff(c.file_1.splitlines(1), c.file_2.splitlines(1)) |
|
78 | 93 | c.diff_files = render_udiff(udiff=d2) |
|
79 | 94 | |
|
80 | 95 | if len(c.diff_files) < 1: |
|
81 | 96 | c.no_changes = True |
|
82 | 97 | return render('files/file_diff.html') |
|
83 | 98 | |
|
84 | 99 | def _get_history(self, repo, node, f_path): |
|
85 | 100 | from vcs.nodes import NodeKind |
|
86 | 101 | if not node.kind is NodeKind.FILE: |
|
87 | 102 | return [] |
|
88 | 103 | changesets = node.history |
|
89 | 104 | hist_l = [] |
|
90 | 105 | for chs in changesets: |
|
91 | 106 | n_desc = 'r%s:%s' % (chs.revision, chs._short) |
|
92 | 107 | hist_l.append((chs._short, n_desc,)) |
|
93 | 108 | return hist_l |
@@ -1,66 +1,66 b'' | |||
|
1 | 1 | <%def name="file_class(node)"> |
|
2 | 2 | %if node.is_file(): |
|
3 | 3 | <%return "browser-file" %> |
|
4 | 4 | %else: |
|
5 | 5 | <%return "browser-dir"%> |
|
6 | 6 | %endif |
|
7 | 7 | </%def> |
|
8 | 8 | <div id="body" class="browserblock"> |
|
9 | 9 | <div class="browser-header"> |
|
10 | 10 | ${h.form(h.url.current())} |
|
11 | <span>${_('view')}@rev ${h.submit('view_low','-')}${h.text('at_rev',value=c.rev_nr,size='5')}${h.submit('view_high','+')}</span> | |
|
11 | <span>${_('view')}@rev <a style="font-size: 1.3em" href="${c.url_prev}">«</a>${h.text('at_rev',value=c.rev_nr,size='5')}<a style="font-size: 1.3em" href="${c.url_next}">»</a></span> | |
|
12 | 12 | ${h.submit('view','view')} |
|
13 | 13 | ${h.end_form()} |
|
14 | 14 | </div> |
|
15 | 15 |
<div class="browser-body"> |
|
16 | 16 | <table class="code-browser"> |
|
17 | 17 | <thead> |
|
18 | 18 | <tr> |
|
19 | 19 | <th>${_('Name')}</th> |
|
20 | 20 | <th>${_('Size')}</th> |
|
21 | 21 | <th>${_('Revision')}</th> |
|
22 | 22 | <th>${_('Last modified')}</th> |
|
23 | 23 | <th>${_('Last commiter')}</th> |
|
24 | 24 | </tr> |
|
25 | 25 | </thead> |
|
26 | 26 | <tr class="parity0"> |
|
27 | 27 | <td> |
|
28 | 28 | % if c.files_list.parent: |
|
29 | 29 | ${h.link_to('..',h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=c.files_list.parent.path),class_="browser-dir")} |
|
30 | 30 | %endif |
|
31 | 31 | </td> |
|
32 | 32 | <td></td> |
|
33 | 33 | <td></td> |
|
34 | 34 | <td></td> |
|
35 | 35 | <td></td> |
|
36 | 36 | </tr> |
|
37 | 37 | %for cnt,node in enumerate(c.files_list,1): |
|
38 | 38 | <tr class="parity${cnt%2}"> |
|
39 | 39 | <td> |
|
40 | 40 | ${h.link_to(node.name,h.url('files_home',repo_name=c.repo_name,revision=c.cur_rev,f_path=node.path),class_=file_class(node))} |
|
41 | 41 | </td> |
|
42 | 42 | <td> |
|
43 | 43 | %if node.is_file(): |
|
44 | 44 | ${h.filesizeformat(node.size)} |
|
45 | 45 | %endif |
|
46 | 46 | </td> |
|
47 | 47 | <td> |
|
48 | 48 | %if node.is_file(): |
|
49 | 49 | ${node.last_changeset.revision} |
|
50 | 50 | %endif |
|
51 | 51 | </td> |
|
52 | 52 | <td> |
|
53 | 53 | %if node.is_file(): |
|
54 | 54 | ${node.last_changeset.date} |
|
55 | 55 | %endif |
|
56 | 56 | </td> |
|
57 | 57 | <td> |
|
58 | 58 | %if node.is_file(): |
|
59 | 59 | ${node.last_changeset.author} |
|
60 | 60 | %endif |
|
61 | 61 | </td> |
|
62 | 62 | </tr> |
|
63 | 63 | %endfor |
|
64 | 64 | </table> |
|
65 | 65 | </div> |
|
66 | 66 | </div> No newline at end of file |
@@ -1,125 +1,127 b'' | |||
|
1 | 1 | <%inherit file="/base/base.html"/> |
|
2 | 2 | <%! |
|
3 | 3 | from pylons_app.lib import filters |
|
4 | 4 | %> |
|
5 | 5 | <%def name="title()"> |
|
6 | 6 | ${_('Repository managment')} |
|
7 | 7 | </%def> |
|
8 | 8 | <%def name="breadcrumbs()"> |
|
9 | 9 | ${h.link_to(u'Home',h.url('/'))} |
|
10 | 10 | / |
|
11 | 11 | ${h.link_to(c.repo_name,h.url('summary_home',repo_name=c.repo_name))} |
|
12 | 12 | / |
|
13 | 13 | ${_('summary')} |
|
14 | 14 | </%def> |
|
15 | 15 | <%def name="page_nav()"> |
|
16 | 16 | <form action="log"> |
|
17 | 17 | <dl class="search"> |
|
18 | 18 | <dt><label>Search: </label></dt> |
|
19 | 19 | <dd><input type="text" name="rev" /></dd> |
|
20 | 20 | </dl> |
|
21 | 21 | </form> |
|
22 | 22 | |
|
23 | 23 | ${self.menu('summary')} |
|
24 | 24 | </%def> |
|
25 | 25 | <%def name="main()"> |
|
26 | 26 | |
|
27 | 27 | <h2 class="no-link no-border">${_('Mercurial Repository Overview')}</h2> |
|
28 | 28 | <dl class="overview"> |
|
29 | 29 | <dt>${_('name')}</dt> |
|
30 | 30 | <dd>${c.repo_info.name}</dd> |
|
31 | 31 | <dt>${_('description')}</dt> |
|
32 | 32 | <dd>${c.repo_info.description}</dd> |
|
33 | 33 | <dt>${_('contact')}</dt> |
|
34 | 34 | <dd>${c.repo_info.contact}</dd> |
|
35 | 35 | <dt>${_('last change')}</dt> |
|
36 | 36 | <dd>${c.repo_info.last_change|n,filters.rfc822date} - ${c.repo_info.last_change|n,filters.age}</dd> |
|
37 | 37 | <dt>${_('url')}</dt> |
|
38 | 38 | <dd><pre>hg clone <a href="${c.clone_repo_url}">${c.clone_repo_url}</a></pre></dd> |
|
39 | 39 | <dt>${_('Download')}</dt> |
|
40 | 40 | <dd> |
|
41 | %for archive in c.repo_info._get_archives(): | |
|
42 | | <a href="/${c.repo_info.name}/archive/${archive['node']}${archive['extension']}"> | |
|
43 | ${c.repo_info.name}.${archive['type']} | |
|
44 | </a> | |
|
41 | %for cnt,archive in enumerate(c.repo_info._get_archives()): | |
|
42 | %if cnt >=1: | |
|
43 | | | |
|
44 | %endif | |
|
45 | ${h.link_to(c.repo_info.name+'.'+archive['type'], | |
|
46 | h.url('files_archive_home',repo_name=c.repo_info.name, | |
|
47 | revision='tip',fileformat=archive['extension']))} | |
|
45 | 48 | %endfor |
|
46 | | | |
|
47 | 49 | </dd> |
|
48 | 50 | </dl> |
|
49 | 51 | |
|
50 | 52 | <h2>${h.link_to(_('Changes'),h.url('changelog_home',repo_name=c.repo_name))}</h2> |
|
51 | 53 | <table> |
|
52 | 54 | <%def name="message_slug(msg)"> |
|
53 | 55 | <% |
|
54 | 56 | limit = 60 |
|
55 | 57 | if len(msg) > limit: |
|
56 | 58 | return msg[:limit]+'...' |
|
57 | 59 | else: |
|
58 | 60 | return msg |
|
59 | 61 | %> |
|
60 | 62 | </%def> |
|
61 | 63 | %for cnt,cs in enumerate(c.repo_changesets): |
|
62 | 64 | <tr class="parity${cnt%2}"> |
|
63 | 65 | <td>${cs._ctx.date()|n,filters.age}</td> |
|
64 | 66 | <td>${cs.author|n,filters.person}</td> |
|
65 | 67 | <td> |
|
66 | 68 | ${h.link_to(message_slug(cs.message), |
|
67 | 69 | h.url('changeset_home',repo_name=c.repo_name,revision=cs._short), |
|
68 | 70 | title=cs.message)} |
|
69 | 71 | </td> |
|
70 | 72 | <td> |
|
71 | 73 | <span class="logtags"> |
|
72 | 74 | <span class="branchtag">${cs.branch}</span> |
|
73 | 75 | %for tag in cs.tags: |
|
74 | 76 | <span class="tagtag">${tag}</span> |
|
75 | 77 | %endfor |
|
76 | 78 | </span> |
|
77 | 79 | </td> |
|
78 | 80 | <td class="nowrap"> |
|
79 | 81 | ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=cs._short))} |
|
80 | 82 | | |
|
81 | 83 | ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=cs._short))} |
|
82 | 84 | </td> |
|
83 | 85 | </tr> |
|
84 | 86 | %endfor |
|
85 | 87 | </table> |
|
86 | 88 | |
|
87 | 89 | <h2>${h.link_to(_('Tags'),h.url('tags_home',repo_name=c.repo_name))}</h2> |
|
88 | 90 | <table> |
|
89 | 91 | %for cnt,tag in enumerate(c.repo_tags): |
|
90 | 92 | <tr class="parity${cnt%2}"> |
|
91 | 93 | <td>${tag._ctx.date()|n,filters.age}</td> |
|
92 | 94 | <td> |
|
93 | 95 | <span class="logtags"> |
|
94 | 96 | <span class="tagtag">${h.link_to(tag.tags[-1],h.url('changeset_home',repo_name=c.repo_name,revision=tag._short))}</span> |
|
95 | 97 | </span> |
|
96 | 98 | </td> |
|
97 | 99 | <td class="nowrap"> |
|
98 | 100 | ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=tag._short))} |
|
99 | 101 | | |
|
100 | 102 | ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=tag._short))} |
|
101 | 103 | </td> |
|
102 | 104 | </tr> |
|
103 | 105 | %endfor |
|
104 | 106 | </table> |
|
105 | 107 | |
|
106 | 108 | <h2>${h.link_to(_('Branches'),h.url('branches_home',repo_name=c.repo_name))}</h2> |
|
107 | 109 | <table> |
|
108 | 110 | %for cnt,branch in enumerate(c.repo_branches): |
|
109 | 111 | <tr class="parity${cnt%2}"> |
|
110 | 112 | <td>${branch._ctx.date()|n,filters.age}</td> |
|
111 | 113 | <td> |
|
112 | 114 | <span class="logtags"> |
|
113 | 115 | <span class="branchtag">${h.link_to(branch.branch,h.url('changeset_home',repo_name=c.repo_name,revision=branch._short))}</span> |
|
114 | 116 | </span> |
|
115 | 117 | </td> |
|
116 | 118 | <td class="nowrap"> |
|
117 | 119 | ${h.link_to(_('changeset'),h.url('changeset_home',repo_name=c.repo_name,revision=branch._short))} |
|
118 | 120 | | |
|
119 | 121 | ${h.link_to(_('files'),h.url('files_home',repo_name=c.repo_name,revision=branch._short))} |
|
120 | 122 | </td> |
|
121 | 123 | </tr> |
|
122 | 124 | %endfor |
|
123 | 125 | </table> |
|
124 | 126 | |
|
125 | 127 | </%def> No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now