annotate pylons_app/lib/utils.py @ 265:0e5455fda8fd

Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
author Marcin Kuzminski <marcin@python-works.com>
date Mon, 07 Jun 2010 00:18:33 +0200
parents 3782a6d698af
children cd2ee462fc2c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
252
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
1 #!/usr/bin/env python
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
2 # encoding: utf-8
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
3 # Utilities for hg app
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
4 # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com>
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
5
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
6 # This program is free software; you can redistribute it and/or
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
7 # modify it under the terms of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
8 # as published by the Free Software Foundation; version 2
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
9 # of the License or (at your opinion) any later version of the license.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
10 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
11 # This program is distributed in the hope that it will be useful,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
14 # GNU General Public License for more details.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
15 #
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
16 # You should have received a copy of the GNU General Public License
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
17 # along with this program; if not, write to the Free Software
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
19 # MA 02110-1301, USA.
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
20
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
21 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
22 Created on April 18, 2010
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
23 Utilities for hg app
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
24 @author: marcink
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
25 """
3782a6d698af licensing updates, code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 248
diff changeset
26
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
27 import os
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
28 import logging
125
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
29 from mercurial import ui, config, hg
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
30 from mercurial.error import RepoError
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
31 from pylons_app.model.db import Repository, User
125
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
32 log = logging.getLogger(__name__)
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
33
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
34
82
670713507d03 Moved summary to seperate controller,
Marcin Kuzminski <marcin@python-blog.com>
parents:
diff changeset
35 def get_repo_slug(request):
248
fb7f066126cc Added support for repository located in subdirectories.
Marcin Kuzminski <marcin@python-works.com>
parents: 245
diff changeset
36 return request.environ['pylons.routes_dict'].get('repo_name')
96
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
37
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
38 def is_mercurial(environ):
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
39 """
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
40 Returns True if request's target is mercurial server - header
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
41 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
42 """
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
43 http_accept = environ.get('HTTP_ACCEPT')
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
44 if http_accept and http_accept.startswith('application/mercurial'):
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
45 return True
f24b9a2934cf added is mercurial method in utils,
Marcin Kuzminski <marcin@python-works.com>
parents: 93
diff changeset
46 return False
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
47
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
48 def check_repo_dir(paths):
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
49 repos_path = paths[0][1].split('/')
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
50 if repos_path[-1] in ['*', '**']:
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
51 repos_path = repos_path[:-1]
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
52 if repos_path[0] != '/':
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
53 repos_path[0] = '/'
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
54 if not os.path.isdir(os.path.join(*repos_path)):
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
55 raise Exception('Not a valid repository in %s' % paths[0][1])
125
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
56
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
57 def check_repo(repo_name, base_path):
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
58
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
59 repo_path = os.path.join(base_path, repo_name)
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
60
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
61 try:
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
62 r = hg.repository(ui.ui(), repo_path)
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
63 hg.verify(r)
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
64 #here we hnow that repo exists it was verified
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
65 log.info('%s repo is already created', repo_name)
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
66 return False
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
67 #raise Exception('Repo exists')
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
68 except RepoError:
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
69 log.info('%s repo is free for creation', repo_name)
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
70 #it means that there is no valid repo there...
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
71 return True
2811259dc12d Moved check_repo function to utils, error controller check for first name in url, for this repo and only prints 404 make repo template if repo does not exists, moded check repo from admin
Marcin Kuzminski <marcin@python-works.com>
parents: 114
diff changeset
72
241
48727add84c9 Made repos path config configurable from pylons app configs. update Readme
Marcin Kuzminski <marcin@python-works.com>
parents: 197
diff changeset
73 def make_ui(path=None, checkpaths=True):
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
74 """
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
75 A funcion that will read python rc files and make an ui from read options
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
76
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
77 @param path: path to mercurial config file
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
78 """
241
48727add84c9 Made repos path config configurable from pylons app configs. update Readme
Marcin Kuzminski <marcin@python-works.com>
parents: 197
diff changeset
79 if not path:
48727add84c9 Made repos path config configurable from pylons app configs. update Readme
Marcin Kuzminski <marcin@python-works.com>
parents: 197
diff changeset
80 log.error('repos config path is empty !')
48727add84c9 Made repos path config configurable from pylons app configs. update Readme
Marcin Kuzminski <marcin@python-works.com>
parents: 197
diff changeset
81
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
82 if not os.path.isfile(path):
193
50a39f923f31 Added file annotation template. Bumped version to 0.6.8. Changelog and changeset are now cleaned with js, it's still very beta.
Marcin Kuzminski <marcin@python-works.com>
parents: 171
diff changeset
83 log.warning('Unable to read config file %s' % path)
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
84 return False
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
85 #propagated from mercurial documentation
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
86 sections = [
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
87 'alias',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
88 'auth',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
89 'decode/encode',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
90 'defaults',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
91 'diff',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
92 'email',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
93 'extensions',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
94 'format',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
95 'merge-patterns',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
96 'merge-tools',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
97 'hooks',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
98 'http_proxy',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
99 'smtp',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
100 'patch',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
101 'paths',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
102 'profiling',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
103 'server',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
104 'trusted',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
105 'ui',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
106 'web',
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
107 ]
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
108
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
109 baseui = ui.ui()
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
110 cfg = config.config()
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
111 cfg.read(path)
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
112 if checkpaths:check_repo_dir(cfg.items('paths'))
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
113
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
114 for section in sections:
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
115 for k, v in cfg.items(section):
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
116 baseui.setconfig(section, k, v)
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
117
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
118 return baseui
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
119
171
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
120 def invalidate_cache(name, *args):
194
3d1dd13887f9 invalidate the repo list also for online changes. Small fixes in LoginRequired decorator.
Marcin Kuzminski <marcin@python-works.com>
parents: 193
diff changeset
121 """Invalidates given name cache"""
3d1dd13887f9 invalidate the repo list also for online changes. Small fixes in LoginRequired decorator.
Marcin Kuzminski <marcin@python-works.com>
parents: 193
diff changeset
122
140
b5e59e2b5cfe moved cache invalidating to utils, as seperate function. Implemented invalidating in
Marcin Kuzminski <marcin@python-works.com>
parents: 136
diff changeset
123 from beaker.cache import region_invalidate
171
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
124 log.info('INVALIDATING CACHE FOR %s', name)
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
125
194
3d1dd13887f9 invalidate the repo list also for online changes. Small fixes in LoginRequired decorator.
Marcin Kuzminski <marcin@python-works.com>
parents: 193
diff changeset
126 """propagate our arguments to make sure invalidation works. First
171
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
127 argument has to be the name of cached func name give to cache decorator
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
128 without that the invalidation would not work"""
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
129 tmp = [name]
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
130 tmp.extend(args)
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
131 args = tuple(tmp)
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
132
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
133 if name == 'cached_repo_list':
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 241
diff changeset
134 from pylons_app.model.hg_model import _get_repos_cached
171
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
135 region_invalidate(_get_repos_cached, None, *args)
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
136
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
137 if name == 'full_changelog':
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 241
diff changeset
138 from pylons_app.model.hg_model import _full_changelog_cached
171
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
139 region_invalidate(_full_changelog_cached, None, *args)
52bbeb1e813f Added universal cache invalidator for two cached functions.
Marcin Kuzminski <marcin@python-works.com>
parents: 140
diff changeset
140
136
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
141 from vcs.backends.base import BaseChangeset
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
142 from vcs.utils.lazy import LazyProperty
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
143 class EmptyChangeset(BaseChangeset):
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
144
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
145 revision = -1
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
146
136
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
147 @LazyProperty
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
148 def raw_id(self):
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
149 """
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
150 Returns raw string identifing this changeset, useful for web
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
151 representation.
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
152 """
36102488d634 Added empty changeset to use in newly created repository, and used this inside a hg model in repos list
Marcin Kuzminski <marcin@python-works.com>
parents: 125
diff changeset
153 return '0' * 12
114
cc5cf1a93902 Implemented simplehg middleware,moved make_ui functions to lib.utils
Marcin Kuzminski <marcin@python-works.com>
parents: 96
diff changeset
154
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 241
diff changeset
155
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
156 def repo2db_mapper(initial_repo_list):
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
157 """
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
158 maps all found repositories into db
245
a83a1799480c Reimplemented way of caching repos list, hg model now get's repos objects right from cached dict, this way we skipp creating instances of MercurialRepository and gain performance. Some import cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 241
diff changeset
159 """
265
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
160 from pylons_app.model.meta import Session
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
161 sa = Session()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
162 user = sa.query(User).filter(User.admin == True).first()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
163 for name, repo in initial_repo_list.items():
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
164 if not sa.query(Repository).get(name):
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
165 log.info('%s not found creating default', name)
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
166 try:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
167
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
168 new_repo = Repository()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
169 new_repo.repo_name = name
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
170 desc = repo.description if repo.description != 'unknown' else \
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
171 'auto description for %s' % name
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
172 new_repo.description = desc
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
173 new_repo.user_id = user.user_id
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
174 new_repo.private = False
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
175 sa.add(new_repo)
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
176 sa.commit()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
177 except:
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
178 sa.rollback()
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
179 raise
0e5455fda8fd Implemented basic repository managment. Implemented repo2db mappings, model, helpers updates and code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 252
diff changeset
180