Show More
@@ -1,84 +1,91 b'' | |||||
1 | import logging |
|
1 | import logging | |
2 | import cgi |
|
2 | import cgi | |
3 | import os |
|
3 | import os | |
4 | import paste.fileapp |
|
4 | import paste.fileapp | |
5 | 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 | |
6 | from pylons.controllers.util import forward |
|
6 | from pylons.controllers.util import forward | |
7 | from pylons.i18n.translation import _ |
|
7 | from pylons.i18n.translation import _ | |
8 | from pylons_app.lib.base import BaseController, render |
|
8 | from pylons_app.lib.base import BaseController, render | |
9 | from pylons.middleware import media_path |
|
9 | from pylons.middleware import media_path | |
10 | from pylons_app.lib.utils import check_repo |
|
10 | from pylons_app.lib.utils import check_repo | |
|
11 | from pylons_app.lib.filters import clean_repo | |||
|
12 | log = logging.getLogger(__name__) | |||
11 |
|
13 | |||
12 | log = logging.getLogger(__name__) |
|
|||
13 | class ErrorController(BaseController): |
|
14 | class ErrorController(BaseController): | |
14 | """ |
|
15 | """ | |
15 | Generates error documents as and when they are required. |
|
16 | Generates error documents as and when they are required. | |
16 |
|
17 | |||
17 | The ErrorDocuments middleware forwards to ErrorController when error |
|
18 | The ErrorDocuments middleware forwards to ErrorController when error | |
18 | related status codes are returned from the application. |
|
19 | related status codes are returned from the application. | |
19 |
|
20 | |||
20 | This behaviour can be altered by changing the parameters to the |
|
21 | This behaviour can be altered by changing the parameters to the | |
21 | ErrorDocuments middleware in your config/middleware.py file. |
|
22 | ErrorDocuments middleware in your config/middleware.py file. | |
22 | """ |
|
23 | """ | |
|
24 | # def __before__(self): | |||
|
25 | # super(ErrorController, self).__before__() | |||
23 |
|
26 | |||
24 | def document(self): |
|
27 | def document(self): | |
25 | resp = request.environ.get('pylons.original_response') |
|
28 | resp = request.environ.get('pylons.original_response') | |
|
29 | ||||
26 | log.debug(resp.status) |
|
30 | log.debug(resp.status) | |
27 |
|
31 | |||
28 | e = request.environ |
|
32 | e = request.environ | |
29 | c.serv_p = r'%(protocol)s://%(host)s/' % { |
|
33 | c.serv_p = r'%(protocol)s://%(host)s/' % { | |
30 | 'protocol': e.get('wsgi.url_scheme'), |
|
34 | 'protocol': e.get('wsgi.url_scheme'), | |
31 | 'host':e.get('HTTP_HOST'), |
|
35 | 'host':e.get('HTTP_HOST'), | |
32 | } |
|
36 | } | |
33 |
|
37 | |||
34 |
|
38 | |||
35 | if resp.status_int == 404: |
|
39 | if resp.status_int == 404: | |
36 | if check_repo(c.repo_name, g.base_path): |
|
40 | org_e = request.environ.get('pylons.original_request').environ | |
|
41 | c.repo_name = repo_name = org_e['PATH_INFO'].split('/')[1] | |||
|
42 | c.repo_name_cleaned = clean_repo(c.repo_name) | |||
|
43 | if check_repo(repo_name, g.base_path): | |||
37 | return render('/errors/error_404.html') |
|
44 | return render('/errors/error_404.html') | |
38 |
|
45 | |||
39 | c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) |
|
46 | c.error_message = cgi.escape(request.GET.get('code', str(resp.status))) | |
40 | c.error_explanation = self.get_error_explanation(resp.status_int) |
|
47 | c.error_explanation = self.get_error_explanation(resp.status_int) | |
41 |
|
48 | |||
42 | #redirect to when error with given seconds |
|
49 | #redirect to when error with given seconds | |
43 | c.redirect_time = 0 |
|
50 | c.redirect_time = 0 | |
44 | c.redirect_module = _('Home page')# name to what your going to be redirected |
|
51 | c.redirect_module = _('Home page')# name to what your going to be redirected | |
45 | c.url_redirect = "/" |
|
52 | c.url_redirect = "/" | |
46 |
|
53 | |||
47 | return render('/errors/error_document.html') |
|
54 | return render('/errors/error_document.html') | |
48 |
|
55 | |||
49 |
|
56 | |||
50 | def img(self, id): |
|
57 | def img(self, id): | |
51 | """Serve Pylons' stock images""" |
|
58 | """Serve Pylons' stock images""" | |
52 | return self._serve_file(os.path.join(media_path, 'img', id)) |
|
59 | return self._serve_file(os.path.join(media_path, 'img', id)) | |
53 |
|
60 | |||
54 | def style(self, id): |
|
61 | def style(self, id): | |
55 | """Serve Pylons' stock stylesheets""" |
|
62 | """Serve Pylons' stock stylesheets""" | |
56 | return self._serve_file(os.path.join(media_path, 'style', id)) |
|
63 | return self._serve_file(os.path.join(media_path, 'style', id)) | |
57 |
|
64 | |||
58 | def _serve_file(self, path): |
|
65 | def _serve_file(self, path): | |
59 | """Call Paste's FileApp (a WSGI application) to serve the file |
|
66 | """Call Paste's FileApp (a WSGI application) to serve the file | |
60 | at the specified path |
|
67 | at the specified path | |
61 | """ |
|
68 | """ | |
62 | fapp = paste.fileapp.FileApp(path) |
|
69 | fapp = paste.fileapp.FileApp(path) | |
63 | return fapp(request.environ, self.start_response) |
|
70 | return fapp(request.environ, self.start_response) | |
64 |
|
71 | |||
65 | def get_error_explanation(self, code): |
|
72 | def get_error_explanation(self, code): | |
66 | ''' get the error explanations of int codes |
|
73 | ''' get the error explanations of int codes | |
67 | [400, 401, 403, 404, 500]''' |
|
74 | [400, 401, 403, 404, 500]''' | |
68 | try: |
|
75 | try: | |
69 | code = int(code) |
|
76 | code = int(code) | |
70 | except: |
|
77 | except: | |
71 | code = 500 |
|
78 | code = 500 | |
72 |
|
79 | |||
73 | if code == 400: |
|
80 | if code == 400: | |
74 | return _('The request could not be understood by the server due to malformed syntax.') |
|
81 | return _('The request could not be understood by the server due to malformed syntax.') | |
75 | if code == 401: |
|
82 | if code == 401: | |
76 | return _('Unathorized access to resource') |
|
83 | return _('Unathorized access to resource') | |
77 | if code == 403: |
|
84 | if code == 403: | |
78 | return _("You don't have permission to view this page") |
|
85 | return _("You don't have permission to view this page") | |
79 | if code == 404: |
|
86 | if code == 404: | |
80 | return _('The resource could not be found') |
|
87 | return _('The resource could not be found') | |
81 | if code == 500: |
|
88 | if code == 500: | |
82 | return _('The server encountered an unexpected condition which prevented it from fulfilling the request.') |
|
89 | return _('The server encountered an unexpected condition which prevented it from fulfilling the request.') | |
83 |
|
90 | |||
84 |
|
91 |
@@ -1,75 +1,94 b'' | |||||
|
1 | from pylons import request, response, session, tmpl_context as c, url, \ | |||
|
2 | app_globals as g | |||
|
3 | from pylons.controllers.util import abort, redirect | |||
|
4 | from pylons_app.lib.base import BaseController, render | |||
|
5 | from pylons_app.lib.utils import check_repo, invalidate_cache | |||
1 | import logging |
|
6 | import logging | |
2 | import os |
|
7 | import os | |
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 | from pylons_app.lib import auth |
|
|||
6 | from pylons_app.lib.base import BaseController, render |
|
|||
7 | from pylons_app.model.db import Users, UserLogs |
|
|||
8 | from pylons_app.model.hg_model import HgModel |
|
|||
9 | from operator import itemgetter |
|
|||
10 | import shutil |
|
8 | import shutil | |
11 |
from pylons_app.lib. |
|
9 | from pylons_app.lib.filters import clean_repo | |
12 | log = logging.getLogger(__name__) |
|
10 | log = logging.getLogger(__name__) | |
13 |
|
11 | |||
14 | class ReposController(BaseController): |
|
12 | class ReposController(BaseController): | |
15 | """REST Controller styled on the Atom Publishing Protocol""" |
|
13 | """REST Controller styled on the Atom Publishing Protocol""" | |
16 | # To properly map this controller, ensure your config/routing.py |
|
14 | # To properly map this controller, ensure your config/routing.py | |
17 | # file has a resource setup: |
|
15 | # file has a resource setup: | |
18 | # map.resource('repo', 'repos') |
|
16 | # map.resource('repo', 'repos') | |
19 |
|
17 | |||
20 | def __before__(self): |
|
18 | def __before__(self): | |
21 | c.admin_user = session.get('admin_user') |
|
19 | c.admin_user = session.get('admin_user') | |
22 | c.admin_username = session.get('admin_username') |
|
20 | c.admin_username = session.get('admin_username') | |
23 | super(ReposController, self).__before__() |
|
21 | super(ReposController, self).__before__() | |
24 |
|
22 | |||
25 | def index(self, format='html'): |
|
23 | def index(self, format='html'): | |
26 | """GET /repos: All items in the collection""" |
|
24 | """GET /repos: All items in the collection""" | |
27 | # url('repos') |
|
25 | # url('repos') | |
28 | c.repos_list = c.cached_repo_list |
|
26 | c.repos_list = c.cached_repo_list | |
29 | return render('admin/repos/repos.html') |
|
27 | return render('admin/repos/repos.html') | |
30 |
|
28 | |||
31 | def create(self): |
|
29 | def create(self): | |
32 | """POST /repos: Create a new item""" |
|
30 | """POST /repos: Create a new item""" | |
33 | # url('repos') |
|
31 | # url('repos') | |
|
32 | name = request.POST.get('name') | |||
|
33 | ||||
|
34 | try: | |||
|
35 | self._create_repo(name) | |||
|
36 | #clear our cached list for refresh with new repo | |||
|
37 | invalidate_cache('cached_repo_list') | |||
|
38 | except Exception as e: | |||
|
39 | log.error(e) | |||
|
40 | ||||
|
41 | return redirect('repos') | |||
|
42 | ||||
|
43 | def _create_repo(self, repo_name): | |||
|
44 | repo_path = os.path.join(g.base_path, repo_name) | |||
|
45 | if check_repo(repo_name, g.base_path): | |||
|
46 | log.info('creating repo %s in %s', repo_name, repo_path) | |||
|
47 | from vcs.backends.hg import MercurialRepository | |||
|
48 | MercurialRepository(repo_path, create=True) | |||
|
49 | ||||
34 |
|
50 | |||
35 | def new(self, format='html'): |
|
51 | def new(self, format='html'): | |
36 | """GET /repos/new: Form to create a new item""" |
|
52 | """GET /repos/new: Form to create a new item""" | |
37 | # url('new_repo') |
|
53 | new_repo = request.GET.get('repo', '') | |
|
54 | c.new_repo = clean_repo(new_repo) | |||
|
55 | ||||
|
56 | return render('admin/repos/repo_add.html') | |||
38 |
|
57 | |||
39 | def update(self, id): |
|
58 | def update(self, id): | |
40 | """PUT /repos/id: Update an existing item""" |
|
59 | """PUT /repos/id: Update an existing item""" | |
41 | # Forms posted to this method should contain a hidden field: |
|
60 | # Forms posted to this method should contain a hidden field: | |
42 | # <input type="hidden" name="_method" value="PUT" /> |
|
61 | # <input type="hidden" name="_method" value="PUT" /> | |
43 | # Or using helpers: |
|
62 | # Or using helpers: | |
44 | # h.form(url('repo', id=ID), |
|
63 | # h.form(url('repo', id=ID), | |
45 | # method='put') |
|
64 | # method='put') | |
46 | # url('repo', id=ID) |
|
65 | # url('repo', id=ID) | |
47 |
|
66 | |||
48 | def delete(self, id): |
|
67 | def delete(self, id): | |
49 | """DELETE /repos/id: Delete an existing item""" |
|
68 | """DELETE /repos/id: Delete an existing item""" | |
50 | # Forms posted to this method should contain a hidden field: |
|
69 | # Forms posted to this method should contain a hidden field: | |
51 | # <input type="hidden" name="_method" value="DELETE" /> |
|
70 | # <input type="hidden" name="_method" value="DELETE" /> | |
52 | # Or using helpers: |
|
71 | # Or using helpers: | |
53 | # h.form(url('repo', id=ID), |
|
72 | # h.form(url('repo', id=ID), | |
54 | # method='delete') |
|
73 | # method='delete') | |
55 | # url('repo', id=ID) |
|
74 | # url('repo', id=ID) | |
56 | from datetime import datetime |
|
75 | from datetime import datetime | |
57 | path = g.paths[0][1].replace('*', '') |
|
76 | path = g.paths[0][1].replace('*', '') | |
58 | rm_path = os.path.join(path, id) |
|
77 | rm_path = os.path.join(path, id) | |
59 | log.info("Removing %s", rm_path) |
|
78 | log.info("Removing %s", rm_path) | |
60 | shutil.move(os.path.join(rm_path, '.hg'), os.path.join(rm_path, 'rm__.hg')) |
|
79 | shutil.move(os.path.join(rm_path, '.hg'), os.path.join(rm_path, 'rm__.hg')) | |
61 | shutil.move(rm_path, os.path.join(path, 'rm__%s-%s' % (datetime.today(), id))) |
|
80 | shutil.move(rm_path, os.path.join(path, 'rm__%s-%s' % (datetime.today(), id))) | |
62 |
|
81 | |||
63 | #clear our cached list for refresh with new repo |
|
82 | #clear our cached list for refresh with new repo | |
64 | invalidate_cache('cached_repo_list') |
|
83 | invalidate_cache('cached_repo_list') | |
65 |
|
84 | |||
66 | return redirect(url('repos')) |
|
85 | return redirect(url('repos')) | |
67 |
|
86 | |||
68 |
|
87 | |||
69 | def show(self, id, format='html'): |
|
88 | def show(self, id, format='html'): | |
70 | """GET /repos/id: Show a specific item""" |
|
89 | """GET /repos/id: Show a specific item""" | |
71 | # url('repo', id=ID) |
|
90 | # url('repo', id=ID) | |
72 | return render('/repos_show.html') |
|
91 | return render('/repos_show.html') | |
73 | def edit(self, id, format='html'): |
|
92 | def edit(self, id, format='html'): | |
74 | """GET /repos/id/edit: Form to edit an existing item""" |
|
93 | """GET /repos/id/edit: Form to edit an existing item""" | |
75 | # url('edit_repo', id=ID) |
|
94 | # url('edit_repo', id=ID) |
@@ -1,34 +1,35 b'' | |||||
1 | ## -*- coding: utf-8 -*- |
|
1 | ## -*- coding: utf-8 -*- | |
2 | <%! |
|
2 | <%! | |
3 | from pylons_app.lib import filters |
|
3 | from pylons_app.lib import filters | |
4 | %> |
|
4 | %> | |
5 | <%inherit file="./../base/base.html"/> |
|
5 | <%inherit file="./../base/base.html"/> | |
6 |
|
6 | |||
7 | <%def name="title()"> |
|
7 | <%def name="title()"> | |
8 | ${_('Repository not found')} |
|
8 | ${_('Repository not found')} | |
9 | </%def> |
|
9 | </%def> | |
10 |
|
10 | |||
11 | <%def name="breadcrumbs()"> |
|
11 | <%def name="breadcrumbs()"> | |
12 | ${h.link_to(u'Home',h.url('hg_home'))} |
|
12 | ${h.link_to(u'Home',h.url('hg_home'))} | |
13 | / |
|
13 | / | |
14 | ${h.link_to(u'Admin',h.url('admin_home'))} |
|
14 | ${h.link_to(u'Admin',h.url('admin_home'))} | |
15 | </%def> |
|
15 | </%def> | |
16 |
|
16 | |||
17 | <%def name="page_nav()"> |
|
17 | <%def name="page_nav()"> | |
18 | ${self.menu('admin')} |
|
18 | ${self.menu('admin')} | |
19 | </%def> |
|
19 | </%def> | |
20 | <%def name="js()"> |
|
20 | <%def name="js()"> | |
21 |
|
21 | |||
22 | </%def> |
|
22 | </%def> | |
23 | <%def name="main()"> |
|
23 | <%def name="main()"> | |
24 |
|
24 | |||
25 | <h2 class="no-link no-border">Not Found</h2> |
|
25 | <h2 class="no-link no-border">${_('Not Found')}</h2> | |
26 |
<p class="normal">The specified repository " |
|
26 | <p class="normal">${_('The specified repository "%s" is unknown, sorry.') % c.repo_name}</p> | |
27 | <p class="normal"> |
|
27 | <p class="normal"> | |
28 | <a href="/_admin/add_repo/${c.repo_name|n,filters.clean_repo}">Create "${c.repo_name}" repository as ${c.repo_name|n,filters.clean_repo}</a> |
|
28 | <a href="${h.url('new_repo',repo=c.repo_name_cleaned)}"> | |
|
29 | ${_('Create "%s" repository as %s' % (c.repo_name,c.repo_name_cleaned))}</a> | |||
29 |
|
30 | |||
30 | </p> |
|
31 | </p> | |
31 |
<p class="normal">Go back to the |
|
32 | <p class="normal">${h.link_to(_('Go back to the main repository list page'),h.url('hg_home'))}</p> | |
32 | <div class="page-footer"> |
|
33 | <div class="page-footer"> | |
33 | </div> |
|
34 | </div> | |
34 | </%def> No newline at end of file |
|
35 | </%def> |
General Comments 0
You need to be logged in to leave comments.
Login now