Show More
@@ -13,7 +13,7 b' import rhodecode.lib.helpers' | |||||
13 |
|
13 | |||
14 | from rhodecode.config.routing import make_map |
|
14 | from rhodecode.config.routing import make_map | |
15 | from rhodecode.lib import celerypylons |
|
15 | from rhodecode.lib import celerypylons | |
16 |
from rhodecode.lib.auth import set_available_permissions |
|
16 | from rhodecode.lib.auth import set_available_permissions | |
17 | from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config |
|
17 | from rhodecode.lib.utils import repo2db_mapper, make_ui, set_rhodecode_config | |
18 | from rhodecode.model import init_model |
|
18 | from rhodecode.model import init_model | |
19 | from rhodecode.model.scm import ScmModel |
|
19 | from rhodecode.model.scm import ScmModel | |
@@ -72,13 +72,11 b' def load_environment(global_conf, app_co' | |||||
72 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') |
|
72 | sa_engine_db1 = engine_from_config(config, 'sqlalchemy.db1.') | |
73 |
|
73 | |||
74 | init_model(sa_engine_db1) |
|
74 | init_model(sa_engine_db1) | |
75 | #init baseui |
|
|||
76 | config['pylons.app_globals'].baseui = make_ui('db') |
|
|||
77 |
|
75 | |||
78 | g = config['pylons.app_globals'] |
|
76 | repos_path = make_ui('db').configitems('paths')[0][1] | |
79 |
repo2db_mapper(ScmModel().repo_scan( |
|
77 | repo2db_mapper(ScmModel().repo_scan(repos_path)) | |
80 | set_available_permissions(config) |
|
78 | set_available_permissions(config) | |
81 | set_base_path(config) |
|
79 | config['base_path'] = repos_path | |
82 | set_rhodecode_config(config) |
|
80 | set_rhodecode_config(config) | |
83 | # CONFIGURATION OPTIONS HERE (note: all config options will override |
|
81 | # CONFIGURATION OPTIONS HERE (note: all config options will override | |
84 | # any Pylons config options) |
|
82 | # any Pylons config options) |
@@ -31,8 +31,7 b' import formencode' | |||||
31 |
|
31 | |||
32 | from sqlalchemy import func |
|
32 | from sqlalchemy import func | |
33 | from formencode import htmlfill |
|
33 | from formencode import htmlfill | |
34 |
from pylons import request, session, tmpl_context as c, url, |
|
34 | from pylons import request, session, tmpl_context as c, url, config | |
35 | config |
|
|||
36 | from pylons.controllers.util import abort, redirect |
|
35 | from pylons.controllers.util import abort, redirect | |
37 | from pylons.i18n.translation import _ |
|
36 | from pylons.i18n.translation import _ | |
38 |
|
37 | |||
@@ -49,7 +48,7 b' from rhodecode.model.forms import UserFo' | |||||
49 | from rhodecode.model.scm import ScmModel |
|
48 | from rhodecode.model.scm import ScmModel | |
50 | from rhodecode.model.settings import SettingsModel |
|
49 | from rhodecode.model.settings import SettingsModel | |
51 | from rhodecode.model.user import UserModel |
|
50 | from rhodecode.model.user import UserModel | |
52 |
|
51 | from rhodecode.model.repo import RepoModel | ||
53 |
|
52 | |||
54 | log = logging.getLogger(__name__) |
|
53 | log = logging.getLogger(__name__) | |
55 |
|
54 | |||
@@ -105,8 +104,7 b' class SettingsController(BaseController)' | |||||
105 | if setting_id == 'mapping': |
|
104 | if setting_id == 'mapping': | |
106 | rm_obsolete = request.POST.get('destroy', False) |
|
105 | rm_obsolete = request.POST.get('destroy', False) | |
107 | log.debug('Rescanning directories with destroy=%s', rm_obsolete) |
|
106 | log.debug('Rescanning directories with destroy=%s', rm_obsolete) | |
108 |
|
107 | initial = ScmModel().repo_scan() | ||
109 | initial = ScmModel().repo_scan(g.paths[0][1], g.baseui) |
|
|||
110 | for repo_name in initial.keys(): |
|
108 | for repo_name in initial.keys(): | |
111 | invalidate_cache('get_repo_cached_%s' % repo_name) |
|
109 | invalidate_cache('get_repo_cached_%s' % repo_name) | |
112 |
|
110 |
@@ -2,7 +2,6 b'' | |||||
2 |
|
2 | |||
3 | from beaker.cache import CacheManager |
|
3 | from beaker.cache import CacheManager | |
4 | from beaker.util import parse_cache_config_options |
|
4 | from beaker.util import parse_cache_config_options | |
5 | from vcs.utils.lazy import LazyProperty |
|
|||
6 |
|
5 | |||
7 | class Globals(object): |
|
6 | class Globals(object): | |
8 | """Globals acts as a container for objects available throughout the |
|
7 | """Globals acts as a container for objects available throughout the | |
@@ -18,14 +17,3 b' class Globals(object):' | |||||
18 | """ |
|
17 | """ | |
19 | self.cache = CacheManager(**parse_cache_config_options(config)) |
|
18 | self.cache = CacheManager(**parse_cache_config_options(config)) | |
20 | self.available_permissions = None # propagated after init_model |
|
19 | self.available_permissions = None # propagated after init_model | |
21 | self.baseui = None # propagated after init_model |
|
|||
22 |
|
||||
23 | @LazyProperty |
|
|||
24 | def paths(self): |
|
|||
25 | if self.baseui: |
|
|||
26 | return self.baseui.configitems('paths') |
|
|||
27 |
|
||||
28 | @LazyProperty |
|
|||
29 | def base_path(self): |
|
|||
30 | if self.baseui: |
|
|||
31 | return self.paths[0][1] |
|
@@ -213,10 +213,6 b' def set_available_permissions(config):' | |||||
213 |
|
213 | |||
214 | config['available_permissions'] = [x.permission_name for x in all_perms] |
|
214 | config['available_permissions'] = [x.permission_name for x in all_perms] | |
215 |
|
215 | |||
216 | def set_base_path(config): |
|
|||
217 | config['base_path'] = config['pylons.app_globals'].base_path |
|
|||
218 |
|
||||
219 |
|
||||
220 | def fill_perms(user): |
|
216 | def fill_perms(user): | |
221 | """Fills user permission attribute with permissions taken from database |
|
217 | """Fills user permission attribute with permissions taken from database | |
222 | works for permissions given for repositories, and for permissions that |
|
218 | works for permissions given for repositories, and for permissions that |
@@ -19,11 +19,12 b' class BaseController(WSGIController):' | |||||
19 | c.rhodecode_name = config.get('rhodecode_title') |
|
19 | c.rhodecode_name = config.get('rhodecode_title') | |
20 | c.ga_code = config.get('rhodecode_ga_code') |
|
20 | c.ga_code = config.get('rhodecode_ga_code') | |
21 | c.repo_name = get_repo_slug(request) |
|
21 | c.repo_name = get_repo_slug(request) | |
22 | c.cached_repo_list = ScmModel().get_repos() |
|
|||
23 | c.backends = BACKENDS.keys() |
|
22 | c.backends = BACKENDS.keys() | |
24 | self.cut_off_limit = int(config.get('cut_off_limit')) |
|
23 | self.cut_off_limit = int(config.get('cut_off_limit')) | |
|
24 | ||||
25 | self.sa = meta.Session() |
|
25 | self.sa = meta.Session() | |
26 | scm_model = ScmModel(self.sa) |
|
26 | scm_model = ScmModel(self.sa) | |
|
27 | c.cached_repo_list = scm_model.get_repos() | |||
27 | #c.unread_journal = scm_model.get_unread_journal() |
|
28 | #c.unread_journal = scm_model.get_unread_journal() | |
28 |
|
29 | |||
29 | if c.repo_name: |
|
30 | if c.repo_name: |
@@ -81,7 +81,7 b' class WhooshIndexingDaemon(object):' | |||||
81 | if not repo_location: |
|
81 | if not repo_location: | |
82 | raise Exception('You have to provide repositories location') |
|
82 | raise Exception('You have to provide repositories location') | |
83 |
|
83 | |||
84 |
self.repo_paths = ScmModel(sa).repo_scan(self.repo_location |
|
84 | self.repo_paths = ScmModel(sa).repo_scan(self.repo_location) | |
85 |
|
85 | |||
86 | if repo_list: |
|
86 | if repo_list: | |
87 | filtered_repo_paths = {} |
|
87 | filtered_repo_paths = {} |
@@ -30,38 +30,30 b' import logging' | |||||
30 | import traceback |
|
30 | import traceback | |
31 | from datetime import datetime |
|
31 | from datetime import datetime | |
32 |
|
32 | |||
|
33 | from sqlalchemy.orm import joinedload | |||
|
34 | ||||
|
35 | from vcs.utils.lazy import LazyProperty | |||
|
36 | from vcs.backends import get_backend | |||
|
37 | ||||
33 | from rhodecode.model import BaseModel |
|
38 | from rhodecode.model import BaseModel | |
34 | from rhodecode.model.caching_query import FromCache |
|
39 | from rhodecode.model.caching_query import FromCache | |
35 | from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ |
|
40 | from rhodecode.model.db import Repository, RepoToPerm, User, Permission, \ | |
36 | Statistics, UsersGroup, UsersGroupToPerm |
|
41 | Statistics, UsersGroup, UsersGroupToPerm, RhodeCodeUi | |
37 | from rhodecode.model.user import UserModel |
|
42 | from rhodecode.model.user import UserModel | |
38 | from rhodecode.model.users_group import UsersGroupMember, UsersGroupModel |
|
43 | from rhodecode.model.users_group import UsersGroupMember, UsersGroupModel | |
39 |
|
44 | |||
40 | from vcs.backends import get_backend |
|
|||
41 |
|
45 | |||
42 | log = logging.getLogger(__name__) |
|
46 | log = logging.getLogger(__name__) | |
43 |
|
47 | |||
44 | class RepoModel(BaseModel): |
|
48 | class RepoModel(BaseModel): | |
45 |
|
49 | |||
46 | def __init__(self, sa=None): |
|
50 | @LazyProperty | |
47 | try: |
|
51 | def repos_path(self): | |
48 | from pylons import app_globals |
|
52 | """Get's the repositories root path from database | |
49 | self._base_path = app_globals.base_path |
|
53 | """ | |
50 | except: |
|
|||
51 | self._base_path = None |
|
|||
52 |
|
||||
53 | super(RepoModel, self).__init__(sa) |
|
|||
54 |
|
54 | |||
55 | @property |
|
55 | q = self.sa.query(RhodeCodeUi).filter(RhodeCodeUi.ui_key == '/').one() | |
56 | def base_path(self): |
|
56 | return q.ui_value | |
57 | if self._base_path is None: |
|
|||
58 | raise Exception('Base Path is empty, try set this after' |
|
|||
59 | 'class initialization when not having ' |
|
|||
60 | 'app_globals available') |
|
|||
61 | return self._base_path |
|
|||
62 |
|
||||
63 | super(RepoModel, self).__init__() |
|
|||
64 |
|
||||
65 |
|
57 | |||
66 | def get(self, repo_id, cache=False): |
|
58 | def get(self, repo_id, cache=False): | |
67 | repo = self.sa.query(Repository)\ |
|
59 | repo = self.sa.query(Repository)\ | |
@@ -82,6 +74,25 b' class RepoModel(BaseModel):' | |||||
82 | "get_repo_%s" % repo_name)) |
|
74 | "get_repo_%s" % repo_name)) | |
83 | return repo.scalar() |
|
75 | return repo.scalar() | |
84 |
|
76 | |||
|
77 | ||||
|
78 | def get_full(self, repo_name, cache=False, invalidate=False): | |||
|
79 | repo = self.sa.query(Repository)\ | |||
|
80 | .options(joinedload(Repository.fork))\ | |||
|
81 | .options(joinedload(Repository.user))\ | |||
|
82 | .options(joinedload(Repository.followers))\ | |||
|
83 | .options(joinedload(Repository.repo_to_perm))\ | |||
|
84 | .options(joinedload(Repository.users_group_to_perm))\ | |||
|
85 | .filter(Repository.repo_name == repo_name)\ | |||
|
86 | ||||
|
87 | if cache: | |||
|
88 | repo = repo.options(FromCache("sql_cache_long", | |||
|
89 | "get_repo_full_%s" % repo_name)) | |||
|
90 | if invalidate: | |||
|
91 | repo.invalidate() | |||
|
92 | ||||
|
93 | return repo.scalar() | |||
|
94 | ||||
|
95 | ||||
85 | def get_users_js(self): |
|
96 | def get_users_js(self): | |
86 |
|
97 | |||
87 | users = self.sa.query(User).filter(User.active == True).all() |
|
98 | users = self.sa.query(User).filter(User.active == True).all() | |
@@ -290,8 +301,8 b' class RepoModel(BaseModel):' | |||||
290 | :param alias: |
|
301 | :param alias: | |
291 | """ |
|
302 | """ | |
292 | from rhodecode.lib.utils import check_repo |
|
303 | from rhodecode.lib.utils import check_repo | |
293 |
repo_path = os.path.join(self. |
|
304 | repo_path = os.path.join(self.repos_path, repo_name) | |
294 |
if check_repo(repo_name, self. |
|
305 | if check_repo(repo_name, self.repos_path): | |
295 | log.info('creating repo %s in %s', repo_name, repo_path) |
|
306 | log.info('creating repo %s in %s', repo_name, repo_path) | |
296 | backend = get_backend(alias) |
|
307 | backend = get_backend(alias) | |
297 | backend(repo_path, create=True) |
|
308 | backend(repo_path, create=True) | |
@@ -304,8 +315,8 b' class RepoModel(BaseModel):' | |||||
304 | """ |
|
315 | """ | |
305 | log.info('renaming repo from %s to %s', old, new) |
|
316 | log.info('renaming repo from %s to %s', old, new) | |
306 |
|
317 | |||
307 |
old_path = os.path.join(self. |
|
318 | old_path = os.path.join(self.repos_path, old) | |
308 |
new_path = os.path.join(self. |
|
319 | new_path = os.path.join(self.repos_path, new) | |
309 | if os.path.isdir(new_path): |
|
320 | if os.path.isdir(new_path): | |
310 | raise Exception('Was trying to rename to already existing dir %s', |
|
321 | raise Exception('Was trying to rename to already existing dir %s', | |
311 | new_path) |
|
322 | new_path) | |
@@ -319,13 +330,13 b' class RepoModel(BaseModel):' | |||||
319 | by reverting the renames on this repository |
|
330 | by reverting the renames on this repository | |
320 | :param repo: repo object |
|
331 | :param repo: repo object | |
321 | """ |
|
332 | """ | |
322 |
rm_path = os.path.join(self. |
|
333 | rm_path = os.path.join(self.repos_path, repo.repo_name) | |
323 | log.info("Removing %s", rm_path) |
|
334 | log.info("Removing %s", rm_path) | |
324 | #disable hg/git |
|
335 | #disable hg/git | |
325 | alias = repo.repo_type |
|
336 | alias = repo.repo_type | |
326 | shutil.move(os.path.join(rm_path, '.%s' % alias), |
|
337 | shutil.move(os.path.join(rm_path, '.%s' % alias), | |
327 | os.path.join(rm_path, 'rm__.%s' % alias)) |
|
338 | os.path.join(rm_path, 'rm__.%s' % alias)) | |
328 | #disable repo |
|
339 | #disable repo | |
329 |
shutil.move(rm_path, os.path.join(self. |
|
340 | shutil.move(rm_path, os.path.join(self.repos_path, 'rm__%s__%s' \ | |
330 | % (datetime.today().isoformat(), |
|
341 | % (datetime.today().isoformat(), | |
331 | repo.repo_name))) |
|
342 | repo.repo_name))) |
General Comments 0
You need to be logged in to leave comments.
Login now