Show More
@@ -44,11 +44,13 b' cache_dir = %(here)s/data' | |||
|
44 | 44 | #################################### |
|
45 | 45 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
46 | 46 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
47 | beaker.cache.regions=short_term,long_term | |
|
47 | beaker.cache.regions=super_short_term,short_term,long_term | |
|
48 | 48 | beaker.cache.long_term.type=memory |
|
49 | 49 | beaker.cache.long_term.expire=36000 |
|
50 | 50 | beaker.cache.short_term.type=memory |
|
51 | 51 | beaker.cache.short_term.expire=60 |
|
52 | beaker.cache.super_short_term.type=memory | |
|
53 | beaker.cache.super_short_term.expire=10 | |
|
52 | 54 | |
|
53 | 55 | ################################################################################ |
|
54 | 56 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
@@ -39,17 +39,18 b' static_files = false' | |||
|
39 | 39 | lang=en |
|
40 | 40 | cache_dir = %(here)s/data |
|
41 | 41 | |
|
42 | ||
|
43 | 42 | #################################### |
|
44 | 43 | ### BEAKER CACHE #### |
|
45 | 44 | #################################### |
|
46 | 45 | beaker.cache.data_dir=/%(here)s/data/cache/data |
|
47 | 46 | beaker.cache.lock_dir=/%(here)s/data/cache/lock |
|
48 | beaker.cache.regions=short_term,long_term | |
|
47 | beaker.cache.regions=super_short_term,short_term,long_term | |
|
49 | 48 | beaker.cache.long_term.type=memory |
|
50 | 49 | beaker.cache.long_term.expire=36000 |
|
51 | 50 | beaker.cache.short_term.type=memory |
|
52 | 51 | beaker.cache.short_term.expire=60 |
|
52 | beaker.cache.super_short_term.type=memory | |
|
53 | beaker.cache.super_short_term.expire=10 | |
|
53 | 54 | |
|
54 | 55 | ################################################################################ |
|
55 | 56 | ## WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* ## |
@@ -22,18 +22,18 b' Created on April 4, 2010' | |||
|
22 | 22 | |
|
23 | 23 | @author: marcink |
|
24 | 24 | """ |
|
25 | ||
|
25 | from beaker.cache import cache_region | |
|
26 | 26 | from functools import wraps |
|
27 | from pylons import session, url, request | |
|
27 | from pylons import config, session, url, request | |
|
28 | 28 | from pylons.controllers.util import abort, redirect |
|
29 | from pylons_app.lib.utils import get_repo_slug | |
|
29 | 30 | from pylons_app.model import meta |
|
30 | 31 | from pylons_app.model.db import User, Repo2Perm, Repository, Permission |
|
31 | from pylons_app.lib.utils import get_repo_slug | |
|
32 | 32 | from sqlalchemy.exc import OperationalError |
|
33 | 33 | from sqlalchemy.orm.exc import NoResultFound, MultipleResultsFound |
|
34 | 34 | import crypt |
|
35 | 35 | import logging |
|
36 | from pylons import config | |
|
36 | ||
|
37 | 37 | log = logging.getLogger(__name__) |
|
38 | 38 | |
|
39 | 39 | def get_crypt_password(password): |
@@ -43,11 +43,17 b' def get_crypt_password(password):' | |||
|
43 | 43 | """ |
|
44 | 44 | return crypt.crypt(password, '6a') |
|
45 | 45 | |
|
46 | ||
|
47 | @cache_region('super_short_term', 'cached_user') | |
|
48 | def get_user_cached(username): | |
|
49 | sa = meta.Session | |
|
50 | user = sa.query(User).filter(User.username == username).one() | |
|
51 | return user | |
|
52 | ||
|
46 | 53 | def authfunc(environ, username, password): |
|
47 | sa = meta.Session | |
|
48 | 54 | password_crypt = get_crypt_password(password) |
|
49 | 55 | try: |
|
50 | user = sa.query(User).filter(User.username == username).one() | |
|
56 | user = get_user_cached(username) | |
|
51 | 57 | except (NoResultFound, MultipleResultsFound, OperationalError) as e: |
|
52 | 58 | log.error(e) |
|
53 | 59 | user = None |
@@ -27,21 +27,23 b" It's implemented with basic auth functio" | |||
|
27 | 27 | """ |
|
28 | 28 | from datetime import datetime |
|
29 | 29 | from itertools import chain |
|
30 | from mercurial.error import RepoError | |
|
30 | 31 | from mercurial.hgweb import hgweb |
|
31 | 32 | from mercurial.hgweb.request import wsgiapplication |
|
32 | from mercurial.error import RepoError | |
|
33 | 33 | from paste.auth.basic import AuthBasicAuthenticator |
|
34 | 34 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
|
35 | from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware | |
|
35 | from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware, \ | |
|
36 | get_user_cached | |
|
36 | 37 | from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache, \ |
|
37 | 38 | check_repo_fast |
|
38 | 39 | from pylons_app.model import meta |
|
39 | 40 | from pylons_app.model.db import UserLog, User |
|
40 | import pylons_app.lib.helpers as h | |
|
41 | 41 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
|
42 | 42 | import logging |
|
43 | 43 | import os |
|
44 | import pylons_app.lib.helpers as h | |
|
44 | 45 | import traceback |
|
46 | ||
|
45 | 47 | log = logging.getLogger(__name__) |
|
46 | 48 | |
|
47 | 49 | class SimpleHg(object): |
@@ -56,7 +58,7 b' class SimpleHg(object):' | |||
|
56 | 58 | def __call__(self, environ, start_response): |
|
57 | 59 | if not is_mercurial(environ): |
|
58 | 60 | return self.application(environ, start_response) |
|
59 | else: | |
|
61 | ||
|
60 | 62 |
|
|
61 | 63 |
|
|
62 | 64 |
|
@@ -82,9 +84,7 b' class SimpleHg(object):' | |||
|
82 | 84 |
|
|
83 | 85 |
|
|
84 | 86 |
|
|
85 | sa = meta.Session | |
|
86 | user = sa.query(User)\ | |
|
87 | .filter(User.username == username).one() | |
|
87 | user = self.__get_user(username) | |
|
88 | 88 |
|
|
89 | 89 |
|
|
90 | 90 |
|
@@ -160,6 +160,11 b' class SimpleHg(object):' | |||
|
160 | 160 | def __get_environ_user(self, environ): |
|
161 | 161 | return environ.get('REMOTE_USER') |
|
162 | 162 | |
|
163 | def __get_user(self, username): | |
|
164 | return get_user_cached(username) | |
|
165 | ||
|
166 | ||
|
167 | ||
|
163 | 168 | def __get_size(self, repo_path, content_size): |
|
164 | 169 | size = int(content_size) |
|
165 | 170 | for path, dirs, files in os.walk(repo_path): |
@@ -16,6 +16,7 b'' | |||
|
16 | 16 | # along with this program; if not, write to the Free Software |
|
17 | 17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
18 | 18 | # MA 02110-1301, USA. |
|
19 | from beaker.cache import cache_region | |
|
19 | 20 | |
|
20 | 21 | """ |
|
21 | 22 | Created on April 18, 2010 |
@@ -75,6 +76,13 b' def check_repo(repo_name, base_path, ver' | |||
|
75 | 76 | log.info('%s repo is free for creation', repo_name) |
|
76 | 77 | return True |
|
77 | 78 | |
|
79 | ||
|
80 | @cache_region('super_short_term', 'cached_hg_ui') | |
|
81 | def get_hg_ui_cached(): | |
|
82 | from pylons_app.model.meta import Session | |
|
83 | sa = Session() | |
|
84 | return sa.query(HgAppUi).all() | |
|
85 | ||
|
78 | 86 | def make_ui(read_from='file', path=None, checkpaths=True): |
|
79 | 87 | """ |
|
80 | 88 | A function that will read python rc files or database |
@@ -112,10 +120,7 b" def make_ui(read_from='file', path=None," | |||
|
112 | 120 | |
|
113 | 121 | |
|
114 | 122 | elif read_from == 'db': |
|
115 | from pylons_app.model.meta import Session | |
|
116 | sa = Session() | |
|
117 | ||
|
118 | hg_ui = sa.query(HgAppUi).all() | |
|
123 | hg_ui = get_hg_ui_cached() | |
|
119 | 124 | for ui_ in hg_ui: |
|
120 | 125 | baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) |
|
121 | 126 |
General Comments 0
You need to be logged in to leave comments.
Login now