Mercurial > public > src > rhodecode
comparison pylons_app/controllers/admin.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 | |
children | d924b931b488 |
comparison
equal
deleted
inserted
replaced
42:b2bc08f2974b | 43:2e1247e62c5b |
---|---|
1 import logging | |
2 | |
3 from pylons import request, response, session, tmpl_context as c, url, app_globals as g | |
4 from pylons.controllers.util import abort, redirect | |
5 | |
6 from pylons_app.lib.base import BaseController, render | |
7 import os | |
8 from mercurial import ui, hg | |
9 from mercurial.error import RepoError | |
10 from ConfigParser import ConfigParser | |
11 log = logging.getLogger(__name__) | |
12 | |
13 class AdminController(BaseController): | |
14 | |
15 | |
16 def __before__(self): | |
17 c.staticurl = g.statics | |
18 | |
19 def index(self): | |
20 # Return a rendered template | |
21 return render('/admin.html') | |
22 | |
23 | |
24 def manage_hgrc(self): | |
25 pass | |
26 | |
27 def hgrc(self, dirname): | |
28 filename = os.path.join(dirname, '.hg', 'hgrc') | |
29 return filename | |
30 | |
31 def add_repo(self, new_repo): | |
32 | |
33 | |
34 #extra check it can be add since it's the command | |
35 if new_repo == 'add': | |
36 c.msg = 'you basstard ! this repo is a command' | |
37 c.new_repo = '' | |
38 return render('add.html') | |
39 | |
40 new_repo = new_repo.replace(" ", "_") | |
41 new_repo = new_repo.replace("-", "_") | |
42 | |
43 try: | |
44 self._create_repo(new_repo) | |
45 c.new_repo = new_repo | |
46 c.msg = 'added repo' | |
47 except Exception as e: | |
48 c.new_repo = 'Exception when adding: %s' % new_repo | |
49 c.msg = str(e) | |
50 | |
51 return render('add.html') | |
52 | |
53 def _check_repo(self, repo_name): | |
54 p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) | |
55 config_path = os.path.join(p, 'hgwebdir.config') | |
56 | |
57 cp = ConfigParser() | |
58 | |
59 cp.read(config_path) | |
60 repos_path = cp.get('paths', '/').replace("**", '') | |
61 | |
62 if not repos_path: | |
63 raise Exception('Could not read config !') | |
64 | |
65 self.repo_path = os.path.join(repos_path, repo_name) | |
66 | |
67 try: | |
68 r = hg.repository(ui.ui(), self.repo_path) | |
69 hg.verify(r) | |
70 #here we hnow that repo exists it was verified | |
71 log.info('%s repo is already created', repo_name) | |
72 raise Exception('Repo exists') | |
73 except RepoError: | |
74 log.info('%s repo is free for creation', repo_name) | |
75 #it means that there is no valid repo there... | |
76 return True | |
77 | |
78 | |
79 def _create_repo(self, repo_name): | |
80 if repo_name in [None, '', 'add']: | |
81 raise Exception('undefined repo_name of repo') | |
82 | |
83 if self._check_repo(repo_name): | |
84 log.info('creating repo %s in %s', repo_name, self.repo_path) | |
85 cmd = """mkdir %s && hg init %s""" \ | |
86 % (self.repo_path, self.repo_path) | |
87 os.popen(cmd) |