annotate pylons_app/lib/utils.py @ 348:e8fc875467bd

implemented manual repo rescann and remapping
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 14 Jul 2010 16:51:19 +0200
parents bb8f45f6d8f9
children 664a5b8c551a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
1 #!/usr/bin/env python
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
2 # encoding: utf-8
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
3 # Utilities for hg app
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
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: 295
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: 295
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: 295
diff changeset
7 # as published by the Free Software Foundation; version 2
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
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: 295
diff changeset
9 #
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
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: 295
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: 295
diff changeset
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
13 # GNU General Public License for more details.
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
14 #
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
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: 295
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: 295
diff changeset
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
18 # MA 02110-1301, USA.
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
19 from beaker.cache import cache_region
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
20
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
21 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
22 Created on April 18, 2010
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
23 Utilities for hg app
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
24 @author: marcink
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
25 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
26
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
27 import os
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
28 import logging
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
29 from mercurial import ui, config, hg
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
30 from mercurial.error import RepoError
345
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
31 from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
32 from pylons_app.model.meta import Session
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
33 log = logging.getLogger(__name__)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
34
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
35
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
36 def get_repo_slug(request):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
37 return request.environ['pylons.routes_dict'].get('repo_name')
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
38
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
39 def is_mercurial(environ):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
40 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
41 Returns True if request's target is mercurial server - header
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
42 ``HTTP_ACCEPT`` of such request would start with ``application/mercurial``.
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
43 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
44 http_accept = environ.get('HTTP_ACCEPT')
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
45 if http_accept and http_accept.startswith('application/mercurial'):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
46 return True
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
47 return False
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
48
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
49 def check_repo_dir(paths):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
50 repos_path = paths[0][1].split('/')
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
51 if repos_path[-1] in ['*', '**']:
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
52 repos_path = repos_path[:-1]
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
53 if repos_path[0] != '/':
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
54 repos_path[0] = '/'
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
55 if not os.path.isdir(os.path.join(*repos_path)):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
56 raise Exception('Not a valid repository in %s' % paths[0][1])
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
57
301
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
58 def check_repo_fast(repo_name, base_path):
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
59 if os.path.isdir(os.path.join(base_path, repo_name)):return False
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
60 return True
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
61
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
62 def check_repo(repo_name, base_path, verify=True):
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
63
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
64 repo_path = os.path.join(base_path, repo_name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
65
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
66 try:
301
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
67 if not check_repo_fast(repo_name, base_path):
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
68 return False
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
69 r = hg.repository(ui.ui(), repo_path)
301
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
70 if verify:
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
71 hg.verify(r)
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
72 #here we hnow that repo exists it was verified
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
73 log.info('%s repo is already created', repo_name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
74 return False
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
75 except RepoError:
301
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
76 #it means that there is no valid repo there...
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
77 log.info('%s repo is free for creation', repo_name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
78 return True
301
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 297
diff changeset
79
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
80
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
81 @cache_region('super_short_term', 'cached_hg_ui')
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
82 def get_hg_ui_cached():
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
83 sa = Session()
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
84 return sa.query(HgAppUi).all()
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
85
345
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
86 def get_hg_settings():
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
87 sa = Session()
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
88 ret = sa.query(HgAppSettings).scalar()
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
89 if not ret:
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
90 raise Exception('Could not get application settings !')
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
91 return ret
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
92
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
93 def make_ui(read_from='file', path=None, checkpaths=True):
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
94 """
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
95 A function that will read python rc files or database
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
96 and make an mercurial ui object from read options
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
97
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
98 @param path: path to mercurial config file
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
99 @param checkpaths: check the path
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
100 @param read_from: read from 'file' or 'db'
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
101 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
102 #propagated from mercurial documentation
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
103 sections = ['alias', 'auth',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
104 'decode/encode', 'defaults',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
105 'diff', 'email',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
106 'extensions', 'format',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
107 'merge-patterns', 'merge-tools',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
108 'hooks', 'http_proxy',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
109 'smtp', 'patch',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
110 'paths', 'profiling',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
111 'server', 'trusted',
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
112 'ui', 'web', ]
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
113 baseui = ui.ui()
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
114
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
115
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
116 if read_from == 'file':
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
117 if not os.path.isfile(path):
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
118 log.warning('Unable to read config file %s' % path)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
119 return False
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
120
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
121 cfg = config.config()
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
122 cfg.read(path)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
123 for section in sections:
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
124 for k, v in cfg.items(section):
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
125 baseui.setconfig(section, k, v)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
126 if checkpaths:check_repo_dir(cfg.items('paths'))
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
127
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
128
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
129 elif read_from == 'db':
343
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 341
diff changeset
130 hg_ui = get_hg_ui_cached()
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
131 for ui_ in hg_ui:
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
132 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
133
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
134
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
135 return baseui
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
136
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
137
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
138 def set_hg_app_config(config):
345
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
139 hgsettings = get_hg_settings()
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
140 config['hg_app_auth_realm'] = hgsettings.app_auth_realm
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 343
diff changeset
141 config['hg_app_name'] = hgsettings.app_title
341
1ef52a70f3b7 Made config file free configuration based on database and capable of beeing manage via application settings + some code cleanups
Marcin Kuzminski <marcin@python-works.com>
parents: 301
diff changeset
142
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
143 def invalidate_cache(name, *args):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
144 """Invalidates given name cache"""
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
145
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
146 from beaker.cache import region_invalidate
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
147 log.info('INVALIDATING CACHE FOR %s', name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
148
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
149 """propagate our arguments to make sure invalidation works. First
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
150 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: 295
diff changeset
151 without that the invalidation would not work"""
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
152 tmp = [name]
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
153 tmp.extend(args)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
154 args = tuple(tmp)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
155
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
156 if name == 'cached_repo_list':
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
157 from pylons_app.model.hg_model import _get_repos_cached
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
158 region_invalidate(_get_repos_cached, None, *args)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
159
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
160 if name == 'full_changelog':
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
161 from pylons_app.model.hg_model import _full_changelog_cached
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
162 region_invalidate(_full_changelog_cached, None, *args)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
163
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
164 from vcs.backends.base import BaseChangeset
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
165 from vcs.utils.lazy import LazyProperty
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
166 class EmptyChangeset(BaseChangeset):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
167
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
168 revision = -1
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
169 message = ''
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
170
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
171 @LazyProperty
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
172 def raw_id(self):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
173 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
174 Returns raw string identifing this changeset, useful for web
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
175 representation.
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
176 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
177 return '0' * 12
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
178
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
179
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
180 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
181 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
182 maps all found repositories into db
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
183 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
184 from pylons_app.model.repo_model import RepoModel
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
185
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
186 sa = Session()
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
187 user = sa.query(User).filter(User.admin == True).first()
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
188
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
189 rm = RepoModel()
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
190
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
191 for name, repo in initial_repo_list.items():
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
192 if not sa.query(Repository).get(name):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
193 log.info('repository %s not found creating default', name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
194
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
195 form_data = {
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
196 'repo_name':name,
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
197 'description':repo.description if repo.description != 'unknown' else \
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
198 'auto description for %s' % name,
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
199 'private':False
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
200 }
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
201 rm.create(form_data, user, just_db=True)
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
202
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
203
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
204 if remove_obsolete:
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
205 #remove from database those repositories that are not in the filesystem
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
206 for repo in sa.query(Repository).all():
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
207 if repo.repo_name not in initial_repo_list.keys():
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
208 sa.delete(repo)
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
209 sa.commit()
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
210