Mercurial > public > src > rhodecode
annotate pylons_app/controllers/hg.py @ 22:3142616771cd
Removed default contact name
changed depracated import of helpers,
added manage repo funciton draft.
Template updates
removed colored logger
author | Marcin Kuzminski |
---|---|
date | Sun, 28 Feb 2010 14:19:21 +0100 |
parents | fac1f62a1d71 |
children | 2963f2894a7a |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 import logging | |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
4 from pylons_app.lib.base import BaseController, render |
22 | 5 from pylons import c, g, session, request |
6 from pylons_app.lib import helpers as h | |
0 | 7 from mako.template import Template |
8 from pprint import pprint | |
5 | 9 import os |
10 from mercurial import ui, hg | |
11 from mercurial.error import RepoError | |
6 | 12 from ConfigParser import ConfigParser |
0 | 13 |
10
525ed90e4577
major app speedup moved the wsgi creation to app globals, in order to make it run only once.
Marcin Kuzminski
parents:
8
diff
changeset
|
14 log = logging.getLogger(__name__) |
0 | 15 |
16 class HgController(BaseController): | |
21 | 17 |
18 def __before__(self): | |
19 c.repos_prefix = 'etelko' | |
20 | |
8 | 21 |
22 def view(self, *args, **kwargs): | |
21 | 23 response = g.hgapp(request.environ, self.start_response) |
24 #for mercurial protocols we can't wrap into mako | |
25 if request.environ['HTTP_ACCEPT'].find("mercurial") >= 0: | |
26 return response | |
27 | |
28 #wrap the murcurial response in a mako template. | |
29 template = Template("".join(response), | |
30 lookup = request.environ['pylons.pylons']\ | |
31 .config['pylons.g'].mako_lookup) | |
32 | |
33 return template.render(g = g, c = c, session = session, h = h) | |
8 | 34 |
22 | 35 |
36 def manage_hgrc(self): | |
37 pass | |
38 | |
8 | 39 def add_repo(self, new_repo): |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
40 c.staticurl = g.statics |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
41 |
8 | 42 #extra check it can be add since it's the command |
43 if new_repo == 'add': | |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
44 c.msg = 'you basstard ! this repo is a command' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
45 c.new_repo = '' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
46 return render('add.html') |
8 | 47 |
48 new_repo = new_repo.replace(" ", "_") | |
49 new_repo = new_repo.replace("-", "_") | |
50 | |
51 try: | |
52 self._create_repo(new_repo) | |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
53 c.new_repo = new_repo |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
54 c.msg = 'added repo' |
8 | 55 except Exception as e: |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
56 c.new_repo = 'Exception when adding: %s' % new_repo |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
57 c.msg = str(e) |
8 | 58 |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
59 return render('add.html') |
0 | 60 |
5 | 61 def _check_repo(self, repo_name): |
12 | 62 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
63 config_path = os.path.join(p, 'hgwebdir.config') | |
6 | 64 |
65 cp = ConfigParser() | |
66 | |
67 cp.read(config_path) | |
68 repos_path = cp.get('paths', '/').replace("**", '') | |
69 | |
70 if not repos_path: | |
71 raise Exception('Could not read config !') | |
72 | |
5 | 73 self.repo_path = os.path.join(repos_path, repo_name) |
0 | 74 |
5 | 75 try: |
76 r = hg.repository(ui.ui(), self.repo_path) | |
77 hg.verify(r) | |
78 #here we hnow that repo exists it was verified | |
79 log.info('%s repo is already created', repo_name) | |
80 raise Exception('Repo exists') | |
81 except RepoError: | |
82 log.info('%s repo is free for creation', repo_name) | |
83 #it means that there is no valid repo there... | |
84 return True | |
85 | |
86 | |
87 def _create_repo(self, repo_name): | |
88 if repo_name in [None, '', 'add']: | |
89 raise Exception('undefined repo_name of repo') | |
90 | |
91 if self._check_repo(repo_name): | |
6 | 92 log.info('creating repo %s in %s', repo_name, self.repo_path) |
5 | 93 cmd = """mkdir %s && hg init %s""" \ |
94 % (self.repo_path, self.repo_path) | |
95 os.popen(cmd) | |
96 | |
8 | 97 #def _make_app(): |
98 # #for single a repo | |
99 # #return hgweb("/path/to/repo", "Name") | |
100 # repos = "hgwebdir.config" | |
101 # return hgwebdir(repos) | |
102 # | |
5 | 103 |
8 | 104 # def view(self, environ, start_response): |
105 # #the following is only needed when using hgwebdir | |
106 # app = _make_app() | |
107 # #return wsgi_app(environ, start_response) | |
108 # response = app(request.environ, self.start_response) | |
109 # | |
110 # if environ['PATH_INFO'].find("static") != -1: | |
111 # return response | |
112 # else: | |
113 # #wrap the murcurial response in a mako template. | |
114 # template = Template("".join(response), | |
115 # lookup = environ['pylons.pylons']\ | |
116 # .config['pylons.g'].mako_lookup) | |
117 # | |
118 # return template.render(g = g, c = c, session = session, h = h) |