Mercurial > public > src > rhodecode
annotate pylons_app/controllers/hg.py @ 20:bbaab7501c1a
Added custom templates, did over check of code to make it work.
Added templating for add repository, and styling. App globals now handles our custom static files. (logo etc can be changed)
author | Marcin Kuzminski |
---|---|
date | Sun, 28 Feb 2010 01:52:38 +0100 |
parents | 5f30a6d558dc |
children | fac1f62a1d71 |
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 |
0 | 5 from pylons import c, g, session, h, request |
6 from mako.template import Template | |
7 from pprint import pprint | |
5 | 8 import os |
9 from mercurial import ui, hg | |
10 from mercurial.error import RepoError | |
6 | 11 from ConfigParser import ConfigParser |
0 | 12 |
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
|
13 log = logging.getLogger(__name__) |
0 | 14 |
15 class HgController(BaseController): | |
8 | 16 def index(self): |
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
|
17 return g.hgapp(request.environ, self.start_response) |
8 | 18 |
19 def view(self, *args, **kwargs): | |
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
|
20 return g.hgapp(request.environ, self.start_response) |
8 | 21 |
22 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
|
23 c.staticurl = g.statics |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
24 |
8 | 25 #extra check it can be add since it's the command |
26 if new_repo == 'add': | |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
27 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
|
28 c.new_repo = '' |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
29 return render('add.html') |
8 | 30 |
31 new_repo = new_repo.replace(" ", "_") | |
32 new_repo = new_repo.replace("-", "_") | |
33 | |
34 try: | |
35 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
|
36 c.new_repo = new_repo |
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
37 c.msg = 'added repo' |
8 | 38 except Exception as e: |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
39 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
|
40 c.msg = str(e) |
8 | 41 |
20
bbaab7501c1a
Added custom templates, did over check of code to make it work.
Marcin Kuzminski
parents:
12
diff
changeset
|
42 return render('add.html') |
0 | 43 |
5 | 44 def _check_repo(self, repo_name): |
12 | 45 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
46 config_path = os.path.join(p, 'hgwebdir.config') | |
6 | 47 |
48 cp = ConfigParser() | |
49 | |
50 cp.read(config_path) | |
51 repos_path = cp.get('paths', '/').replace("**", '') | |
52 | |
53 if not repos_path: | |
54 raise Exception('Could not read config !') | |
55 | |
5 | 56 self.repo_path = os.path.join(repos_path, repo_name) |
0 | 57 |
5 | 58 try: |
59 r = hg.repository(ui.ui(), self.repo_path) | |
60 hg.verify(r) | |
61 #here we hnow that repo exists it was verified | |
62 log.info('%s repo is already created', repo_name) | |
63 raise Exception('Repo exists') | |
64 except RepoError: | |
65 log.info('%s repo is free for creation', repo_name) | |
66 #it means that there is no valid repo there... | |
67 return True | |
68 | |
69 | |
70 def _create_repo(self, repo_name): | |
71 if repo_name in [None, '', 'add']: | |
72 raise Exception('undefined repo_name of repo') | |
73 | |
74 if self._check_repo(repo_name): | |
6 | 75 log.info('creating repo %s in %s', repo_name, self.repo_path) |
5 | 76 cmd = """mkdir %s && hg init %s""" \ |
77 % (self.repo_path, self.repo_path) | |
78 os.popen(cmd) | |
79 | |
8 | 80 #def _make_app(): |
81 # #for single a repo | |
82 # #return hgweb("/path/to/repo", "Name") | |
83 # repos = "hgwebdir.config" | |
84 # return hgwebdir(repos) | |
85 # | |
5 | 86 |
8 | 87 # def view(self, environ, start_response): |
88 # #the following is only needed when using hgwebdir | |
89 # app = _make_app() | |
90 # #return wsgi_app(environ, start_response) | |
91 # response = app(request.environ, self.start_response) | |
92 # | |
93 # if environ['PATH_INFO'].find("static") != -1: | |
94 # return response | |
95 # else: | |
96 # #wrap the murcurial response in a mako template. | |
97 # template = Template("".join(response), | |
98 # lookup = environ['pylons.pylons']\ | |
99 # .config['pylons.g'].mako_lookup) | |
100 # | |
101 # return template.render(g = g, c = c, session = session, h = h) |