Mercurial > public > src > rhodecode
annotate pylons_app/controllers/hg.py @ 12:5f30a6d558dc
Added pylons manage script
fix the configs for zip archives
some other minot changes.
author | Marcin Kuzminski |
---|---|
date | Sat, 20 Feb 2010 17:51:51 +0100 |
parents | 525ed90e4577 |
children | bbaab7501c1a |
rev | line source |
---|---|
0 | 1 #!/usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 import logging | |
4 from pylons_app.lib.base import BaseController | |
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): | |
12 | 23 tmpl = u''' |
8 | 24 <html> |
25 <body> | |
26 %(msg)s%(new_repo)s!<br \> | |
27 <a href="/">repos</a> | |
28 </body> | |
29 </html> | |
30 ''' | |
31 #extra check it can be add since it's the command | |
32 if new_repo == 'add': | |
33 return [tmpl % ({'new_repo':'', 'msg':'you basstard ! this repo is a command'})] | |
34 | |
35 new_repo = new_repo.replace(" ", "_") | |
36 new_repo = new_repo.replace("-", "_") | |
37 | |
38 try: | |
39 self._create_repo(new_repo) | |
40 except Exception as e: | |
41 return [tmpl % ({'new_repo':' Exception when adding: ' + new_repo, 'msg':str(e)})] | |
42 | |
43 return [tmpl % ({'new_repo':new_repo, 'msg':'added repo: '})] | |
0 | 44 |
5 | 45 def _check_repo(self, repo_name): |
12 | 46 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) |
47 config_path = os.path.join(p, 'hgwebdir.config') | |
6 | 48 |
49 cp = ConfigParser() | |
50 | |
51 cp.read(config_path) | |
52 repos_path = cp.get('paths', '/').replace("**", '') | |
53 | |
54 if not repos_path: | |
55 raise Exception('Could not read config !') | |
56 | |
5 | 57 self.repo_path = os.path.join(repos_path, repo_name) |
0 | 58 |
5 | 59 try: |
60 r = hg.repository(ui.ui(), self.repo_path) | |
61 hg.verify(r) | |
62 #here we hnow that repo exists it was verified | |
63 log.info('%s repo is already created', repo_name) | |
64 raise Exception('Repo exists') | |
65 except RepoError: | |
66 log.info('%s repo is free for creation', repo_name) | |
67 #it means that there is no valid repo there... | |
68 return True | |
69 | |
70 | |
71 def _create_repo(self, repo_name): | |
72 if repo_name in [None, '', 'add']: | |
73 raise Exception('undefined repo_name of repo') | |
74 | |
75 if self._check_repo(repo_name): | |
6 | 76 log.info('creating repo %s in %s', repo_name, self.repo_path) |
5 | 77 cmd = """mkdir %s && hg init %s""" \ |
78 % (self.repo_path, self.repo_path) | |
79 os.popen(cmd) | |
80 | |
8 | 81 #def _make_app(): |
82 # #for single a repo | |
83 # #return hgweb("/path/to/repo", "Name") | |
84 # repos = "hgwebdir.config" | |
85 # return hgwebdir(repos) | |
86 # | |
5 | 87 |
8 | 88 # def view(self, environ, start_response): |
89 # #the following is only needed when using hgwebdir | |
90 # app = _make_app() | |
91 # #return wsgi_app(environ, start_response) | |
92 # response = app(request.environ, self.start_response) | |
93 # | |
94 # if environ['PATH_INFO'].find("static") != -1: | |
95 # return response | |
96 # else: | |
97 # #wrap the murcurial response in a mako template. | |
98 # template = Template("".join(response), | |
99 # lookup = environ['pylons.pylons']\ | |
100 # .config['pylons.g'].mako_lookup) | |
101 # | |
102 # return template.render(g = g, c = c, session = session, h = h) |