Show More
@@ -1,118 +1,118 b'' | |||||
1 | """Routes configuration |
|
1 | """Routes configuration | |
2 |
|
2 | |||
3 | The more specific and detailed routes should be defined first so they |
|
3 | The more specific and detailed routes should be defined first so they | |
4 | may take precedent over the more generic routes. For more information |
|
4 | may take precedent over the more generic routes. For more information | |
5 | refer to the routes manual at http://routes.groovie.org/docs/ |
|
5 | refer to the routes manual at http://routes.groovie.org/docs/ | |
6 | """ |
|
6 | """ | |
7 | from routes import Mapper |
|
7 | from routes import Mapper | |
8 | from pylons_app.lib.utils import check_repo as cr |
|
8 | from pylons_app.lib.utils import check_repo_fast as cr | |
9 |
|
9 | |||
10 | def make_map(config): |
|
10 | def make_map(config): | |
11 | """Create, configure and return the routes Mapper""" |
|
11 | """Create, configure and return the routes Mapper""" | |
12 | map = Mapper(directory=config['pylons.paths']['controllers'], |
|
12 | map = Mapper(directory=config['pylons.paths']['controllers'], | |
13 | always_scan=config['debug']) |
|
13 | always_scan=config['debug']) | |
14 | map.minimization = False |
|
14 | map.minimization = False | |
15 | map.explicit = False |
|
15 | map.explicit = False | |
16 |
|
16 | |||
17 | # The ErrorController route (handles 404/500 error pages); it should |
|
17 | # The ErrorController route (handles 404/500 error pages); it should | |
18 | # likely stay at the top, ensuring it can always be resolved |
|
18 | # likely stay at the top, ensuring it can always be resolved | |
19 | map.connect('/error/{action}', controller='error') |
|
19 | map.connect('/error/{action}', controller='error') | |
20 | map.connect('/error/{action}/{id}', controller='error') |
|
20 | map.connect('/error/{action}/{id}', controller='error') | |
21 |
|
21 | |||
22 | # CUSTOM ROUTES HERE |
|
22 | # CUSTOM ROUTES HERE | |
23 | map.connect('hg_home', '/', controller='hg', action='index') |
|
23 | map.connect('hg_home', '/', controller='hg', action='index') | |
24 |
|
24 | |||
25 | def check_repo(environ, match_dict): |
|
25 | def check_repo(environ, match_dict): | |
26 | """ |
|
26 | """ | |
27 | check for valid repository for proper 404 handling |
|
27 | check for valid repository for proper 404 handling | |
28 | @param environ: |
|
28 | @param environ: | |
29 | @param match_dict: |
|
29 | @param match_dict: | |
30 | """ |
|
30 | """ | |
31 | repo_name = match_dict.get('repo_name') |
|
31 | repo_name = match_dict.get('repo_name') | |
32 | return not cr(repo_name, config['base_path']) |
|
32 | return not cr(repo_name, config['base_path']) | |
33 |
|
33 | |||
34 | #REST routes |
|
34 | #REST routes | |
35 | with map.submapper(path_prefix='/_admin', controller='repos') as m: |
|
35 | with map.submapper(path_prefix='/_admin', controller='repos') as m: | |
36 | m.connect("repos", "/repos", |
|
36 | m.connect("repos", "/repos", | |
37 | action="create", conditions=dict(method=["POST"])) |
|
37 | action="create", conditions=dict(method=["POST"])) | |
38 | m.connect("repos", "/repos", |
|
38 | m.connect("repos", "/repos", | |
39 | action="index", conditions=dict(method=["GET"])) |
|
39 | action="index", conditions=dict(method=["GET"])) | |
40 | m.connect("formatted_repos", "/repos.{format}", |
|
40 | m.connect("formatted_repos", "/repos.{format}", | |
41 | action="index", |
|
41 | action="index", | |
42 | conditions=dict(method=["GET"])) |
|
42 | conditions=dict(method=["GET"])) | |
43 | m.connect("new_repo", "/repos/new", |
|
43 | m.connect("new_repo", "/repos/new", | |
44 | action="new", conditions=dict(method=["GET"])) |
|
44 | action="new", conditions=dict(method=["GET"])) | |
45 | m.connect("formatted_new_repo", "/repos/new.{format}", |
|
45 | m.connect("formatted_new_repo", "/repos/new.{format}", | |
46 | action="new", conditions=dict(method=["GET"])) |
|
46 | action="new", conditions=dict(method=["GET"])) | |
47 | m.connect("/repos/{repo_name:.*}", |
|
47 | m.connect("/repos/{repo_name:.*}", | |
48 | action="update", conditions=dict(method=["PUT"], |
|
48 | action="update", conditions=dict(method=["PUT"], | |
49 | function=check_repo)) |
|
49 | function=check_repo)) | |
50 | m.connect("/repos/{repo_name:.*}", |
|
50 | m.connect("/repos/{repo_name:.*}", | |
51 | action="delete", conditions=dict(method=["DELETE"], |
|
51 | action="delete", conditions=dict(method=["DELETE"], | |
52 | function=check_repo)) |
|
52 | function=check_repo)) | |
53 | m.connect("edit_repo", "/repos/{repo_name:.*}/edit", |
|
53 | m.connect("edit_repo", "/repos/{repo_name:.*}/edit", | |
54 | action="edit", conditions=dict(method=["GET"], |
|
54 | action="edit", conditions=dict(method=["GET"], | |
55 | function=check_repo)) |
|
55 | function=check_repo)) | |
56 | m.connect("formatted_edit_repo", "/repos/{repo_name:.*}.{format}/edit", |
|
56 | m.connect("formatted_edit_repo", "/repos/{repo_name:.*}.{format}/edit", | |
57 | action="edit", conditions=dict(method=["GET"], |
|
57 | action="edit", conditions=dict(method=["GET"], | |
58 | function=check_repo)) |
|
58 | function=check_repo)) | |
59 | m.connect("repo", "/repos/{repo_name:.*}", |
|
59 | m.connect("repo", "/repos/{repo_name:.*}", | |
60 | action="show", conditions=dict(method=["GET"], |
|
60 | action="show", conditions=dict(method=["GET"], | |
61 | function=check_repo)) |
|
61 | function=check_repo)) | |
62 | m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", |
|
62 | m.connect("formatted_repo", "/repos/{repo_name:.*}.{format}", | |
63 | action="show", conditions=dict(method=["GET"], |
|
63 | action="show", conditions=dict(method=["GET"], | |
64 | function=check_repo)) |
|
64 | function=check_repo)) | |
65 | #ajax delete repo perm user |
|
65 | #ajax delete repo perm user | |
66 | m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", |
|
66 | m.connect('delete_repo_user', "/repos_delete_user/{repo_name:.*}", | |
67 | action="delete_perm_user", conditions=dict(method=["DELETE"], |
|
67 | action="delete_perm_user", conditions=dict(method=["DELETE"], | |
68 | function=check_repo)) |
|
68 | function=check_repo)) | |
69 |
|
69 | |||
70 | map.resource('user', 'users', path_prefix='/_admin') |
|
70 | map.resource('user', 'users', path_prefix='/_admin') | |
71 | map.resource('permission', 'permissions', path_prefix='/_admin') |
|
71 | map.resource('permission', 'permissions', path_prefix='/_admin') | |
72 |
|
72 | |||
73 | #ADMIN |
|
73 | #ADMIN | |
74 | with map.submapper(path_prefix='/_admin', controller='admin') as m: |
|
74 | with map.submapper(path_prefix='/_admin', controller='admin') as m: | |
75 | m.connect('admin_home', '/', action='index')#main page |
|
75 | m.connect('admin_home', '/', action='index')#main page | |
76 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', |
|
76 | m.connect('admin_add_repo', '/add_repo/{new_repo:[a-z0-9\. _-]*}', | |
77 | action='add_repo') |
|
77 | action='add_repo') | |
78 |
|
78 | |||
79 | #FEEDS |
|
79 | #FEEDS | |
80 | map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', |
|
80 | map.connect('rss_feed_home', '/{repo_name:.*}/feed/rss', | |
81 | controller='feed', action='rss', |
|
81 | controller='feed', action='rss', | |
82 | conditions=dict(function=check_repo)) |
|
82 | conditions=dict(function=check_repo)) | |
83 | map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', |
|
83 | map.connect('atom_feed_home', '/{repo_name:.*}/feed/atom', | |
84 | controller='feed', action='atom', |
|
84 | controller='feed', action='atom', | |
85 | conditions=dict(function=check_repo)) |
|
85 | conditions=dict(function=check_repo)) | |
86 |
|
86 | |||
87 | map.connect('login_home', '/login', controller='login') |
|
87 | map.connect('login_home', '/login', controller='login') | |
88 | map.connect('logout_home', '/logout', controller='login', action='logout') |
|
88 | map.connect('logout_home', '/logout', controller='login', action='logout') | |
89 |
|
89 | |||
90 | map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', |
|
90 | map.connect('changeset_home', '/{repo_name:.*}/changeset/{revision}', | |
91 | controller='changeset', revision='tip', |
|
91 | controller='changeset', revision='tip', | |
92 | conditions=dict(function=check_repo)) |
|
92 | conditions=dict(function=check_repo)) | |
93 | map.connect('summary_home', '/{repo_name:.*}/summary', |
|
93 | map.connect('summary_home', '/{repo_name:.*}/summary', | |
94 | controller='summary', conditions=dict(function=check_repo)) |
|
94 | controller='summary', conditions=dict(function=check_repo)) | |
95 | map.connect('shortlog_home', '/{repo_name:.*}/shortlog', |
|
95 | map.connect('shortlog_home', '/{repo_name:.*}/shortlog', | |
96 | controller='shortlog', conditions=dict(function=check_repo)) |
|
96 | controller='shortlog', conditions=dict(function=check_repo)) | |
97 | map.connect('branches_home', '/{repo_name:.*}/branches', |
|
97 | map.connect('branches_home', '/{repo_name:.*}/branches', | |
98 | controller='branches', conditions=dict(function=check_repo)) |
|
98 | controller='branches', conditions=dict(function=check_repo)) | |
99 | map.connect('tags_home', '/{repo_name:.*}/tags', |
|
99 | map.connect('tags_home', '/{repo_name:.*}/tags', | |
100 | controller='tags', conditions=dict(function=check_repo)) |
|
100 | controller='tags', conditions=dict(function=check_repo)) | |
101 | map.connect('changelog_home', '/{repo_name:.*}/changelog', |
|
101 | map.connect('changelog_home', '/{repo_name:.*}/changelog', | |
102 | controller='changelog', conditions=dict(function=check_repo)) |
|
102 | controller='changelog', conditions=dict(function=check_repo)) | |
103 | map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', |
|
103 | map.connect('files_home', '/{repo_name:.*}/files/{revision}/{f_path:.*}', | |
104 | controller='files', revision='tip', f_path='', |
|
104 | controller='files', revision='tip', f_path='', | |
105 | conditions=dict(function=check_repo)) |
|
105 | conditions=dict(function=check_repo)) | |
106 | map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}', |
|
106 | map.connect('files_diff_home', '/{repo_name:.*}/diff/{f_path:.*}', | |
107 | controller='files', action='diff', revision='tip', f_path='', |
|
107 | controller='files', action='diff', revision='tip', f_path='', | |
108 | conditions=dict(function=check_repo)) |
|
108 | conditions=dict(function=check_repo)) | |
109 | map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}', |
|
109 | map.connect('files_raw_home', '/{repo_name:.*}/rawfile/{revision}/{f_path:.*}', | |
110 | controller='files', action='rawfile', revision='tip', f_path='', |
|
110 | controller='files', action='rawfile', revision='tip', f_path='', | |
111 | conditions=dict(function=check_repo)) |
|
111 | conditions=dict(function=check_repo)) | |
112 | map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', |
|
112 | map.connect('files_annotate_home', '/{repo_name:.*}/annotate/{revision}/{f_path:.*}', | |
113 | controller='files', action='annotate', revision='tip', f_path='', |
|
113 | controller='files', action='annotate', revision='tip', f_path='', | |
114 | conditions=dict(function=check_repo)) |
|
114 | conditions=dict(function=check_repo)) | |
115 | map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', |
|
115 | map.connect('files_archive_home', '/{repo_name:.*}/archive/{revision}/{fileformat}', | |
116 | controller='files', action='archivefile', revision='tip', |
|
116 | controller='files', action='archivefile', revision='tip', | |
117 | conditions=dict(function=check_repo)) |
|
117 | conditions=dict(function=check_repo)) | |
118 | return map |
|
118 | return map |
@@ -1,178 +1,184 b'' | |||||
1 | #!/usr/bin/env python |
|
1 | #!/usr/bin/env python | |
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # Utilities for hg app |
|
3 | # Utilities for hg app | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
5 | # This program is free software; you can redistribute it and/or |
|
5 | # This program is free software; you can redistribute it and/or | |
6 | # modify it under the terms of the GNU General Public License |
|
6 | # modify it under the terms of the GNU General Public License | |
7 | # as published by the Free Software Foundation; version 2 |
|
7 | # as published by the Free Software Foundation; version 2 | |
8 | # of the License or (at your opinion) any later version of the license. |
|
8 | # of the License or (at your opinion) any later version of the license. | |
9 | # |
|
9 | # | |
10 | # This program is distributed in the hope that it will be useful, |
|
10 | # This program is distributed in the hope that it will be useful, | |
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | # GNU General Public License for more details. |
|
13 | # GNU General Public License for more details. | |
14 | # |
|
14 | # | |
15 | # You should have received a copy of the GNU General Public License |
|
15 | # You should have received a copy of the GNU General Public License | |
16 | # along with this program; if not, write to the Free Software |
|
16 | # along with this program; if not, write to the Free Software | |
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|
17 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
18 | # MA 02110-1301, USA. |
|
18 | # MA 02110-1301, USA. | |
19 |
|
19 | |||
20 | """ |
|
20 | """ | |
21 | Created on April 18, 2010 |
|
21 | Created on April 18, 2010 | |
22 | Utilities for hg app |
|
22 | Utilities for hg app | |
23 | @author: marcink |
|
23 | @author: marcink | |
24 | """ |
|
24 | """ | |
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 | |
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') | |
36 |
|
36 | |||
37 | def is_mercurial(environ): |
|
37 | def is_mercurial(environ): | |
38 | """ |
|
38 | """ | |
39 | Returns True if request's target is mercurial server - header |
|
39 | Returns True if request's target is mercurial server - header | |
40 | ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. |
|
40 | ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. | |
41 | """ |
|
41 | """ | |
42 | http_accept = environ.get('HTTP_ACCEPT') |
|
42 | http_accept = environ.get('HTTP_ACCEPT') | |
43 | if http_accept and http_accept.startswith('application/mercurial'): |
|
43 | if http_accept and http_accept.startswith('application/mercurial'): | |
44 | return True |
|
44 | return True | |
45 | return False |
|
45 | return False | |
46 |
|
46 | |||
47 | def check_repo_dir(paths): |
|
47 | def check_repo_dir(paths): | |
48 | repos_path = paths[0][1].split('/') |
|
48 | repos_path = paths[0][1].split('/') | |
49 | if repos_path[-1] in ['*', '**']: |
|
49 | if repos_path[-1] in ['*', '**']: | |
50 | repos_path = repos_path[:-1] |
|
50 | repos_path = repos_path[:-1] | |
51 | if repos_path[0] != '/': |
|
51 | if repos_path[0] != '/': | |
52 | repos_path[0] = '/' |
|
52 | repos_path[0] = '/' | |
53 | if not os.path.isdir(os.path.join(*repos_path)): |
|
53 | if not os.path.isdir(os.path.join(*repos_path)): | |
54 | raise Exception('Not a valid repository in %s' % paths[0][1]) |
|
54 | raise Exception('Not a valid repository in %s' % paths[0][1]) | |
55 |
|
55 | |||
56 | def check_repo(repo_name, base_path): |
|
56 | def check_repo_fast(repo_name, base_path): | |
|
57 | if os.path.isdir(os.path.join(base_path, repo_name)):return False | |||
|
58 | return True | |||
|
59 | ||||
|
60 | def check_repo(repo_name, base_path, verify=True): | |||
57 |
|
61 | |||
58 | repo_path = os.path.join(base_path, repo_name) |
|
62 | repo_path = os.path.join(base_path, repo_name) | |
59 |
|
63 | |||
60 | try: |
|
64 | try: | |
|
65 | if not check_repo_fast(repo_name, base_path): | |||
|
66 | return False | |||
61 | r = hg.repository(ui.ui(), repo_path) |
|
67 | r = hg.repository(ui.ui(), repo_path) | |
62 |
|
|
68 | if verify: | |
|
69 | hg.verify(r) | |||
63 | #here we hnow that repo exists it was verified |
|
70 | #here we hnow that repo exists it was verified | |
64 | log.info('%s repo is already created', repo_name) |
|
71 | log.info('%s repo is already created', repo_name) | |
65 | return False |
|
72 | return False | |
66 | #raise Exception('Repo exists') |
|
|||
67 | except RepoError: |
|
73 | except RepoError: | |
|
74 | #it means that there is no valid repo there... | |||
68 | log.info('%s repo is free for creation', repo_name) |
|
75 | log.info('%s repo is free for creation', repo_name) | |
69 | #it means that there is no valid repo there... |
|
|||
70 | return True |
|
76 | return True | |
71 |
|
77 | |||
72 | def make_ui(path=None, checkpaths=True): |
|
78 | def make_ui(path=None, checkpaths=True): | |
73 | """ |
|
79 | """ | |
74 | A funcion that will read python rc files and make an ui from read options |
|
80 | A funcion that will read python rc files and make an ui from read options | |
75 |
|
81 | |||
76 | @param path: path to mercurial config file |
|
82 | @param path: path to mercurial config file | |
77 | """ |
|
83 | """ | |
78 | if not path: |
|
84 | if not path: | |
79 | log.error('repos config path is empty !') |
|
85 | log.error('repos config path is empty !') | |
80 |
|
86 | |||
81 | if not os.path.isfile(path): |
|
87 | if not os.path.isfile(path): | |
82 | log.warning('Unable to read config file %s' % path) |
|
88 | log.warning('Unable to read config file %s' % path) | |
83 | return False |
|
89 | return False | |
84 | #propagated from mercurial documentation |
|
90 | #propagated from mercurial documentation | |
85 | sections = [ |
|
91 | sections = [ | |
86 | 'alias', |
|
92 | 'alias', | |
87 | 'auth', |
|
93 | 'auth', | |
88 | 'decode/encode', |
|
94 | 'decode/encode', | |
89 | 'defaults', |
|
95 | 'defaults', | |
90 | 'diff', |
|
96 | 'diff', | |
91 | 'email', |
|
97 | 'email', | |
92 | 'extensions', |
|
98 | 'extensions', | |
93 | 'format', |
|
99 | 'format', | |
94 | 'merge-patterns', |
|
100 | 'merge-patterns', | |
95 | 'merge-tools', |
|
101 | 'merge-tools', | |
96 | 'hooks', |
|
102 | 'hooks', | |
97 | 'http_proxy', |
|
103 | 'http_proxy', | |
98 | 'smtp', |
|
104 | 'smtp', | |
99 | 'patch', |
|
105 | 'patch', | |
100 | 'paths', |
|
106 | 'paths', | |
101 | 'profiling', |
|
107 | 'profiling', | |
102 | 'server', |
|
108 | 'server', | |
103 | 'trusted', |
|
109 | 'trusted', | |
104 | 'ui', |
|
110 | 'ui', | |
105 | 'web', |
|
111 | 'web', | |
106 | ] |
|
112 | ] | |
107 |
|
113 | |||
108 | baseui = ui.ui() |
|
114 | baseui = ui.ui() | |
109 | cfg = config.config() |
|
115 | cfg = config.config() | |
110 | cfg.read(path) |
|
116 | cfg.read(path) | |
111 | if checkpaths:check_repo_dir(cfg.items('paths')) |
|
117 | if checkpaths:check_repo_dir(cfg.items('paths')) | |
112 |
|
118 | |||
113 | for section in sections: |
|
119 | for section in sections: | |
114 | for k, v in cfg.items(section): |
|
120 | for k, v in cfg.items(section): | |
115 | baseui.setconfig(section, k, v) |
|
121 | baseui.setconfig(section, k, v) | |
116 |
|
122 | |||
117 | return baseui |
|
123 | return baseui | |
118 |
|
124 | |||
119 | def invalidate_cache(name, *args): |
|
125 | def invalidate_cache(name, *args): | |
120 | """Invalidates given name cache""" |
|
126 | """Invalidates given name cache""" | |
121 |
|
127 | |||
122 | from beaker.cache import region_invalidate |
|
128 | from beaker.cache import region_invalidate | |
123 | log.info('INVALIDATING CACHE FOR %s', name) |
|
129 | log.info('INVALIDATING CACHE FOR %s', name) | |
124 |
|
130 | |||
125 | """propagate our arguments to make sure invalidation works. First |
|
131 | """propagate our arguments to make sure invalidation works. First | |
126 | argument has to be the name of cached func name give to cache decorator |
|
132 | argument has to be the name of cached func name give to cache decorator | |
127 | without that the invalidation would not work""" |
|
133 | without that the invalidation would not work""" | |
128 | tmp = [name] |
|
134 | tmp = [name] | |
129 | tmp.extend(args) |
|
135 | tmp.extend(args) | |
130 | args = tuple(tmp) |
|
136 | args = tuple(tmp) | |
131 |
|
137 | |||
132 | if name == 'cached_repo_list': |
|
138 | if name == 'cached_repo_list': | |
133 | from pylons_app.model.hg_model import _get_repos_cached |
|
139 | from pylons_app.model.hg_model import _get_repos_cached | |
134 | region_invalidate(_get_repos_cached, None, *args) |
|
140 | region_invalidate(_get_repos_cached, None, *args) | |
135 |
|
141 | |||
136 | if name == 'full_changelog': |
|
142 | if name == 'full_changelog': | |
137 | from pylons_app.model.hg_model import _full_changelog_cached |
|
143 | from pylons_app.model.hg_model import _full_changelog_cached | |
138 | region_invalidate(_full_changelog_cached, None, *args) |
|
144 | region_invalidate(_full_changelog_cached, None, *args) | |
139 |
|
145 | |||
140 | from vcs.backends.base import BaseChangeset |
|
146 | from vcs.backends.base import BaseChangeset | |
141 | from vcs.utils.lazy import LazyProperty |
|
147 | from vcs.utils.lazy import LazyProperty | |
142 | class EmptyChangeset(BaseChangeset): |
|
148 | class EmptyChangeset(BaseChangeset): | |
143 |
|
149 | |||
144 | revision = -1 |
|
150 | revision = -1 | |
145 | message = '' |
|
151 | message = '' | |
146 |
|
152 | |||
147 | @LazyProperty |
|
153 | @LazyProperty | |
148 | def raw_id(self): |
|
154 | def raw_id(self): | |
149 | """ |
|
155 | """ | |
150 | Returns raw string identifing this changeset, useful for web |
|
156 | Returns raw string identifing this changeset, useful for web | |
151 | representation. |
|
157 | representation. | |
152 | """ |
|
158 | """ | |
153 | return '0' * 12 |
|
159 | return '0' * 12 | |
154 |
|
160 | |||
155 |
|
161 | |||
156 | def repo2db_mapper(initial_repo_list): |
|
162 | def repo2db_mapper(initial_repo_list): | |
157 | """ |
|
163 | """ | |
158 | maps all found repositories into db |
|
164 | maps all found repositories into db | |
159 | """ |
|
165 | """ | |
160 | from pylons_app.model.meta import Session |
|
166 | from pylons_app.model.meta import Session | |
161 | from pylons_app.model.repo_model import RepoModel |
|
167 | from pylons_app.model.repo_model import RepoModel | |
162 |
|
168 | |||
163 | sa = Session() |
|
169 | sa = Session() | |
164 | user = sa.query(User).filter(User.admin == True).first() |
|
170 | user = sa.query(User).filter(User.admin == True).first() | |
165 |
|
171 | |||
166 | rm = RepoModel() |
|
172 | rm = RepoModel() | |
167 |
|
173 | |||
168 | for name, repo in initial_repo_list.items(): |
|
174 | for name, repo in initial_repo_list.items(): | |
169 | if not sa.query(Repository).get(name): |
|
175 | if not sa.query(Repository).get(name): | |
170 | log.info('repository %s not found creating default', name) |
|
176 | log.info('repository %s not found creating default', name) | |
171 |
|
177 | |||
172 | form_data = { |
|
178 | form_data = { | |
173 | 'repo_name':name, |
|
179 | 'repo_name':name, | |
174 | 'description':repo.description if repo.description != 'unknown' else \ |
|
180 | 'description':repo.description if repo.description != 'unknown' else \ | |
175 | 'auto description for %s' % name, |
|
181 | 'auto description for %s' % name, | |
176 | 'private':False |
|
182 | 'private':False | |
177 | } |
|
183 | } | |
178 | rm.create(form_data, user, just_db=True) |
|
184 | rm.create(form_data, user, just_db=True) |
General Comments 0
You need to be logged in to leave comments.
Login now