Show More
@@ -33,7 +33,7 b' from rhodecode.lib.auth import LoginRequ' | |||
|
33 | 33 | from rhodecode.lib.base import BaseController, render |
|
34 | 34 | from rhodecode.lib.celerylib import tasks, run_task |
|
35 | 35 | from rhodecode.lib.utils import repo2db_mapper, invalidate_cache, \ |
|
36 | set_rhodecode_config, get_hg_settings, get_hg_ui_settings | |
|
36 | set_rhodecode_config | |
|
37 | 37 | from rhodecode.model.db import RhodeCodeUi, Repository |
|
38 | 38 | from rhodecode.model.forms import UserForm, ApplicationSettingsForm, \ |
|
39 | 39 | ApplicationUiSettingsForm |
@@ -68,8 +68,8 b' class SettingsController(BaseController)' | |||
|
68 | 68 | """GET /admin/settings: All items in the collection""" |
|
69 | 69 | # url('admin_settings') |
|
70 | 70 | |
|
71 |
defaults = |
|
|
72 | defaults.update(get_hg_ui_settings()) | |
|
71 | defaults = SettingsModel().get_app_settings() | |
|
72 | defaults.update(self.get_hg_ui_settings()) | |
|
73 | 73 | return htmlfill.render( |
|
74 | 74 | render('admin/settings/settings.html'), |
|
75 | 75 | defaults=defaults, |
@@ -109,7 +109,7 b' class SettingsController(BaseController)' | |||
|
109 | 109 | h.flash(_('Repositories successfully rescanned'), category='success') |
|
110 | 110 | |
|
111 | 111 | if setting_id == 'whoosh': |
|
112 | repo_location = get_hg_ui_settings()['paths_root_path'] | |
|
112 | repo_location = self.get_hg_ui_settings()['paths_root_path'] | |
|
113 | 113 | full_index = request.POST.get('full_index', False) |
|
114 | 114 | task = run_task(tasks.whoosh_index, repo_location, full_index) |
|
115 | 115 | |
@@ -312,3 +312,24 b' class SettingsController(BaseController)' | |||
|
312 | 312 | |
|
313 | 313 | return render('admin/repos/repo_add_create_repository.html') |
|
314 | 314 | |
|
315 | def get_hg_ui_settings(self): | |
|
316 | ret = self.sa.query(RhodeCodeUi).all() | |
|
317 | ||
|
318 | if not ret: | |
|
319 | raise Exception('Could not get application ui settings !') | |
|
320 | settings = {} | |
|
321 | for each in ret: | |
|
322 | k = each.ui_key | |
|
323 | v = each.ui_value | |
|
324 | if k == '/': | |
|
325 | k = 'root_path' | |
|
326 | ||
|
327 | if k.find('.') != -1: | |
|
328 | k = k.replace('.', '_') | |
|
329 | ||
|
330 | if each.ui_section == 'hooks': | |
|
331 | v = each.ui_active | |
|
332 | ||
|
333 | settings[each.ui_section + '_' + k] = v | |
|
334 | ||
|
335 | return settings |
@@ -63,7 +63,7 b' from dulwich.web import HTTPGitApplicati' | |||
|
63 | 63 | from paste.auth.basic import AuthBasicAuthenticator |
|
64 | 64 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
|
65 | 65 | from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware |
|
66 |
from rhodecode.lib.utils import |
|
|
66 | from rhodecode.lib.utils import invalidate_cache, check_repo_fast | |
|
67 | 67 | from rhodecode.model.user import UserModel |
|
68 | 68 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
|
69 | 69 | import logging |
@@ -72,6 +72,18 b' import traceback' | |||
|
72 | 72 | |
|
73 | 73 | log = logging.getLogger(__name__) |
|
74 | 74 | |
|
75 | def is_git(environ): | |
|
76 | """ | |
|
77 | Returns True if request's target is git server. ``HTTP_USER_AGENT`` would | |
|
78 | then have git client version given. | |
|
79 | ||
|
80 | :param environ: | |
|
81 | """ | |
|
82 | http_user_agent = environ.get('HTTP_USER_AGENT') | |
|
83 | if http_user_agent and http_user_agent.startswith('git'): | |
|
84 | return True | |
|
85 | return False | |
|
86 | ||
|
75 | 87 | class SimpleGit(object): |
|
76 | 88 | |
|
77 | 89 | def __init__(self, application, config): |
@@ -24,14 +24,13 b' Created on 2010-04-28' | |||
|
24 | 24 | SimpleHG middleware for handling mercurial protocol request (push/clone etc.) |
|
25 | 25 | It's implemented with basic auth function |
|
26 | 26 | """ |
|
27 | from itertools import chain | |
|
28 | 27 | from mercurial.error import RepoError |
|
29 | 28 | from mercurial.hgweb import hgweb |
|
30 | 29 | from mercurial.hgweb.request import wsgiapplication |
|
31 | 30 | from paste.auth.basic import AuthBasicAuthenticator |
|
32 | 31 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
|
33 | 32 | from rhodecode.lib.auth import authfunc, HasPermissionAnyMiddleware |
|
34 |
from rhodecode.lib.utils import |
|
|
33 | from rhodecode.lib.utils import make_ui, invalidate_cache, \ | |
|
35 | 34 | check_repo_fast, ui_sections |
|
36 | 35 | from rhodecode.model.user import UserModel |
|
37 | 36 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError |
@@ -41,6 +40,16 b' import traceback' | |||
|
41 | 40 | |
|
42 | 41 | log = logging.getLogger(__name__) |
|
43 | 42 | |
|
43 | def is_mercurial(environ): | |
|
44 | """ | |
|
45 | Returns True if request's target is mercurial server - header | |
|
46 | ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. | |
|
47 | """ | |
|
48 | http_accept = environ.get('HTTP_ACCEPT') | |
|
49 | if http_accept and http_accept.startswith('application/mercurial'): | |
|
50 | return True | |
|
51 | return False | |
|
52 | ||
|
44 | 53 | class SimpleHg(object): |
|
45 | 54 | |
|
46 | 55 | def __init__(self, application, config): |
@@ -143,7 +152,7 b' class SimpleHg(object):' | |||
|
143 | 152 | #invalidate cache on push |
|
144 | 153 | if self.action == 'push': |
|
145 | 154 | self.__invalidate_cache(repo_name) |
|
146 | ||
|
155 | ||
|
147 | 156 | return app(environ, start_response) |
|
148 | 157 | |
|
149 | 158 |
@@ -27,10 +27,10 b' from mercurial import ui, config, hg' | |||
|
27 | 27 | from mercurial.error import RepoError |
|
28 | 28 | from rhodecode.model import meta |
|
29 | 29 | from rhodecode.model.caching_query import FromCache |
|
30 |
from rhodecode.model.db import Repository, User, RhodeCodeUi, |
|
|
31 | UserLog | |
|
30 | from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog | |
|
32 | 31 | from rhodecode.model.repo import RepoModel |
|
33 | 32 | from rhodecode.model.user import UserModel |
|
33 | ||
|
34 | 34 | from vcs.backends.base import BaseChangeset |
|
35 | 35 | from paste.script import command |
|
36 | 36 | import ConfigParser |
@@ -46,28 +46,6 b' log = logging.getLogger(__name__)' | |||
|
46 | 46 | def get_repo_slug(request): |
|
47 | 47 | return request.environ['pylons.routes_dict'].get('repo_name') |
|
48 | 48 | |
|
49 | def is_mercurial(environ): | |
|
50 | """ | |
|
51 | Returns True if request's target is mercurial server - header | |
|
52 | ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. | |
|
53 | """ | |
|
54 | http_accept = environ.get('HTTP_ACCEPT') | |
|
55 | if http_accept and http_accept.startswith('application/mercurial'): | |
|
56 | return True | |
|
57 | return False | |
|
58 | ||
|
59 | def is_git(environ): | |
|
60 | """ | |
|
61 | Returns True if request's target is git server. ``HTTP_USER_AGENT`` would | |
|
62 | then have git client version given. | |
|
63 | ||
|
64 | :param environ: | |
|
65 | """ | |
|
66 | http_user_agent = environ.get('HTTP_USER_AGENT') | |
|
67 | if http_user_agent and http_user_agent.startswith('git'): | |
|
68 | return True | |
|
69 | return False | |
|
70 | ||
|
71 | 49 | def action_logger(user, action, repo, ipaddr='', sa=None): |
|
72 | 50 | """ |
|
73 | 51 | Action logger for various actions made by users |
@@ -110,17 +88,16 b' def action_logger(user, action, repo, ip' | |||
|
110 | 88 | user_log = UserLog() |
|
111 | 89 | user_log.user_id = user_obj.user_id |
|
112 | 90 | user_log.action = action |
|
113 | ||
|
91 | ||
|
114 | 92 | user_log.repository_id = repo_obj.repo_id |
|
115 | 93 | user_log.repository_name = repo_name |
|
116 | ||
|
94 | ||
|
117 | 95 | user_log.action_date = datetime.datetime.now() |
|
118 | 96 | user_log.user_ip = ipaddr |
|
119 | 97 | sa.add(user_log) |
|
120 | 98 | sa.commit() |
|
121 | 99 | |
|
122 | log.info('Adding user %s, action %s on %s', | |
|
123 | user_obj.username, action, repo) | |
|
100 | log.info('Adding user %s, action %s on %s', user_obj, action, repo) | |
|
124 | 101 | except: |
|
125 | 102 | log.error(traceback.format_exc()) |
|
126 | 103 | sa.rollback() |
@@ -150,10 +127,6 b' def get_repos(path, recursive=False, ini' | |||
|
150 | 127 | except VCSError: |
|
151 | 128 | pass |
|
152 | 129 | |
|
153 | if __name__ == '__main__': | |
|
154 | get_repos('', '/home/marcink/workspace-python') | |
|
155 | ||
|
156 | ||
|
157 | 130 | def check_repo_fast(repo_name, base_path): |
|
158 | 131 | if os.path.isdir(os.path.join(base_path, repo_name)):return False |
|
159 | 132 | return True |
@@ -185,66 +158,6 b' def ask_ok(prompt, retries=4, complaint=' | |||
|
185 | 158 | if retries < 0: raise IOError |
|
186 | 159 | print complaint |
|
187 | 160 | |
|
188 | def get_hg_ui_cached(): | |
|
189 | try: | |
|
190 | sa = meta.Session | |
|
191 | ret = sa.query(RhodeCodeUi)\ | |
|
192 | .options(FromCache("sql_cache_short", "get_hg_ui_settings"))\ | |
|
193 | .all() | |
|
194 | except: | |
|
195 | pass | |
|
196 | finally: | |
|
197 | meta.Session.remove() | |
|
198 | return ret | |
|
199 | ||
|
200 | ||
|
201 | def get_hg_settings(): | |
|
202 | try: | |
|
203 | sa = meta.Session() | |
|
204 | ret = sa.query(RhodeCodeSettings)\ | |
|
205 | .options(FromCache("sql_cache_short", "get_hg_settings"))\ | |
|
206 | .all() | |
|
207 | except: | |
|
208 | pass | |
|
209 | finally: | |
|
210 | meta.Session.remove() | |
|
211 | ||
|
212 | if not ret: | |
|
213 | raise Exception('Could not get application settings !') | |
|
214 | settings = {} | |
|
215 | for each in ret: | |
|
216 | settings['rhodecode_' + each.app_settings_name] = each.app_settings_value | |
|
217 | ||
|
218 | return settings | |
|
219 | ||
|
220 | def get_hg_ui_settings(): | |
|
221 | try: | |
|
222 | sa = meta.Session() | |
|
223 | ret = sa.query(RhodeCodeUi).all() | |
|
224 | except: | |
|
225 | pass | |
|
226 | finally: | |
|
227 | meta.Session.remove() | |
|
228 | ||
|
229 | if not ret: | |
|
230 | raise Exception('Could not get application ui settings !') | |
|
231 | settings = {} | |
|
232 | for each in ret: | |
|
233 | k = each.ui_key | |
|
234 | v = each.ui_value | |
|
235 | if k == '/': | |
|
236 | k = 'root_path' | |
|
237 | ||
|
238 | if k.find('.') != -1: | |
|
239 | k = k.replace('.', '_') | |
|
240 | ||
|
241 | if each.ui_section == 'hooks': | |
|
242 | v = each.ui_active | |
|
243 | ||
|
244 | settings[each.ui_section + '_' + k] = v | |
|
245 | ||
|
246 | return settings | |
|
247 | ||
|
248 | 161 | #propagated from mercurial documentation |
|
249 | 162 | ui_sections = ['alias', 'auth', |
|
250 | 163 | 'decode/encode', 'defaults', |
@@ -288,7 +201,12 b" def make_ui(read_from='file', path=None," | |||
|
288 | 201 | |
|
289 | 202 | |
|
290 | 203 | elif read_from == 'db': |
|
291 | hg_ui = get_hg_ui_cached() | |
|
204 | sa = meta.Session() | |
|
205 | ret = sa.query(RhodeCodeUi)\ | |
|
206 | .options(FromCache("sql_cache_short", | |
|
207 | "get_hg_ui_settings")).all() | |
|
208 | meta.Session.remove() | |
|
209 | hg_ui = ret | |
|
292 | 210 | for ui_ in hg_ui: |
|
293 | 211 | if ui_.ui_active: |
|
294 | 212 | log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value) |
@@ -297,7 +215,12 b" def make_ui(read_from='file', path=None," | |||
|
297 | 215 | |
|
298 | 216 | |
|
299 | 217 | def set_rhodecode_config(config): |
|
300 | hgsettings = get_hg_settings() | |
|
218 | """ | |
|
219 | Updates pylons config with new settings from database | |
|
220 | :param config: | |
|
221 | """ | |
|
222 | from rhodecode.model.settings import SettingsModel | |
|
223 | hgsettings = SettingsModel().get_app_settings() | |
|
301 | 224 | |
|
302 | 225 | for k, v in hgsettings.items(): |
|
303 | 226 | config[k] = v |
@@ -28,7 +28,6 b' from rhodecode.model import BaseModel' | |||
|
28 | 28 | from rhodecode.model.caching_query import FromCache |
|
29 | 29 | from rhodecode.model.db import RhodeCodeSettings |
|
30 | 30 | from sqlalchemy.orm import joinedload |
|
31 | from sqlalchemy.orm.session import make_transient | |
|
32 | 31 | import logging |
|
33 | 32 | |
|
34 | 33 | log = logging.getLogger(__name__) |
@@ -46,6 +45,18 b' class SettingsModel(BaseModel):' | |||
|
46 | 45 | "get_setting_%s" % settings_key)) |
|
47 | 46 | return r |
|
48 | 47 | |
|
48 | def get_app_settings(self): | |
|
49 | ret = self.sa.query(RhodeCodeSettings)\ | |
|
50 | .options(FromCache("sql_cache_short", | |
|
51 | "get_hg_settings")).all() | |
|
52 | ||
|
53 | if not ret: | |
|
54 | raise Exception('Could not get application settings !') | |
|
55 | settings = {} | |
|
56 | for each in ret: | |
|
57 | settings['rhodecode_' + each.app_settings_name] = each.app_settings_value | |
|
58 | ||
|
59 | return settings | |
|
49 | 60 | |
|
50 | 61 | def get_ldap_settings(self): |
|
51 | 62 | """ |
General Comments 0
You need to be logged in to leave comments.
Login now