Show More
@@ -0,0 +1,72 b'' | |||||
|
1 | #!/usr/bin/env python | |||
|
2 | # encoding: utf-8 | |||
|
3 | # | |||
|
4 | # Copyright (c) 2010 marcink. All rights reserved. | |||
|
5 | # | |||
|
6 | ''' | |||
|
7 | Created on Apr 9, 2010 | |||
|
8 | ||||
|
9 | @author: marcink | |||
|
10 | ''' | |||
|
11 | import os | |||
|
12 | from pylons_app.lib.base import BaseController | |||
|
13 | from pylons import tmpl_context as c, app_globals as g, session, request, config | |||
|
14 | from pylons_app.lib import helpers as h | |||
|
15 | from mako.template import Template | |||
|
16 | from pylons.controllers.util import abort | |||
|
17 | from pylons_app.lib.base import BaseController, render | |||
|
18 | try: | |||
|
19 | from vcs.backends.hg import get_repositories | |||
|
20 | except ImportError: | |||
|
21 | print 'You have to import vcs module' | |||
|
22 | from mercurial.util import matchdate, Abort, makedate | |||
|
23 | from mercurial.hgweb.common import get_contact | |||
|
24 | from mercurial.templatefilters import age | |||
|
25 | from operator import itemgetter | |||
|
26 | ||||
|
27 | class HgModel(object): | |||
|
28 | """ | |||
|
29 | Mercurial Model | |||
|
30 | """ | |||
|
31 | ||||
|
32 | ||||
|
33 | def __init__(self): | |||
|
34 | """ | |||
|
35 | Constructor | |||
|
36 | """ | |||
|
37 | ||||
|
38 | ||||
|
39 | def get_mtime(self, spath): | |||
|
40 | cl_path = os.path.join(spath, "00changelog.i") | |||
|
41 | if os.path.exists(cl_path): | |||
|
42 | return os.stat(cl_path).st_mtime | |||
|
43 | else: | |||
|
44 | return os.stat(spath).st_mtime | |||
|
45 | ||||
|
46 | def archivelist(self, ui, nodeid, url): | |||
|
47 | allowed = g.baseui.configlist("web", "allow_archive", untrusted=True) | |||
|
48 | for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: | |||
|
49 | if i[0] in allowed or ui.configbool("web", "allow" + i[0], | |||
|
50 | untrusted=True): | |||
|
51 | yield {"type" : i[0], "extension": i[1], | |||
|
52 | "node": nodeid, "url": url} | |||
|
53 | ||||
|
54 | def get_repos(self): | |||
|
55 | for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items(): | |||
|
56 | last_change = (self.get_mtime(r.spath), makedate()[1]) | |||
|
57 | tip = r.changectx('tip') | |||
|
58 | tmp_d = {} | |||
|
59 | tmp_d['name'] = name | |||
|
60 | tmp_d['name_sort'] = tmp_d['name'] | |||
|
61 | tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True) | |||
|
62 | tmp_d['description_sort'] = tmp_d['description'] | |||
|
63 | tmp_d['last_change'] = age(last_change) | |||
|
64 | tmp_d['last_change_sort'] = last_change[1] - last_change[0] | |||
|
65 | tmp_d['tip'] = str(tip) | |||
|
66 | tmp_d['tip_sort'] = tip.rev() | |||
|
67 | tmp_d['rev'] = tip.rev() | |||
|
68 | tmp_d['contact'] = get_contact(r.ui.config) | |||
|
69 | tmp_d['contact_sort'] = get_contact(r.ui.config) | |||
|
70 | tmp_d['repo_archives'] = self.archivelist(r.ui, "tip", 'sa') | |||
|
71 | ||||
|
72 | yield tmp_d |
@@ -8,14 +8,9 b' from pylons_app.lib import helpers as h' | |||||
8 | from mako.template import Template |
|
8 | from mako.template import Template | |
9 | from pylons.controllers.util import abort |
|
9 | from pylons.controllers.util import abort | |
10 | from pylons_app.lib.base import BaseController, render |
|
10 | from pylons_app.lib.base import BaseController, render | |
11 | try: |
|
|||
12 | from vcs.backends.hg import get_repositories |
|
|||
13 | except ImportError: |
|
|||
14 | print 'You have to import vcs module' |
|
|||
15 | from mercurial.util import matchdate, Abort, makedate |
|
|||
16 | from mercurial.hgweb.common import get_contact |
|
|||
17 | from mercurial.templatefilters import age |
|
|||
18 | from operator import itemgetter |
|
11 | from operator import itemgetter | |
|
12 | ||||
|
13 | from pylons_app.model.hg_model import HgModel | |||
19 | log = logging.getLogger(__name__) |
|
14 | log = logging.getLogger(__name__) | |
20 |
|
15 | |||
21 | class HgController(BaseController): |
|
16 | class HgController(BaseController): | |
@@ -25,43 +20,10 b' class HgController(BaseController):' | |||||
25 | c.staticurl = g.statics |
|
20 | c.staticurl = g.statics | |
26 |
|
21 | |||
27 | def index(self): |
|
22 | def index(self): | |
28 | c.repos_list = [] |
|
23 | hg_model = HgModel() | |
|
24 | c.repos_list = list(hg_model.get_repos()) | |||
29 | c.current_sort = request.GET.get('sort', 'name') |
|
25 | c.current_sort = request.GET.get('sort', 'name') | |
30 |
|
26 | |||
31 | def get_mtime(spath): |
|
|||
32 | cl_path = os.path.join(spath, "00changelog.i") |
|
|||
33 | if os.path.exists(cl_path): |
|
|||
34 | return os.stat(cl_path).st_mtime |
|
|||
35 | else: |
|
|||
36 | return os.stat(spath).st_mtime |
|
|||
37 |
|
||||
38 | def archivelist(ui, nodeid, url): |
|
|||
39 | allowed = g.baseui.configlist("web", "allow_archive", untrusted=True) |
|
|||
40 | for i in [('zip', '.zip'), ('gz', '.tar.gz'), ('bz2', '.tar.bz2')]: |
|
|||
41 | if i[0] in allowed or ui.configbool("web", "allow" + i[0], |
|
|||
42 | untrusted=True): |
|
|||
43 | yield {"type" : i[0], "extension": i[1], |
|
|||
44 | "node": nodeid, "url": url} |
|
|||
45 |
|
||||
46 | for name, r in get_repositories(g.paths[0][0], g.paths[0][1]).items(): |
|
|||
47 | last_change = (get_mtime(r.spath), makedate()[1]) |
|
|||
48 | tip = r.changectx('tip') |
|
|||
49 | tmp_d = {} |
|
|||
50 | tmp_d['name'] = name |
|
|||
51 | tmp_d['name_sort'] = tmp_d['name'] |
|
|||
52 | tmp_d['description'] = r.ui.config('web', 'description', 'Unknown', untrusted=True) |
|
|||
53 | tmp_d['description_sort'] = tmp_d['description'] |
|
|||
54 | tmp_d['last_change'] = age(last_change) |
|
|||
55 | tmp_d['last_change_sort'] = last_change[1] - last_change[0] |
|
|||
56 | tmp_d['tip'] = str(tip) |
|
|||
57 | tmp_d['tip_sort'] = tip.rev() |
|
|||
58 | tmp_d['rev'] = tip.rev() |
|
|||
59 | tmp_d['contact'] = get_contact(r.ui.config) |
|
|||
60 | tmp_d['contact_sort'] = get_contact(r.ui.config) |
|
|||
61 | tmp_d['repo_archives'] = archivelist(r.ui, "tip", 'sa') |
|
|||
62 |
|
||||
63 | c.repos_list.append(tmp_d) |
|
|||
64 |
|
||||
65 | cs = c.current_sort |
|
27 | cs = c.current_sort | |
66 | c.cs_slug = cs.replace('-', '') |
|
28 | c.cs_slug = cs.replace('-', '') | |
67 | sortables = ['name', 'description', 'last_change', 'tip', 'contact'] |
|
29 | sortables = ['name', 'description', 'last_change', 'tip', 'contact'] |
@@ -1,5 +1,5 b'' | |||||
1 | import logging |
|
1 | import logging | |
2 |
|
2 | import os | ||
3 | from pylons import request, response, session, tmpl_context as c, url, app_globals as g |
|
3 | from pylons import request, response, session, tmpl_context as c, url, app_globals as g | |
4 | from pylons.controllers.util import abort, redirect |
|
4 | from pylons.controllers.util import abort, redirect | |
5 | from pylons_app.lib import auth |
|
5 | from pylons_app.lib import auth | |
@@ -7,7 +7,9 b' from pylons_app.lib.base import BaseCont' | |||||
7 | from pylons_app.model import meta |
|
7 | from pylons_app.model import meta | |
8 | from pylons_app.model.db import Users, UserLogs |
|
8 | from pylons_app.model.db import Users, UserLogs | |
9 | from pylons_app.lib.auth import authenticate |
|
9 | from pylons_app.lib.auth import authenticate | |
10 |
|
10 | from pylons_app.model.hg_model import HgModel | ||
|
11 | from operator import itemgetter | |||
|
12 | import shutil | |||
11 | log = logging.getLogger(__name__) |
|
13 | log = logging.getLogger(__name__) | |
12 |
|
14 | |||
13 | class ReposController(BaseController): |
|
15 | class ReposController(BaseController): | |
@@ -26,6 +28,9 b' class ReposController(BaseController):' | |||||
26 | def index(self, format='html'): |
|
28 | def index(self, format='html'): | |
27 | """GET /repos: All items in the collection""" |
|
29 | """GET /repos: All items in the collection""" | |
28 | # url('repos') |
|
30 | # url('repos') | |
|
31 | hg_model = HgModel() | |||
|
32 | c.repos_list = list(hg_model.get_repos()) | |||
|
33 | c.repos_list.sort(key=itemgetter('name')) | |||
29 | return render('/repos.html') |
|
34 | return render('/repos.html') | |
30 |
|
35 | |||
31 | def create(self): |
|
36 | def create(self): | |
@@ -53,6 +58,14 b' class ReposController(BaseController):' | |||||
53 | # h.form(url('repo', id=ID), |
|
58 | # h.form(url('repo', id=ID), | |
54 | # method='delete') |
|
59 | # method='delete') | |
55 | # url('repo', id=ID) |
|
60 | # url('repo', id=ID) | |
|
61 | from datetime import datetime | |||
|
62 | path = g.paths[0][1].replace('*', '') | |||
|
63 | rm_path = os.path.join(path, id) | |||
|
64 | log.info("Removing %s", rm_path) | |||
|
65 | shutil.move(os.path.join(rm_path, '.hg'), os.path.join(rm_path, 'rm__.hg')) | |||
|
66 | shutil.move(rm_path, os.path.join(path, 'rm__%s-%s' % (datetime.today(), id))) | |||
|
67 | return redirect(url('repos')) | |||
|
68 | ||||
56 |
|
69 | |||
57 | def show(self, id, format='html'): |
|
70 | def show(self, id, format='html'): | |
58 | """GET /repos/id: Show a specific item""" |
|
71 | """GET /repos/id: Show a specific item""" |
@@ -24,5 +24,18 b'' | |||||
24 | </ul> |
|
24 | </ul> | |
25 | <div> |
|
25 | <div> | |
26 | <h2>${_('Mercurial repos')}</h2> |
|
26 | <h2>${_('Mercurial repos')}</h2> | |
|
27 | <table> | |||
|
28 | %for cnt,repo in enumerate(c.repos_list): | |||
|
29 | <tr class="parity${cnt%2}"> | |||
|
30 | <td><a href="/${repo['name']}">${repo['name']}</a></td> | |||
|
31 | <td>r${repo['rev']}:${repo['tip']}</td> | |||
|
32 | <td> | |||
|
33 | ${h.form(url('repo', id=repo['name']),method='delete')} | |||
|
34 | ${h.submit('remove','remove',class_="submit",onclick="return confirm('Confirm to delete this repository');")} | |||
|
35 | ${h.end_form()} | |||
|
36 | </td> | |||
|
37 | </tr> | |||
|
38 | %endfor | |||
|
39 | </table> | |||
27 | </div> |
|
40 | </div> | |
28 | </%def> No newline at end of file |
|
41 | </%def> |
1 | NO CONTENT: file was removed |
|
NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now