Show More
@@ -1,4 +1,5 b'' | |||
|
1 | """Routes configuration | |
|
1 | """ | |
|
2 | Routes configuration | |
|
2 | 3 | |
|
3 | 4 | The more specific and detailed routes should be defined first so they |
|
4 | 5 | may take precedent over the more generic routes. For more information |
@@ -15,24 +16,28 b' def make_map(config):' | |||
|
15 | 16 | map.minimization = False |
|
16 | 17 | map.explicit = False |
|
17 | 18 | |
|
19 | def check_repo(environ, match_dict): | |
|
20 | """ | |
|
21 | check for valid repository for proper 404 handling | |
|
22 | :param environ: | |
|
23 | :param match_dict: | |
|
24 | """ | |
|
25 | repo_name = match_dict.get('repo_name') | |
|
26 | return not cr(repo_name, config['base_path']) | |
|
27 | ||
|
18 | 28 | # The ErrorController route (handles 404/500 error pages); it should |
|
19 | 29 | # likely stay at the top, ensuring it can always be resolved |
|
20 | 30 | map.connect('/error/{action}', controller='error') |
|
21 | 31 | map.connect('/error/{action}/{id}', controller='error') |
|
22 | 32 | |
|
33 | #========================================================================== | |
|
23 | 34 | # CUSTOM ROUTES HERE |
|
35 | #========================================================================== | |
|
36 | ||
|
37 | #MAIN PAGE | |
|
24 | 38 | map.connect('hg_home', '/', controller='hg', action='index') |
|
25 | ||
|
26 | def check_repo(environ, match_dict): | |
|
27 | """ | |
|
28 | check for valid repository for proper 404 handling | |
|
29 | @param environ: | |
|
30 | @param match_dict: | |
|
31 | """ | |
|
32 | repo_name = match_dict.get('repo_name') | |
|
33 | return not cr(repo_name, config['base_path']) | |
|
34 | ||
|
35 | #REST REPO MAP | |
|
39 | ||
|
40 | #ADMIN REPOSITORY REST ROUTES | |
|
36 | 41 | with map.submapper(path_prefix='/_admin', controller='admin/repos') as m: |
|
37 | 42 | m.connect("repos", "/repos", |
|
38 | 43 | action="create", conditions=dict(method=["POST"])) |
@@ -67,11 +72,14 b' def make_map(config):' | |||
|
67 | 72 | m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", |
|
68 | 73 | action="delete_perm_user", conditions=dict(method=["DELETE"], |
|
69 | 74 | function=check_repo)) |
|
70 | ||
|
75 | ||
|
76 | #ADMIN USER REST ROUTES | |
|
71 | 77 | map.resource('user', 'users', controller='admin/users', path_prefix='/_admin') |
|
78 | ||
|
79 | #ADMIN PERMISSIONS REST ROUTES | |
|
72 | 80 | map.resource('permission', 'permissions', controller='admin/permissions', path_prefix='/_admin') |
|
73 | ||
|
74 | #REST SETTINGS MAP | |
|
81 | ||
|
82 | #ADMIN SETTINGS REST ROUTES | |
|
75 | 83 | with map.submapper(path_prefix='/_admin', controller='admin/settings') as m: |
|
76 | 84 | m.connect("admin_settings", "/settings", |
|
77 | 85 | action="create", conditions=dict(method=["POST"])) |
@@ -101,8 +109,8 b' def make_map(config):' | |||
|
101 | 109 | action="my_account_update", conditions=dict(method=["PUT"])) |
|
102 | 110 | m.connect("admin_settings_create_repository", "/create_repository", |
|
103 | 111 | action="create_repository", conditions=dict(method=["GET"])) |
|
104 | ||
|
105 | #ADMIN | |
|
112 | ||
|
113 | #ADMIN MAIN PAGES | |
|
106 | 114 | with map.submapper(path_prefix='/_admin', controller='admin/admin') as m: |
|
107 | 115 | m.connect('admin_home', '', action='index')#main page |
|
108 | 116 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
@@ -110,13 +118,13 b' def make_map(config):' | |||
|
110 | 118 | #SEARCH |
|
111 | 119 | map.connect('search', '/_admin/search', controller='search',) |
|
112 | 120 | map.connect('search_repo', '/_admin/search/{search_repo:.*}', controller='search') |
|
113 | ||
|
121 | ||
|
114 | 122 | #LOGIN/LOGOUT/REGISTER/SIGN IN |
|
115 | 123 | map.connect('login_home', '/_admin/login', controller='login') |
|
116 | 124 | map.connect('logout_home', '/_admin/logout', controller='login', action='logout') |
|
117 | 125 | map.connect('register', '/_admin/register', controller='login', action='register') |
|
118 | 126 | map.connect('reset_password', '/_admin/password_reset', controller='login', action='password_reset') |
|
119 | ||
|
127 | ||
|
120 | 128 | #FEEDS |
|
121 | 129 | map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', |
|
122 | 130 | controller='feed', action='rss', |
@@ -124,9 +132,9 b' def make_map(config):' | |||
|
124 | 132 | map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', |
|
125 | 133 | controller='feed', action='atom', |
|
126 | 134 | conditions=dict(function=check_repo)) |
|
127 | ||
|
128 | ||
|
129 | #OTHERS | |
|
135 | ||
|
136 | ||
|
137 | #REPOSITORY ROUTES | |
|
130 | 138 | map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', |
|
131 | 139 | controller='changeset', revision='tip', |
|
132 | 140 | conditions=dict(function=check_repo)) |
@@ -142,7 +150,7 b' def make_map(config):' | |||
|
142 | 150 | map.connect('tags_home', '/{repo_name:.*}/tags', |
|
143 | 151 | controller='tags', conditions=dict(function=check_repo)) |
|
144 | 152 | map.connect('changelog_home', '/{repo_name:.*}/changelog', |
|
145 |
controller='changelog', conditions=dict(function=check_repo)) |
|
|
153 | controller='changelog', conditions=dict(function=check_repo)) | |
|
146 | 154 | map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', |
|
147 | 155 | controller='files', revision='tip', f_path='', |
|
148 | 156 | conditions=dict(function=check_repo)) |
@@ -157,10 +165,10 b' def make_map(config):' | |||
|
157 | 165 | conditions=dict(function=check_repo)) |
|
158 | 166 | map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', |
|
159 | 167 | controller='files', action='annotate', revision='tip', f_path='', |
|
160 |
conditions=dict(function=check_repo)) |
|
|
168 | conditions=dict(function=check_repo)) | |
|
161 | 169 | map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', |
|
162 | 170 | controller='files', action='archivefile', revision='tip', |
|
163 |
conditions=dict(function=check_repo)) |
|
|
171 | conditions=dict(function=check_repo)) | |
|
164 | 172 | map.connect('repo_settings_delete', '/{repo_name:.*}/settings', |
|
165 | 173 | controller='settings', action="delete", |
|
166 | 174 | conditions=dict(method=["DELETE"], function=check_repo)) |
@@ -177,5 +185,5 b' def make_map(config):' | |||
|
177 | 185 | map.connect('repo_fork_home', '/{repo_name:.*}/fork', |
|
178 | 186 | controller='settings', action='fork', |
|
179 | 187 | conditions=dict(function=check_repo)) |
|
180 | ||
|
188 | ||
|
181 | 189 | return map |
@@ -193,7 +193,7 b' class ReposController(BaseController):' | |||
|
193 | 193 | def delete_perm_user(self, repo_name): |
|
194 | 194 | """ |
|
195 | 195 | DELETE an existing repository permission user |
|
196 |
|
|
|
196 | :param repo_name: | |
|
197 | 197 | """ |
|
198 | 198 | |
|
199 | 199 | try: |
@@ -66,7 +66,7 b' class PasswordGenerator(object):' | |||
|
66 | 66 | |
|
67 | 67 | def get_crypt_password(password): |
|
68 | 68 | """Cryptographic function used for password hashing based on sha1 |
|
69 |
|
|
|
69 | :param password: password to hash | |
|
70 | 70 | """ |
|
71 | 71 | return bcrypt.hashpw(password, bcrypt.gensalt(10)) |
|
72 | 72 | |
@@ -120,7 +120,7 b' def set_available_permissions(config):' | |||
|
120 | 120 | permission given in db. We don't wannt to check each time from db for new |
|
121 | 121 | permissions since adding a new permission also requires application restart |
|
122 | 122 | ie. to decorate new views with the newly created permission |
|
123 |
|
|
|
123 | :param config: | |
|
124 | 124 | """ |
|
125 | 125 | log.info('getting information about all available permissions') |
|
126 | 126 | try: |
@@ -138,7 +138,7 b' def fill_data(user):' | |||
|
138 | 138 | """ |
|
139 | 139 | Fills user data with those from database and log out user if not present |
|
140 | 140 | in database |
|
141 |
|
|
|
141 | :param user: | |
|
142 | 142 | """ |
|
143 | 143 | sa = meta.Session |
|
144 | 144 | dbuser = sa.query(User).get(user.user_id) |
@@ -156,7 +156,7 b' def fill_data(user):' | |||
|
156 | 156 | def fill_perms(user): |
|
157 | 157 | """ |
|
158 | 158 | Fills user permission attribute with permissions taken from database |
|
159 |
|
|
|
159 | :param user: | |
|
160 | 160 | """ |
|
161 | 161 | |
|
162 | 162 | sa = meta.Session |
@@ -228,7 +228,7 b' def fill_perms(user):' | |||
|
228 | 228 | def get_user(session): |
|
229 | 229 | """ |
|
230 | 230 | Gets user from session, and wraps permissions into user |
|
231 |
|
|
|
231 | :param session: | |
|
232 | 232 | """ |
|
233 | 233 | user = session.get('rhodecode_user', AuthUser()) |
|
234 | 234 | if user.is_authenticated: |
@@ -28,8 +28,8 b' from webhelpers.text import chop_at, col' | |||
|
28 | 28 | class _Link(object): |
|
29 | 29 | ''' |
|
30 | 30 | Make a url based on label and url with help of url_for |
|
31 |
|
|
|
32 |
|
|
|
31 | :param label:name of link if not defined url is used | |
|
32 | :param url: the url for link | |
|
33 | 33 | ''' |
|
34 | 34 | |
|
35 | 35 | def __call__(self, label='', *url_, **urlargs): |
@@ -52,8 +52,8 b' get_error = _GetError()' | |||
|
52 | 52 | def recursive_replace(str, replace=' '): |
|
53 | 53 | """ |
|
54 | 54 | Recursive replace of given sign to just one instance |
|
55 |
|
|
|
56 |
|
|
|
55 | :param str: given string | |
|
56 | :param replace:char to find and replace multiple instances | |
|
57 | 57 | |
|
58 | 58 | Examples:: |
|
59 | 59 | >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') |
@@ -72,7 +72,7 b' class _ToolTip(object):' | |||
|
72 | 72 | """ |
|
73 | 73 | Special function just to wrap our text into nice formatted autowrapped |
|
74 | 74 | text |
|
75 |
|
|
|
75 | :param tooltip_title: | |
|
76 | 76 | """ |
|
77 | 77 | |
|
78 | 78 | return wrap_paragraphs(escape(tooltip_title), trim_at)\ |
@@ -226,7 +226,7 b' class CodeHtmlFormatter(HtmlFormatter):' | |||
|
226 | 226 | def pygmentize(filenode, **kwargs): |
|
227 | 227 | """ |
|
228 | 228 | pygmentize function using pygments |
|
229 |
|
|
|
229 | :param filenode: | |
|
230 | 230 | """ |
|
231 | 231 | return literal(code_highlight(filenode.content, |
|
232 | 232 | filenode.lexer, CodeHtmlFormatter(**kwargs))) |
@@ -234,7 +234,7 b' def pygmentize(filenode, **kwargs):' | |||
|
234 | 234 | def pygmentize_annotation(filenode, **kwargs): |
|
235 | 235 | """ |
|
236 | 236 | pygmentize function for annotation |
|
237 |
|
|
|
237 | :param filenode: | |
|
238 | 238 | """ |
|
239 | 239 | |
|
240 | 240 | color_dict = {} |
@@ -53,9 +53,9 b' def repo_size(ui, repo, hooktype=None, *' | |||
|
53 | 53 | def user_action_mapper(ui, repo, hooktype=None, **kwargs): |
|
54 | 54 | """ |
|
55 | 55 | Maps user last push action to new changeset id, from mercurial |
|
56 |
|
|
|
57 |
|
|
|
58 |
|
|
|
56 | :param ui: | |
|
57 | :param repo: | |
|
58 | :param hooktype: | |
|
59 | 59 | """ |
|
60 | 60 | |
|
61 | 61 | try: |
@@ -115,8 +115,8 b' class ResultWrapper(object):' | |||
|
115 | 115 | Smart function that implements chunking the content |
|
116 | 116 | but not overlap chunks so it doesn't highlight the same |
|
117 | 117 | close occurrences twice. |
|
118 |
|
|
|
119 |
|
|
|
118 | :param matcher: | |
|
119 | :param size: | |
|
120 | 120 | """ |
|
121 | 121 | memory = [(0, 0)] |
|
122 | 122 | for span in self.matcher.spans(): |
@@ -109,8 +109,8 b' class DaemonLock(object):' | |||
|
109 | 109 | def makelock(self, lockname, pidfile): |
|
110 | 110 | """ |
|
111 | 111 | this function will make an actual lock |
|
112 |
|
|
|
113 |
|
|
|
112 | :param lockname: acctual pid of file | |
|
113 | :param pidfile: the file to write the pid in | |
|
114 | 114 | """ |
|
115 | 115 | if self.debug: |
|
116 | 116 | print 'creating a file %s and pid: %s' % (pidfile, lockname) |
@@ -108,7 +108,7 b' class SmtpMailer(object):' | |||
|
108 | 108 | ''' |
|
109 | 109 | Get content based on type, if content is a string do open first |
|
110 | 110 | else just read because it's a probably open file object |
|
111 |
|
|
|
111 | :param msg_file: | |
|
112 | 112 | ''' |
|
113 | 113 | if isinstance(msg_file, str): |
|
114 | 114 | return open(msg_file, "rb").read() |
@@ -36,7 +36,7 b' import os' | |||
|
36 | 36 | log = logging.getLogger(__name__) |
|
37 | 37 | |
|
38 | 38 | |
|
39 |
def get_repo_slug(request): |
|
|
39 | def get_repo_slug(request): | |
|
40 | 40 | return request.environ['pylons.routes_dict'].get('repo_name') |
|
41 | 41 | |
|
42 | 42 | def is_mercurial(environ): |
@@ -49,14 +49,26 b' def is_mercurial(environ):' | |||
|
49 | 49 | return True |
|
50 | 50 | return False |
|
51 | 51 | |
|
52 | def is_git(environ): | |
|
53 | """ | |
|
54 | Returns True if request's target is git server. ``HTTP_USER_AGENT`` would | |
|
55 | then have git client version given. | |
|
56 | ||
|
57 | :param environ: | |
|
58 | """ | |
|
59 | http_user_agent = environ.get('HTTP_USER_AGENT') | |
|
60 | if http_user_agent.startswith('git'): | |
|
61 | return True | |
|
62 | return False | |
|
63 | ||
|
52 | 64 | def action_logger(user, action, repo, ipaddr, sa=None): |
|
53 | 65 | """ |
|
54 | 66 | Action logger for various action made by users |
|
55 | 67 | """ |
|
56 | ||
|
68 | ||
|
57 | 69 | if not sa: |
|
58 |
sa = meta.Session |
|
|
59 | ||
|
70 | sa = meta.Session | |
|
71 | ||
|
60 | 72 | try: |
|
61 | 73 | if hasattr(user, 'user_id'): |
|
62 | 74 | user_id = user.user_id |
@@ -64,7 +76,7 b' def action_logger(user, action, repo, ip' | |||
|
64 | 76 | user_id = sa.query(User).filter(User.username == user).one() |
|
65 | 77 | else: |
|
66 | 78 | raise Exception('You have to provide user object or username') |
|
67 | ||
|
79 | ||
|
68 | 80 | repo_name = repo.lstrip('/') |
|
69 | 81 | user_log = UserLog() |
|
70 | 82 | user_log.user_id = user_id |
@@ -82,7 +94,7 b' def action_logger(user, action, repo, ip' | |||
|
82 | 94 | raise |
|
83 | 95 | sa.rollback() |
|
84 | 96 | log.error('could not log user action:%s', str(e)) |
|
85 | ||
|
97 | ||
|
86 | 98 | def check_repo_dir(paths): |
|
87 | 99 | repos_path = paths[0][1].split('/') |
|
88 | 100 | if repos_path[-1] in ['*', '**']: |
@@ -122,7 +134,7 b' def ask_ok(prompt, retries=4, complaint=' | |||
|
122 | 134 | retries = retries - 1 |
|
123 | 135 | if retries < 0: raise IOError |
|
124 | 136 | print complaint |
|
125 | ||
|
137 | ||
|
126 | 138 | @cache_region('super_short_term', 'cached_hg_ui') |
|
127 | 139 | def get_hg_ui_cached(): |
|
128 | 140 | try: |
@@ -139,13 +151,13 b' def get_hg_settings():' | |||
|
139 | 151 | ret = sa.query(RhodeCodeSettings).all() |
|
140 | 152 | finally: |
|
141 | 153 | meta.Session.remove() |
|
142 | ||
|
154 | ||
|
143 | 155 | if not ret: |
|
144 | 156 | raise Exception('Could not get application settings !') |
|
145 | 157 | settings = {} |
|
146 | 158 | for each in ret: |
|
147 |
settings['rhodecode_' + each.app_settings_name] = each.app_settings_value |
|
|
148 | ||
|
159 | settings['rhodecode_' + each.app_settings_name] = each.app_settings_value | |
|
160 | ||
|
149 | 161 | return settings |
|
150 | 162 | |
|
151 | 163 | def get_hg_ui_settings(): |
@@ -154,7 +166,7 b' def get_hg_ui_settings():' | |||
|
154 | 166 | ret = sa.query(RhodeCodeUi).all() |
|
155 | 167 | finally: |
|
156 | 168 | meta.Session.remove() |
|
157 | ||
|
169 | ||
|
158 | 170 | if not ret: |
|
159 | 171 | raise Exception('Could not get application ui settings !') |
|
160 | 172 | settings = {} |
@@ -163,15 +175,15 b' def get_hg_ui_settings():' | |||
|
163 | 175 | v = each.ui_value |
|
164 | 176 | if k == '/': |
|
165 | 177 | k = 'root_path' |
|
166 | ||
|
178 | ||
|
167 | 179 | if k.find('.') != -1: |
|
168 | 180 | k = k.replace('.', '_') |
|
169 | ||
|
181 | ||
|
170 | 182 | if each.ui_section == 'hooks': |
|
171 | 183 | v = each.ui_active |
|
172 | ||
|
173 |
settings[each.ui_section + '_' + k] = v |
|
|
174 | ||
|
184 | ||
|
185 | settings[each.ui_section + '_' + k] = v | |
|
186 | ||
|
175 | 187 | return settings |
|
176 | 188 | |
|
177 | 189 | #propagated from mercurial documentation |
@@ -185,15 +197,15 b" ui_sections = ['alias', 'auth'," | |||
|
185 | 197 | 'paths', 'profiling', |
|
186 | 198 | 'server', 'trusted', |
|
187 | 199 | 'ui', 'web', ] |
|
188 | ||
|
189 |
def make_ui(read_from='file', path=None, checkpaths=True): |
|
|
200 | ||
|
201 | def make_ui(read_from='file', path=None, checkpaths=True): | |
|
190 | 202 | """ |
|
191 | 203 | A function that will read python rc files or database |
|
192 | 204 | and make an mercurial ui object from read options |
|
193 | 205 | |
|
194 |
|
|
|
195 |
|
|
|
196 |
|
|
|
206 | :param path: path to mercurial config file | |
|
207 | :param checkpaths: check the path | |
|
208 | :param read_from: read from 'file' or 'db' | |
|
197 | 209 | """ |
|
198 | 210 | |
|
199 | 211 | baseui = ui.ui() |
@@ -209,52 +221,52 b" def make_ui(read_from='file', path=None," | |||
|
209 | 221 | for k, v in cfg.items(section): |
|
210 | 222 | baseui.setconfig(section, k, v) |
|
211 | 223 | log.debug('settings ui from file[%s]%s:%s', section, k, v) |
|
212 |
if checkpaths:check_repo_dir(cfg.items('paths')) |
|
|
213 | ||
|
214 | ||
|
224 | if checkpaths:check_repo_dir(cfg.items('paths')) | |
|
225 | ||
|
226 | ||
|
215 | 227 | elif read_from == 'db': |
|
216 | 228 | hg_ui = get_hg_ui_cached() |
|
217 | 229 | for ui_ in hg_ui: |
|
218 | 230 | if ui_.ui_active: |
|
219 | 231 | log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value) |
|
220 | 232 | baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) |
|
221 | ||
|
222 | ||
|
233 | ||
|
234 | ||
|
223 | 235 | return baseui |
|
224 | 236 | |
|
225 | 237 | |
|
226 | 238 | def set_rhodecode_config(config): |
|
227 | 239 | hgsettings = get_hg_settings() |
|
228 | ||
|
240 | ||
|
229 | 241 | for k, v in hgsettings.items(): |
|
230 | 242 | config[k] = v |
|
231 | 243 | |
|
232 | 244 | def invalidate_cache(name, *args): |
|
233 | 245 | """Invalidates given name cache""" |
|
234 | ||
|
246 | ||
|
235 | 247 | from beaker.cache import region_invalidate |
|
236 | 248 | log.info('INVALIDATING CACHE FOR %s', name) |
|
237 | ||
|
249 | ||
|
238 | 250 | """propagate our arguments to make sure invalidation works. First |
|
239 | 251 | argument has to be the name of cached func name give to cache decorator |
|
240 | 252 | without that the invalidation would not work""" |
|
241 | 253 | tmp = [name] |
|
242 | 254 | tmp.extend(args) |
|
243 | 255 | args = tuple(tmp) |
|
244 | ||
|
256 | ||
|
245 | 257 | if name == 'cached_repo_list': |
|
246 | 258 | from rhodecode.model.hg_model import _get_repos_cached |
|
247 | 259 | region_invalidate(_get_repos_cached, None, *args) |
|
248 | ||
|
260 | ||
|
249 | 261 | if name == 'full_changelog': |
|
250 | 262 | from rhodecode.model.hg_model import _full_changelog_cached |
|
251 | 263 | region_invalidate(_full_changelog_cached, None, *args) |
|
252 | ||
|
264 | ||
|
253 | 265 | class EmptyChangeset(BaseChangeset): |
|
254 | 266 | """ |
|
255 | 267 | An dummy empty changeset. |
|
256 | 268 | """ |
|
257 | ||
|
269 | ||
|
258 | 270 | revision = -1 |
|
259 | 271 | message = '' |
|
260 | 272 | author = '' |
@@ -266,35 +278,35 b' class EmptyChangeset(BaseChangeset):' | |||
|
266 | 278 | representation. |
|
267 | 279 | """ |
|
268 | 280 | return '0' * 40 |
|
269 | ||
|
281 | ||
|
270 | 282 | @LazyProperty |
|
271 | 283 | def short_id(self): |
|
272 | 284 | return self.raw_id[:12] |
|
273 | 285 | |
|
274 | 286 | def get_file_changeset(self, path): |
|
275 | 287 | return self |
|
276 | ||
|
288 | ||
|
277 | 289 | def get_file_content(self, path): |
|
278 | 290 | return u'' |
|
279 | ||
|
291 | ||
|
280 | 292 | def get_file_size(self, path): |
|
281 | 293 | return 0 |
|
282 | ||
|
294 | ||
|
283 | 295 | def repo2db_mapper(initial_repo_list, remove_obsolete=False): |
|
284 | 296 | """ |
|
285 | 297 | maps all found repositories into db |
|
286 | 298 | """ |
|
287 | 299 | from rhodecode.model.repo_model import RepoModel |
|
288 | ||
|
300 | ||
|
289 | 301 | sa = meta.Session |
|
290 | 302 | user = sa.query(User).filter(User.admin == True).first() |
|
291 | ||
|
303 | ||
|
292 | 304 | rm = RepoModel() |
|
293 | ||
|
305 | ||
|
294 | 306 | for name, repo in initial_repo_list.items(): |
|
295 | 307 | if not sa.query(Repository).filter(Repository.repo_name == name).scalar(): |
|
296 | 308 | log.info('repository %s not found creating default', name) |
|
297 | ||
|
309 | ||
|
298 | 310 | form_data = { |
|
299 | 311 | 'repo_name':name, |
|
300 | 312 | 'description':repo.description if repo.description != 'unknown' else \ |
@@ -311,7 +323,7 b' def repo2db_mapper(initial_repo_list, re' | |||
|
311 | 323 | sa.delete(repo) |
|
312 | 324 | sa.commit() |
|
313 | 325 | |
|
314 | ||
|
326 | ||
|
315 | 327 | meta.Session.remove() |
|
316 | 328 | |
|
317 | 329 | from UserDict import DictMixin |
@@ -421,25 +433,25 b' class OrderedDict(dict, DictMixin):' | |||
|
421 | 433 | #=============================================================================== |
|
422 | 434 | def create_test_index(repo_location, full_index): |
|
423 | 435 | """Makes default test index |
|
424 |
|
|
|
425 |
|
|
|
436 | :param repo_location: | |
|
437 | :param full_index: | |
|
426 | 438 | """ |
|
427 | 439 | from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon |
|
428 | 440 | from rhodecode.lib.pidlock import DaemonLock, LockHeld |
|
429 | 441 | from rhodecode.lib.indexers import IDX_LOCATION |
|
430 | 442 | import shutil |
|
431 | ||
|
443 | ||
|
432 | 444 | if os.path.exists(IDX_LOCATION): |
|
433 | 445 | shutil.rmtree(IDX_LOCATION) |
|
434 | ||
|
446 | ||
|
435 | 447 | try: |
|
436 | 448 | l = DaemonLock() |
|
437 | 449 | WhooshIndexingDaemon(repo_location=repo_location)\ |
|
438 | 450 | .run(full_index=full_index) |
|
439 | 451 | l.release() |
|
440 | 452 | except LockHeld: |
|
441 |
pass |
|
|
442 | ||
|
453 | pass | |
|
454 | ||
|
443 | 455 | def create_test_env(repos_test_path, config): |
|
444 | 456 | """Makes a fresh database and |
|
445 | 457 | install test repository into tmp dir |
@@ -448,7 +460,7 b' def create_test_env(repos_test_path, con' | |||
|
448 | 460 | import tarfile |
|
449 | 461 | import shutil |
|
450 | 462 | from os.path import dirname as dn, join as jn, abspath |
|
451 | ||
|
463 | ||
|
452 | 464 | log = logging.getLogger('TestEnvCreator') |
|
453 | 465 | # create logger |
|
454 | 466 | log.setLevel(logging.DEBUG) |
@@ -456,20 +468,20 b' def create_test_env(repos_test_path, con' | |||
|
456 | 468 | # create console handler and set level to debug |
|
457 | 469 | ch = logging.StreamHandler() |
|
458 | 470 | ch.setLevel(logging.DEBUG) |
|
459 | ||
|
471 | ||
|
460 | 472 | # create formatter |
|
461 | 473 | formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") |
|
462 | ||
|
474 | ||
|
463 | 475 | # add formatter to ch |
|
464 | 476 | ch.setFormatter(formatter) |
|
465 | ||
|
477 | ||
|
466 | 478 | # add ch to logger |
|
467 | 479 | log.addHandler(ch) |
|
468 | ||
|
480 | ||
|
469 | 481 | #PART ONE create db |
|
470 | 482 | dbname = config['sqlalchemy.db1.url'].split('/')[-1] |
|
471 | 483 | log.debug('making test db %s', dbname) |
|
472 | ||
|
484 | ||
|
473 | 485 | dbmanage = DbManage(log_sql=True, dbname=dbname, root=config['here'], |
|
474 | 486 | tests=True) |
|
475 | 487 | dbmanage.create_tables(override=True) |
@@ -478,12 +490,12 b' def create_test_env(repos_test_path, con' | |||
|
478 | 490 | dbmanage.admin_prompt() |
|
479 | 491 | dbmanage.create_permissions() |
|
480 | 492 | dbmanage.populate_default_permissions() |
|
481 | ||
|
493 | ||
|
482 | 494 | #PART TWO make test repo |
|
483 | 495 | log.debug('making test vcs repo') |
|
484 | 496 | if os.path.isdir('/tmp/vcs_test'): |
|
485 | 497 | shutil.rmtree('/tmp/vcs_test') |
|
486 | ||
|
498 | ||
|
487 | 499 | cur_dir = dn(dn(abspath(__file__))) |
|
488 | 500 | tar = tarfile.open(jn(cur_dir, 'tests', "vcs_test.tar.gz")) |
|
489 | 501 | tar.extractall('/tmp') |
General Comments 0
You need to be logged in to leave comments.
Login now