Mercurial > public > src > rhodecode
comparison pylons_app/controllers/hg.py @ 43:2e1247e62c5b
changed for pylons 0.1 / 1.0
added admin controller
author | marcink |
---|---|
date | Wed, 07 Apr 2010 15:28:50 +0200 |
parents | 71ffa932799d |
children | e00dccb6f211 |
comparison
equal
deleted
inserted
replaced
42:b2bc08f2974b | 43:2e1247e62c5b |
---|---|
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 import logging | 3 import logging |
4 import os | 4 from pylons_app.lib.base import BaseController |
5 from pylons_app.lib.base import BaseController, render | |
6 from pylons import tmpl_context as c, app_globals as g, session, request, config | 5 from pylons import tmpl_context as c, app_globals as g, session, request, config |
7 from pylons_app.lib import helpers as h | 6 from pylons_app.lib import helpers as h |
8 from mako.template import Template | 7 from mako.template import Template |
9 from mercurial import ui, hg | |
10 from mercurial.error import RepoError | |
11 from ConfigParser import ConfigParser | |
12 from pylons.controllers.util import abort | 8 from pylons.controllers.util import abort |
13 | 9 |
14 log = logging.getLogger(__name__) | 10 log = logging.getLogger(__name__) |
15 | 11 |
16 class HgController(BaseController): | 12 class HgController(BaseController): |
41 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ | 37 template = Template(tmpl, lookup=request.environ['pylons.pylons']\ |
42 .config['pylons.app_globals'].mako_lookup, disable_unicode=True) | 38 .config['pylons.app_globals'].mako_lookup, disable_unicode=True) |
43 | 39 |
44 | 40 |
45 return template.render(g=g, c=c, session=session, h=h) | 41 return template.render(g=g, c=c, session=session, h=h) |
46 | |
47 | |
48 def manage_hgrc(self): | |
49 pass | |
50 | |
51 def hgrc(self, dirname): | |
52 filename = os.path.join(dirname, '.hg', 'hgrc') | |
53 return filename | |
54 | |
55 def add_repo(self, new_repo): | |
56 c.staticurl = g.statics | |
57 | |
58 #extra check it can be add since it's the command | |
59 if new_repo == 'add': | |
60 c.msg = 'you basstard ! this repo is a command' | |
61 c.new_repo = '' | |
62 return render('add.html') | |
63 | |
64 new_repo = new_repo.replace(" ", "_") | |
65 new_repo = new_repo.replace("-", "_") | |
66 | |
67 try: | |
68 self._create_repo(new_repo) | |
69 c.new_repo = new_repo | |
70 c.msg = 'added repo' | |
71 except Exception as e: | |
72 c.new_repo = 'Exception when adding: %s' % new_repo | |
73 c.msg = str(e) | |
74 | |
75 return render('add.html') | |
76 | |
77 def _check_repo(self, repo_name): | |
78 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) | |
79 config_path = os.path.join(p, 'hgwebdir.config') | |
80 | |
81 cp = ConfigParser() | |
82 | |
83 cp.read(config_path) | |
84 repos_path = cp.get('paths', '/').replace("**", '') | |
85 | |
86 if not repos_path: | |
87 raise Exception('Could not read config !') | |
88 | |
89 self.repo_path = os.path.join(repos_path, repo_name) | |
90 | |
91 try: | |
92 r = hg.repository(ui.ui(), self.repo_path) | |
93 hg.verify(r) | |
94 #here we hnow that repo exists it was verified | |
95 log.info('%s repo is already created', repo_name) | |
96 raise Exception('Repo exists') | |
97 except RepoError: | |
98 log.info('%s repo is free for creation', repo_name) | |
99 #it means that there is no valid repo there... | |
100 return True | |
101 | |
102 | |
103 def _create_repo(self, repo_name): | |
104 if repo_name in [None, '', 'add']: | |
105 raise Exception('undefined repo_name of repo') | |
106 | |
107 if self._check_repo(repo_name): | |
108 log.info('creating repo %s in %s', repo_name, self.repo_path) | |
109 cmd = """mkdir %s && hg init %s""" \ | |
110 % (self.repo_path, self.repo_path) | |
111 os.popen(cmd) | |
112 | |
113 #def _make_app(): | |
114 # #for single a repo | |
115 # #return hgweb("/path/to/repo", "Name") | |
116 # repos = "hgwebdir.config" | |
117 # return hgwebdir(repos) | |
118 # | |
119 | |
120 # def view(self, environ, start_response): | |
121 # #the following is only needed when using hgwebdir | |
122 # app = _make_app() | |
123 # #return wsgi_app(environ, start_response) | |
124 # response = app(request.environ, self.start_response) | |
125 # | |
126 # if environ['PATH_INFO'].find("static") != -1: | |
127 # return response | |
128 # else: | |
129 # #wrap the murcurial response in a mako template. | |
130 # template = Template("".join(response), | |
131 # lookup = environ['pylons.pylons']\ | |
132 # .config['pylons.g'].mako_lookup) | |
133 # | |
134 # return template.render(g = g, c = c, session = session, h = h) |