Mercurial > public > src > rhodecode
comparison pylons_app/lib/utils.py @ 364:1ef52a70f3b7
Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Wed, 14 Jul 2010 02:28:32 +0200 |
parents | 752675cdd167 |
children | 6484963056cd |
comparison
equal
deleted
inserted
replaced
362:71f25781079d | 364:1ef52a70f3b7 |
---|---|
25 | 25 |
26 import os | 26 import os |
27 import logging | 27 import logging |
28 from mercurial import ui, config, hg | 28 from mercurial import ui, config, hg |
29 from mercurial.error import RepoError | 29 from mercurial.error import RepoError |
30 from pylons_app.model.db import Repository, User | 30 from pylons_app.model.db import Repository, User, HgAppUi |
31 log = logging.getLogger(__name__) | 31 log = logging.getLogger(__name__) |
32 | 32 |
33 | 33 |
34 def get_repo_slug(request): | 34 def get_repo_slug(request): |
35 return request.environ['pylons.routes_dict'].get('repo_name') | 35 return request.environ['pylons.routes_dict'].get('repo_name') |
73 except RepoError: | 73 except RepoError: |
74 #it means that there is no valid repo there... | 74 #it means that there is no valid repo there... |
75 log.info('%s repo is free for creation', repo_name) | 75 log.info('%s repo is free for creation', repo_name) |
76 return True | 76 return True |
77 | 77 |
78 def make_ui(path=None, checkpaths=True): | 78 def make_ui(read_from='file', path=None, checkpaths=True): |
79 """ | 79 """ |
80 A funcion that will read python rc files and make an ui from read options | 80 A function that will read python rc files or database |
81 and make an mercurial ui object from read options | |
81 | 82 |
82 @param path: path to mercurial config file | 83 @param path: path to mercurial config file |
84 @param checkpaths: check the path | |
85 @param read_from: read from 'file' or 'db' | |
83 """ | 86 """ |
84 if not path: | |
85 log.error('repos config path is empty !') | |
86 | |
87 if not os.path.isfile(path): | |
88 log.warning('Unable to read config file %s' % path) | |
89 return False | |
90 #propagated from mercurial documentation | 87 #propagated from mercurial documentation |
91 sections = [ | 88 sections = ['alias', 'auth', |
92 'alias', | 89 'decode/encode', 'defaults', |
93 'auth', | 90 'diff', 'email', |
94 'decode/encode', | 91 'extensions', 'format', |
95 'defaults', | 92 'merge-patterns', 'merge-tools', |
96 'diff', | 93 'hooks', 'http_proxy', |
97 'email', | 94 'smtp', 'patch', |
98 'extensions', | 95 'paths', 'profiling', |
99 'format', | 96 'server', 'trusted', |
100 'merge-patterns', | 97 'ui', 'web', ] |
101 'merge-tools', | 98 baseui = ui.ui() |
102 'hooks', | |
103 'http_proxy', | |
104 'smtp', | |
105 'patch', | |
106 'paths', | |
107 'profiling', | |
108 'server', | |
109 'trusted', | |
110 'ui', | |
111 'web', | |
112 ] | |
113 | 99 |
114 baseui = ui.ui() | 100 |
115 cfg = config.config() | 101 if read_from == 'file': |
116 cfg.read(path) | 102 if not os.path.isfile(path): |
117 if checkpaths:check_repo_dir(cfg.items('paths')) | 103 log.warning('Unable to read config file %s' % path) |
118 | 104 return False |
119 for section in sections: | 105 |
120 for k, v in cfg.items(section): | 106 cfg = config.config() |
121 baseui.setconfig(section, k, v) | 107 cfg.read(path) |
108 for section in sections: | |
109 for k, v in cfg.items(section): | |
110 baseui.setconfig(section, k, v) | |
111 if checkpaths:check_repo_dir(cfg.items('paths')) | |
112 | |
113 | |
114 elif read_from == 'db': | |
115 from pylons_app.model.meta import Session | |
116 sa = Session() | |
117 | |
118 hg_ui = sa.query(HgAppUi).all() | |
119 for ui_ in hg_ui: | |
120 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) | |
121 | |
122 | 122 |
123 return baseui | 123 return baseui |
124 | |
125 | |
126 def set_hg_app_config(config): | |
127 config['hg_app_auth_realm'] = 'realm' | |
128 config['hg_app_name'] = 'app name' | |
124 | 129 |
125 def invalidate_cache(name, *args): | 130 def invalidate_cache(name, *args): |
126 """Invalidates given name cache""" | 131 """Invalidates given name cache""" |
127 | 132 |
128 from beaker.cache import region_invalidate | 133 from beaker.cache import region_invalidate |