Mercurial > public > src > rhodecode
annotate pylons_app/lib/utils.py @ 310:a074dec6ee40
restored utils, wrongly deleted
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 25 Jun 2010 21:53:13 +0200 |
parents | 248642ed1912 |
children | 752675cdd167 |
rev | line source |
---|---|
310
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
1 #!/usr/bin/env python |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
2 # encoding: utf-8 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
3 # Utilities for hg app |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
5 # This program is free software; you can redistribute it and/or |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
6 # modify it under the terms of the GNU General Public License |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
7 # as published by the Free Software Foundation; version 2 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
8 # of the License or (at your opinion) any later version of the license. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
9 # |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
10 # This program is distributed in the hope that it will be useful, |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
13 # GNU General Public License for more details. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
14 # |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
15 # You should have received a copy of the GNU General Public License |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
16 # along with this program; if not, write to the Free Software |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
18 # MA 02110-1301, USA. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
19 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
20 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
21 Created on April 18, 2010 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
22 Utilities for hg app |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
23 @author: marcink |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
24 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
25 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
26 import os |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
27 import logging |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
28 from mercurial import ui, config, hg |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
29 from mercurial.error import RepoError |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
30 from pylons_app.model.db import Repository, User |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
31 log = logging.getLogger(__name__) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
32 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
33 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
34 def get_repo_slug(request): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
35 return request.environ['pylons.routes_dict'].get('repo_name') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
36 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
37 def is_mercurial(environ): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
38 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
39 Returns True if request's target is mercurial server - header |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
40 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
41 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
42 http_accept = environ.get('HTTP_ACCEPT') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
43 if http_accept and http_accept.startswith('application/mercurial'): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
44 return True |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
45 return False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
46 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
47 def check_repo_dir(paths): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
48 repos_path = paths[0][1].split('/') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
49 if repos_path[-1] in ['*', '**']: |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
50 repos_path = repos_path[:-1] |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
51 if repos_path[0] != '/': |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
52 repos_path[0] = '/' |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
53 if not os.path.isdir(os.path.join(*repos_path)): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
54 raise Exception('Not a valid repository in %s' % paths[0][1]) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
55 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
56 def check_repo(repo_name, base_path): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
57 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
58 repo_path = os.path.join(base_path, repo_name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
59 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
60 try: |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
61 r = hg.repository(ui.ui(), repo_path) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
62 hg.verify(r) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
63 #here we hnow that repo exists it was verified |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
64 log.info('%s repo is already created', repo_name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
65 return False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
66 #raise Exception('Repo exists') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
67 except RepoError: |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
68 log.info('%s repo is free for creation', repo_name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
69 #it means that there is no valid repo there... |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
70 return True |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
71 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
72 def make_ui(path=None, checkpaths=True): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
73 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
74 A funcion that will read python rc files and make an ui from read options |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
75 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
76 @param path: path to mercurial config file |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
77 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
78 if not path: |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
79 log.error('repos config path is empty !') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
80 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
81 if not os.path.isfile(path): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
82 log.warning('Unable to read config file %s' % path) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
83 return False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
84 #propagated from mercurial documentation |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
85 sections = [ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
86 'alias', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
87 'auth', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
88 'decode/encode', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
89 'defaults', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
90 'diff', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
91 'email', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
92 'extensions', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
93 'format', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
94 'merge-patterns', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
95 'merge-tools', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
96 'hooks', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
97 'http_proxy', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
98 'smtp', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
99 'patch', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
100 'paths', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
101 'profiling', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
102 'server', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
103 'trusted', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
104 'ui', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
105 'web', |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
106 ] |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
107 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
108 baseui = ui.ui() |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
109 cfg = config.config() |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
110 cfg.read(path) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
111 if checkpaths:check_repo_dir(cfg.items('paths')) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
112 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
113 for section in sections: |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
114 for k, v in cfg.items(section): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
115 baseui.setconfig(section, k, v) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
116 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
117 return baseui |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
118 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
119 def invalidate_cache(name, *args): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
120 """Invalidates given name cache""" |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
121 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
122 from beaker.cache import region_invalidate |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
123 log.info('INVALIDATING CACHE FOR %s', name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
124 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
125 """propagate our arguments to make sure invalidation works. First |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
126 argument has to be the name of cached func name give to cache decorator |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
127 without that the invalidation would not work""" |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
128 tmp = [name] |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
129 tmp.extend(args) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
130 args = tuple(tmp) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
131 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
132 if name == 'cached_repo_list': |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
133 from pylons_app.model.hg_model import _get_repos_cached |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
134 region_invalidate(_get_repos_cached, None, *args) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
135 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
136 if name == 'full_changelog': |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
137 from pylons_app.model.hg_model import _full_changelog_cached |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
138 region_invalidate(_full_changelog_cached, None, *args) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
139 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
140 from vcs.backends.base import BaseChangeset |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
141 from vcs.utils.lazy import LazyProperty |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
142 class EmptyChangeset(BaseChangeset): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
143 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
144 revision = -1 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
145 message = '' |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
146 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
147 @LazyProperty |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
148 def raw_id(self): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
149 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
150 Returns raw string identifing this changeset, useful for web |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
151 representation. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
152 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
153 return '0' * 12 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
154 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
155 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
156 def repo2db_mapper(initial_repo_list): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
157 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
158 maps all found repositories into db |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
159 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
160 from pylons_app.model.meta import Session |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
161 from pylons_app.model.repo_model import RepoModel |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
162 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
163 sa = Session() |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
164 user = sa.query(User).filter(User.admin == True).first() |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
165 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
166 rm = RepoModel() |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
167 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
168 for name, repo in initial_repo_list.items(): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
169 if not sa.query(Repository).get(name): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
170 log.info('repository %s not found creating default', name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
171 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
172 form_data = { |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
173 'repo_name':name, |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
174 'description':repo.description if repo.description != 'unknown' else \ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
175 'auto description for %s' % name, |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
176 'private':False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
177 } |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
308
diff
changeset
|
178 rm.create(form_data, user, just_db=True) |