comparison pylons_app/lib/utils.py @ 376:d09381593b12

updated db manage script, and remove broken test
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 15 Jul 2010 06:25:43 +0200
parents 664a5b8c551a
children 23e720be5f44
comparison
equal deleted inserted replaced
374:664a5b8c551a 376:d09381593b12
14 # 14 #
15 # You should have received a copy of the GNU General Public License 15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software 16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 # MA 02110-1301, USA. 18 # MA 02110-1301, USA.
19 from beaker.cache import cache_region
20 19
21 """ 20 """
22 Created on April 18, 2010 21 Created on April 18, 2010
23 Utilities for hg app 22 Utilities for hg app
24 @author: marcink 23 @author: marcink
25 """ 24 """
26 25 from beaker.cache import cache_region
27 import os
28 import logging
29 from mercurial import ui, config, hg 26 from mercurial import ui, config, hg
30 from mercurial.error import RepoError 27 from mercurial.error import RepoError
28 from pylons_app.model import meta
31 from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings 29 from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings
32 from pylons_app.model import meta 30 from vcs.backends.base import BaseChangeset
31 from vcs.utils.lazy import LazyProperty
32 import logging
33 import os
33 log = logging.getLogger(__name__) 34 log = logging.getLogger(__name__)
34 35
35 36
36 def get_repo_slug(request): 37 def get_repo_slug(request):
37 return request.environ['pylons.routes_dict'].get('repo_name') 38 return request.environ['pylons.routes_dict'].get('repo_name')
75 except RepoError: 76 except RepoError:
76 #it means that there is no valid repo there... 77 #it means that there is no valid repo there...
77 log.info('%s repo is free for creation', repo_name) 78 log.info('%s repo is free for creation', repo_name)
78 return True 79 return True
79 80
80 81 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
82 while True:
83 ok = raw_input(prompt)
84 if ok in ('y', 'ye', 'yes'): return True
85 if ok in ('n', 'no', 'nop', 'nope'): return False
86 retries = retries - 1
87 if retries < 0: raise IOError
88 print complaint
89
81 @cache_region('super_short_term', 'cached_hg_ui') 90 @cache_region('super_short_term', 'cached_hg_ui')
82 def get_hg_ui_cached(): 91 def get_hg_ui_cached():
83 try: 92 try:
84 sa = meta.Session 93 sa = meta.Session
85 ret = sa.query(HgAppUi).all() 94 ret = sa.query(HgAppUi).all()
168 177
169 if name == 'full_changelog': 178 if name == 'full_changelog':
170 from pylons_app.model.hg_model import _full_changelog_cached 179 from pylons_app.model.hg_model import _full_changelog_cached
171 region_invalidate(_full_changelog_cached, None, *args) 180 region_invalidate(_full_changelog_cached, None, *args)
172 181
173 from vcs.backends.base import BaseChangeset
174 from vcs.utils.lazy import LazyProperty
175 class EmptyChangeset(BaseChangeset): 182 class EmptyChangeset(BaseChangeset):
176 183
177 revision = -1 184 revision = -1
178 message = '' 185 message = ''
179 186