Show More
@@ -5,9 +5,6 b' from pylons.controllers.util import abor' | |||
|
5 | 5 | |
|
6 | 6 | from pylons_app.lib.base import BaseController, render |
|
7 | 7 | import os |
|
8 | from mercurial import ui, hg | |
|
9 | from mercurial.error import RepoError | |
|
10 | from ConfigParser import ConfigParser | |
|
11 | 8 | from pylons_app.lib import auth |
|
12 | 9 | from pylons_app.model.forms import LoginForm |
|
13 | 10 | import formencode |
@@ -15,6 +12,7 b' import formencode.htmlfill as htmlfill' | |||
|
15 | 12 | from pylons_app.model import meta |
|
16 | 13 | from pylons_app.model.db import Users, UserLogs |
|
17 | 14 | from webhelpers.paginate import Page |
|
15 | from pylons_app.lib.utils import check_repo | |
|
18 | 16 | log = logging.getLogger(__name__) |
|
19 | 17 | |
|
20 | 18 | class AdminController(BaseController): |
@@ -90,37 +88,12 b' class AdminController(BaseController):' | |||
|
90 | 88 | |
|
91 | 89 | return render('add.html') |
|
92 | 90 | |
|
93 | def _check_repo(self, repo_name): | |
|
94 | p = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) | |
|
95 | config_path = os.path.join(p, 'hgwebdir.config') | |
|
96 | ||
|
97 | cp = ConfigParser() | |
|
98 | ||
|
99 | cp.read(config_path) | |
|
100 | repos_path = cp.get('paths', '/').replace("**", '') | |
|
101 | ||
|
102 | if not repos_path: | |
|
103 | raise Exception('Could not read config !') | |
|
104 | ||
|
105 | self.repo_path = os.path.join(repos_path, repo_name) | |
|
106 | ||
|
107 | try: | |
|
108 | r = hg.repository(ui.ui(), self.repo_path) | |
|
109 | hg.verify(r) | |
|
110 | #here we hnow that repo exists it was verified | |
|
111 | log.info('%s repo is already created', repo_name) | |
|
112 | raise Exception('Repo exists') | |
|
113 | except RepoError: | |
|
114 | log.info('%s repo is free for creation', repo_name) | |
|
115 | #it means that there is no valid repo there... | |
|
116 | return True | |
|
117 | ||
|
118 | 91 | |
|
119 | 92 | def _create_repo(self, repo_name): |
|
120 | 93 | if repo_name in [None, '', 'add']: |
|
121 | 94 | raise Exception('undefined repo_name of repo') |
|
122 | 95 | |
|
123 |
if |
|
|
96 | if check_repo(repo_name, g.base_path): | |
|
124 | 97 | log.info('creating repo %s in %s', repo_name, self.repo_path) |
|
125 | 98 | cmd = """mkdir %s && hg init %s""" \ |
|
126 | 99 | % (self.repo_path, self.repo_path) |
@@ -1,13 +1,13 b'' | |||
|
1 | 1 | import logging |
|
2 | from paste.urlparser import PkgResourcesParser | |
|
2 | import cgi | |
|
3 | import os | |
|
3 | 4 | import paste.fileapp |
|
4 | 5 | from pylons import tmpl_context as c, app_globals as g, request, config |
|
5 | 6 | from pylons.controllers.util import forward |
|
6 | 7 | from pylons.i18n.translation import _ |
|
7 | 8 | from pylons_app.lib.base import BaseController, render |
|
8 |
from pylons.middleware |
|
|
9 | import cgi | |
|
10 | import os | |
|
9 | from pylons.middleware import media_path | |
|
10 | from pylons_app.lib.utils import check_repo | |
|
11 | 11 | |
|
12 | 12 | log = logging.getLogger(__name__) |
|
13 | 13 | class ErrorController(BaseController): |
@@ -25,7 +25,7 b' class ErrorController(BaseController):' | |||
|
25 | 25 | c.repos_prefix = config['repos_name'] |
|
26 | 26 | |
|
27 | 27 | c.repo_name = request.environ['pylons.original_request']\ |
|
28 |
.environ.get('PATH_INFO').split('/')[ |
|
|
28 | .environ.get('PATH_INFO').split('/')[1] | |
|
29 | 29 | |
|
30 | 30 | def document(self): |
|
31 | 31 | resp = request.environ.get('pylons.original_response') |
@@ -37,7 +37,9 b' class ErrorController(BaseController):' | |||
|
37 | 37 | 'host':e.get('HTTP_HOST'), |
|
38 | 38 | } |
|
39 | 39 | |
|
40 | ||
|
40 | 41 | if resp.status_int == 404: |
|
42 | if check_repo(c.repo_name, g.base_path): | |
|
41 | 43 | return render('/errors/error_404.html') |
|
42 | 44 | |
|
43 | 45 | c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) |
@@ -1,6 +1,9 b'' | |||
|
1 | from mercurial import ui, config | |
|
2 | 1 |
|
|
3 | 2 | import logging |
|
3 | from mercurial import ui, config, hg | |
|
4 | from mercurial.error import RepoError | |
|
5 | log = logging.getLogger(__name__) | |
|
6 | ||
|
4 | 7 | |
|
5 | 8 | def get_repo_slug(request): |
|
6 | 9 | path_info = request.environ.get('PATH_INFO') |
@@ -27,6 +30,22 b' def check_repo_dir(paths):' | |||
|
27 | 30 | if not os.path.isdir(os.path.join(*repos_path)): |
|
28 | 31 | raise Exception('Not a valid repository in %s' % paths[0][1]) |
|
29 | 32 | |
|
33 | def check_repo(repo_name, base_path): | |
|
34 | ||
|
35 | repo_path = os.path.join(base_path, repo_name) | |
|
36 | ||
|
37 | try: | |
|
38 | r = hg.repository(ui.ui(), repo_path) | |
|
39 | hg.verify(r) | |
|
40 | #here we hnow that repo exists it was verified | |
|
41 | log.info('%s repo is already created', repo_name) | |
|
42 | return False | |
|
43 | #raise Exception('Repo exists') | |
|
44 | except RepoError: | |
|
45 | log.info('%s repo is free for creation', repo_name) | |
|
46 | #it means that there is no valid repo there... | |
|
47 | return True | |
|
48 | ||
|
30 | 49 | def make_ui(path='hgwebdir.config', checkpaths=True): |
|
31 | 50 | """ |
|
32 | 51 | A funcion that will read python rc files and make an ui from read options |
@@ -34,7 +53,7 b" def make_ui(path='hgwebdir.config', chec" | |||
|
34 | 53 | @param path: path to mercurial config file |
|
35 | 54 | """ |
|
36 | 55 | if not os.path.isfile(path): |
|
37 |
log |
|
|
56 | log.error('Unable to read config file %s' % path) | |
|
38 | 57 | return False |
|
39 | 58 | #propagated from mercurial documentation |
|
40 | 59 | sections = [ |
General Comments 0
You need to be logged in to leave comments.
Login now