##// END OF EJS Templates
Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
marcink -
r125:2811259d default
parent child Browse files
Show More
@@ -5,9 +5,6 b' from pylons.controllers.util import abor'
5
5
6 from pylons_app.lib.base import BaseController, render
6 from pylons_app.lib.base import BaseController, render
7 import os
7 import os
8 from mercurial import ui, hg
9 from mercurial.error import RepoError
10 from ConfigParser import ConfigParser
11 from pylons_app.lib import auth
8 from pylons_app.lib import auth
12 from pylons_app.model.forms import LoginForm
9 from pylons_app.model.forms import LoginForm
13 import formencode
10 import formencode
@@ -15,6 +12,7 b' import formencode.htmlfill as htmlfill'
15 from pylons_app.model import meta
12 from pylons_app.model import meta
16 from pylons_app.model.db import Users, UserLogs
13 from pylons_app.model.db import Users, UserLogs
17 from webhelpers.paginate import Page
14 from webhelpers.paginate import Page
15 from pylons_app.lib.utils import check_repo
18 log = logging.getLogger(__name__)
16 log = logging.getLogger(__name__)
19
17
20 class AdminController(BaseController):
18 class AdminController(BaseController):
@@ -90,37 +88,12 b' class AdminController(BaseController):'
90
88
91 return render('add.html')
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 def _create_repo(self, repo_name):
92 def _create_repo(self, repo_name):
120 if repo_name in [None, '', 'add']:
93 if repo_name in [None, '', 'add']:
121 raise Exception('undefined repo_name of repo')
94 raise Exception('undefined repo_name of repo')
122
95
123 if self._check_repo(repo_name):
96 if check_repo(repo_name, g.base_path):
124 log.info('creating repo %s in %s', repo_name, self.repo_path)
97 log.info('creating repo %s in %s', repo_name, self.repo_path)
125 cmd = """mkdir %s && hg init %s""" \
98 cmd = """mkdir %s && hg init %s""" \
126 % (self.repo_path, self.repo_path)
99 % (self.repo_path, self.repo_path)
@@ -1,13 +1,13 b''
1 import logging
1 import logging
2 from paste.urlparser import PkgResourcesParser
2 import cgi
3 import os
3 import paste.fileapp
4 import paste.fileapp
4 from pylons import tmpl_context as c, app_globals as g, request, config
5 from pylons import tmpl_context as c, app_globals as g, request, config
5 from pylons.controllers.util import forward
6 from pylons.controllers.util import forward
6 from pylons.i18n.translation import _
7 from pylons.i18n.translation import _
7 from pylons_app.lib.base import BaseController, render
8 from pylons_app.lib.base import BaseController, render
8 from pylons.middleware import error_document_template, media_path
9 from pylons.middleware import media_path
9 import cgi
10 from pylons_app.lib.utils import check_repo
10 import os
11
11
12 log = logging.getLogger(__name__)
12 log = logging.getLogger(__name__)
13 class ErrorController(BaseController):
13 class ErrorController(BaseController):
@@ -25,7 +25,7 b' class ErrorController(BaseController):'
25 c.repos_prefix = config['repos_name']
25 c.repos_prefix = config['repos_name']
26
26
27 c.repo_name = request.environ['pylons.original_request']\
27 c.repo_name = request.environ['pylons.original_request']\
28 .environ.get('PATH_INFO').split('/')[-1]
28 .environ.get('PATH_INFO').split('/')[1]
29
29
30 def document(self):
30 def document(self):
31 resp = request.environ.get('pylons.original_response')
31 resp = request.environ.get('pylons.original_response')
@@ -36,9 +36,11 b' class ErrorController(BaseController):'
36 'protocol': e.get('wsgi.url_scheme'),
36 'protocol': e.get('wsgi.url_scheme'),
37 'host':e.get('HTTP_HOST'),
37 'host':e.get('HTTP_HOST'),
38 }
38 }
39
39
40
40 if resp.status_int == 404:
41 if resp.status_int == 404:
41 return render('/errors/error_404.html')
42 if check_repo(c.repo_name, g.base_path):
43 return render('/errors/error_404.html')
42
44
43 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
45 c.error_message = cgi.escape(request.GET.get('code', str(resp.status)))
44 c.error_explanation = self.get_error_explanation(resp.status_int)
46 c.error_explanation = self.get_error_explanation(resp.status_int)
@@ -1,7 +1,10 b''
1 from mercurial import ui, config
2 import os
1 import os
3 import logging
2 import logging
4
3 from mercurial import ui, config, hg
4 from mercurial.error import RepoError
5 log = logging.getLogger(__name__)
6
7
5 def get_repo_slug(request):
8 def get_repo_slug(request):
6 path_info = request.environ.get('PATH_INFO')
9 path_info = request.environ.get('PATH_INFO')
7 uri_lst = path_info.split('/')
10 uri_lst = path_info.split('/')
@@ -26,7 +29,23 b' def check_repo_dir(paths):'
26 repos_path[0] = '/'
29 repos_path[0] = '/'
27 if not os.path.isdir(os.path.join(*repos_path)):
30 if not os.path.isdir(os.path.join(*repos_path)):
28 raise Exception('Not a valid repository in %s' % paths[0][1])
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 def make_ui(path='hgwebdir.config', checkpaths=True):
49 def make_ui(path='hgwebdir.config', checkpaths=True):
31 """
50 """
32 A funcion that will read python rc files and make an ui from read options
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 @param path: path to mercurial config file
53 @param path: path to mercurial config file
35 """
54 """
36 if not os.path.isfile(path):
55 if not os.path.isfile(path):
37 logging.error('Unable to read config file %s' % path)
56 log.error('Unable to read config file %s' % path)
38 return False
57 return False
39 #propagated from mercurial documentation
58 #propagated from mercurial documentation
40 sections = [
59 sections = [
General Comments 0
You need to be logged in to leave comments. Login now