annotate pylons_app/lib/utils.py @ 584:39203995f2c4

made action logger more global, to be used in other places to log other actions. cleaned unused import in simpleHG, fixed little logging in hooks
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 02 Oct 2010 01:52:43 +0200
parents 63212fea2471
children 48be953851fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 """
376
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
25 from beaker.cache import cache_region
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
26 from mercurial import ui, config, hg
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
27 from mercurial.error import RepoError
376
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
28 from pylons_app.model import meta
584
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
29 from pylons_app.model.db import Repository, User, HgAppUi, HgAppSettings,UserLog
376
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
30 from vcs.backends.base import BaseChangeset
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
31 from vcs.utils.lazy import LazyProperty
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
32 import logging
584
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
33 import datetime
376
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
34 import os
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
35
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
36 log = logging.getLogger(__name__)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
37
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
38
584
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
39 def get_repo_slug(request):
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
40 return request.environ['pylons.routes_dict'].get('repo_name')
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 def is_mercurial(environ):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
43 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
44 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
45 ``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
46 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
47 http_accept = environ.get('HTTP_ACCEPT')
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
48 if http_accept and http_accept.startswith('application/mercurial'):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
49 return True
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
50 return False
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
51
584
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
52 def action_logger(user, action, repo, ipaddr, sa=None):
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
53 """
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
54 Action logger for various action made by users
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
55 """
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
56
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
57 if not sa:
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
58 sa = meta.Session
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
59
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
60
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
61 if hasattr(user, 'user_id'):
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
62 user_id = user.user_id
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
63 elif isinstance(user, basestring):
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
64
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
65 user_id = sa.Query(User).filter(User.username == user).one()
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
66 else:
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
67 raise Exception('You have to provide user object or username')
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
68
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
69 try:
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
70 user_log = UserLog()
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
71 user_log.user_id = user_id
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
72 user_log.action = action
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
73 user_log.repository = sa.query(Repository)\
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
74 .filter(Repository.repo_name==repo.lstrip('/')).one()
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
75 user_log.action_date = datetime.datetime.now()
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
76 user_log.user_ip = ipaddr
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
77 sa.add(user_log)
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
78 sa.commit()
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
79 log.info('Adding user %s, action %s on %s',
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
80 user.username, action, repo)
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
81 except Exception, e:
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
82 raise
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
83 sa.rollback()
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
84 log.error('could not log user action:%s', str(e))
39203995f2c4 made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents: 572
diff changeset
85
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
86 def check_repo_dir(paths):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
87 repos_path = paths[0][1].split('/')
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
88 if repos_path[-1] in ['*', '**']:
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
89 repos_path = repos_path[:-1]
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
90 if repos_path[0] != '/':
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
91 repos_path[0] = '/'
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
92 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
93 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
94
314
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
95 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: 310
diff changeset
96 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: 310
diff changeset
97 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: 310
diff changeset
98
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
99 def check_repo(repo_name, base_path, verify=True):
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
100
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
101 repo_path = os.path.join(base_path, repo_name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
102
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
103 try:
314
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
104 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: 310
diff changeset
105 return False
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
106 r = hg.repository(ui.ui(), repo_path)
314
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
107 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: 310
diff changeset
108 hg.verify(r)
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
109 #here we hnow that repo exists it was verified
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
110 log.info('%s repo is already created', repo_name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
111 return False
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
112 except RepoError:
314
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
113 #it means that there is no valid repo there...
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
114 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
115 return True
314
752675cdd167 made routes verification method based only on paths, since it's much faster and enough
Marcin Kuzminski <marcin@python-works.com>
parents: 310
diff changeset
116
376
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
117 def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
118 while True:
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
119 ok = raw_input(prompt)
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
120 if ok in ('y', 'ye', 'yes'): return True
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
121 if ok in ('n', 'no', 'nop', 'nope'): return False
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
122 retries = retries - 1
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
123 if retries < 0: raise IOError
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
124 print complaint
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 374
diff changeset
125
366
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 364
diff changeset
126 @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: 364
diff changeset
127 def get_hg_ui_cached():
374
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
128 try:
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
129 sa = meta.Session
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
130 ret = sa.query(HgAppUi).all()
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
131 finally:
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
132 meta.Session.remove()
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
133 return ret
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
134
366
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 364
diff changeset
135
368
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 366
diff changeset
136 def get_hg_settings():
374
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
137 try:
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
138 sa = meta.Session
413
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
139 ret = sa.query(HgAppSettings).all()
374
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
140 finally:
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
141 meta.Session.remove()
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
142
368
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 366
diff changeset
143 if not ret:
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 366
diff changeset
144 raise Exception('Could not get application settings !')
413
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
145 settings = {}
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
146 for each in ret:
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
147 settings['hg_app_' + each.app_settings_name] = each.app_settings_value
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
148
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
149 return settings
419
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
150
421
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
151 def get_hg_ui_settings():
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
152 try:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
153 sa = meta.Session
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
154 ret = sa.query(HgAppUi).all()
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
155 finally:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
156 meta.Session.remove()
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
157
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
158 if not ret:
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
159 raise Exception('Could not get application ui settings !')
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
160 settings = {}
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
161 for each in ret:
428
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
162 k = each.ui_key
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
163 v = each.ui_value
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
164 if k == '/':
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
165 k = 'root_path'
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
166
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
167 if k.find('.') != -1:
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
168 k = k.replace('.', '_')
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
169
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
170 if each.ui_section == 'hooks':
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
171 v = each.ui_active
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
172
e8af467b5a60 Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents: 425
diff changeset
173 settings[each.ui_section + '_' + k] = v
421
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
174
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
175 return settings
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
176
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
177 #propagated from mercurial documentation
419
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
178 ui_sections = ['alias', 'auth',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
179 'decode/encode', 'defaults',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
180 'diff', 'email',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
181 'extensions', 'format',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
182 'merge-patterns', 'merge-tools',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
183 'hooks', 'http_proxy',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
184 'smtp', 'patch',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
185 'paths', 'profiling',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
186 'server', 'trusted',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
187 'ui', 'web', ]
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
188
364
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: 314
diff changeset
189 def make_ui(read_from='file', path=None, checkpaths=True):
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
190 """
364
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: 314
diff changeset
191 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: 314
diff changeset
192 and make an mercurial ui object from read options
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
193
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
194 @param path: path to mercurial config file
364
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: 314
diff changeset
195 @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: 314
diff changeset
196 @param read_from: read from 'file' or 'db'
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
197 """
419
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
198
364
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: 314
diff changeset
199 baseui = ui.ui()
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
200
364
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: 314
diff changeset
201 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: 314
diff changeset
202 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: 314
diff changeset
203 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: 314
diff changeset
204 return False
421
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
205 log.debug('reading hgrc from %s', path)
364
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: 314
diff changeset
206 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: 314
diff changeset
207 cfg.read(path)
419
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 413
diff changeset
208 for section in ui_sections:
364
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: 314
diff changeset
209 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: 314
diff changeset
210 baseui.setconfig(section, k, v)
421
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 419
diff changeset
211 log.debug('settings ui from file[%s]%s:%s', section, k, v)
364
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: 314
diff changeset
212 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: 314
diff changeset
213
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: 314
diff changeset
214
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: 314
diff changeset
215 elif read_from == 'db':
366
6484963056cd implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents: 364
diff changeset
216 hg_ui = get_hg_ui_cached()
364
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: 314
diff changeset
217 for ui_ in hg_ui:
425
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 421
diff changeset
218 if ui_.ui_active:
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 421
diff changeset
219 log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, ui_.ui_key, ui_.ui_value)
b27d32cb3157 Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents: 421
diff changeset
220 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value)
364
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: 314
diff changeset
221
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
222
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
223 return baseui
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
224
364
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: 314
diff changeset
225
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: 314
diff changeset
226 def set_hg_app_config(config):
368
bb8f45f6d8f9 updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents: 366
diff changeset
227 hgsettings = get_hg_settings()
413
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
228
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
229 for k, v in hgsettings.items():
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 393
diff changeset
230 config[k] = v
364
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: 314
diff changeset
231
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
232 def invalidate_cache(name, *args):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
233 """Invalidates given name cache"""
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
234
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
235 from beaker.cache import region_invalidate
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
236 log.info('INVALIDATING CACHE FOR %s', name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
237
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
238 """propagate our arguments to make sure invalidation works. First
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
239 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
240 without that the invalidation would not work"""
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
241 tmp = [name]
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
242 tmp.extend(args)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
243 args = tuple(tmp)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
244
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
245 if name == 'cached_repo_list':
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
246 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
247 region_invalidate(_get_repos_cached, None, *args)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
248
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
249 if name == 'full_changelog':
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
250 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
251 region_invalidate(_full_changelog_cached, None, *args)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
252
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
253 class EmptyChangeset(BaseChangeset):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
254
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
255 revision = -1
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
256 message = ''
533
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 517
diff changeset
257 author = ''
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
258
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
259 @LazyProperty
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
260 def raw_id(self):
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
261 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
262 Returns raw string identifing this changeset, useful for web
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
263 representation.
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
264 """
568
eda96fb85ba7 dohh !! fixed EmptyCHangeset for new vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 541
diff changeset
265 return '0' * 40
eda96fb85ba7 dohh !! fixed EmptyCHangeset for new vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 541
diff changeset
266
572
63212fea2471 a lot of fixes in templates,
Marcin Kuzminski <marcin@python-works.com>
parents: 568
diff changeset
267 @LazyProperty
568
eda96fb85ba7 dohh !! fixed EmptyCHangeset for new vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 541
diff changeset
268 def short_id(self):
572
63212fea2471 a lot of fixes in templates,
Marcin Kuzminski <marcin@python-works.com>
parents: 568
diff changeset
269 return self.raw_id[:12]
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
270
372
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
271 def repo2db_mapper(initial_repo_list, remove_obsolete=False):
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
272 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
273 maps all found repositories into db
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
274 """
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
275 from pylons_app.model.repo_model import RepoModel
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
276
374
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
277 sa = meta.Session
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
278 user = sa.query(User).filter(User.admin == True).first()
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
279
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
280 rm = RepoModel()
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
281
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
282 for name, repo in initial_repo_list.items():
393
a26f48ad7a8a fixes issue #16 reimplementation of database repository, for using generic pk instead of repo naming as pk. Which caused to many problems.
Marcin Kuzminski <marcin@python-works.com>
parents: 384
diff changeset
283 if not sa.query(Repository).filter(Repository.repo_name == name).scalar():
310
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
284 log.info('repository %s not found creating default', name)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
285
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
286 form_data = {
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
287 'repo_name':name,
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
288 'description':repo.description if repo.description != 'unknown' else \
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
289 'auto description for %s' % name,
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
290 'private':False
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
291 }
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 308
diff changeset
292 rm.create(form_data, user, just_db=True)
372
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
293
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
294
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
295 if remove_obsolete:
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
296 #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: 368
diff changeset
297 for repo in sa.query(Repository).all():
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
298 if repo.repo_name not in initial_repo_list.keys():
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
299 sa.delete(repo)
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
300 sa.commit()
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 368
diff changeset
301
374
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
302
664a5b8c551a Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents: 372
diff changeset
303 meta.Session.remove()
384
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
304
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
305 from UserDict import DictMixin
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
306
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
307 class OrderedDict(dict, DictMixin):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
308
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
309 def __init__(self, *args, **kwds):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
310 if len(args) > 1:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
311 raise TypeError('expected at most 1 arguments, got %d' % len(args))
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
312 try:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
313 self.__end
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
314 except AttributeError:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
315 self.clear()
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
316 self.update(*args, **kwds)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
317
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
318 def clear(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
319 self.__end = end = []
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
320 end += [None, end, end] # sentinel node for doubly linked list
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
321 self.__map = {} # key --> [key, prev, next]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
322 dict.clear(self)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
323
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
324 def __setitem__(self, key, value):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
325 if key not in self:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
326 end = self.__end
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
327 curr = end[1]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
328 curr[2] = end[1] = self.__map[key] = [key, curr, end]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
329 dict.__setitem__(self, key, value)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
330
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
331 def __delitem__(self, key):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
332 dict.__delitem__(self, key)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
333 key, prev, next = self.__map.pop(key)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
334 prev[2] = next
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
335 next[1] = prev
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
336
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
337 def __iter__(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
338 end = self.__end
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
339 curr = end[2]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
340 while curr is not end:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
341 yield curr[0]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
342 curr = curr[2]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
343
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
344 def __reversed__(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
345 end = self.__end
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
346 curr = end[1]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
347 while curr is not end:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
348 yield curr[0]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
349 curr = curr[1]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
350
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
351 def popitem(self, last=True):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
352 if not self:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
353 raise KeyError('dictionary is empty')
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
354 if last:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
355 key = reversed(self).next()
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
356 else:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
357 key = iter(self).next()
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
358 value = self.pop(key)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
359 return key, value
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
360
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
361 def __reduce__(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
362 items = [[k, self[k]] for k in self]
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
363 tmp = self.__map, self.__end
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
364 del self.__map, self.__end
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
365 inst_dict = vars(self).copy()
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
366 self.__map, self.__end = tmp
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
367 if inst_dict:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
368 return (self.__class__, (items,), inst_dict)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
369 return self.__class__, (items,)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
370
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
371 def keys(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
372 return list(self)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
373
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
374 setdefault = DictMixin.setdefault
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
375 update = DictMixin.update
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
376 pop = DictMixin.pop
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
377 values = DictMixin.values
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
378 items = DictMixin.items
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
379 iterkeys = DictMixin.iterkeys
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
380 itervalues = DictMixin.itervalues
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
381 iteritems = DictMixin.iteritems
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
382
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
383 def __repr__(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
384 if not self:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
385 return '%s()' % (self.__class__.__name__,)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
386 return '%s(%r)' % (self.__class__.__name__, self.items())
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
387
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
388 def copy(self):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
389 return self.__class__(self)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
390
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
391 @classmethod
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
392 def fromkeys(cls, iterable, value=None):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
393 d = cls()
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
394 for key in iterable:
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
395 d[key] = value
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
396 return d
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
397
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
398 def __eq__(self, other):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
399 if isinstance(other, OrderedDict):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
400 return len(self) == len(other) and self.items() == other.items()
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
401 return dict.__eq__(self, other)
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
402
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
403 def __ne__(self, other):
23e720be5f44 Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents: 376
diff changeset
404 return not self == other
517
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
405
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
406
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
407 #===============================================================================
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
408 # TEST FUNCTIONS
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
409 #===============================================================================
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
410 def create_test_index(repo_location, full_index):
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
411 """Makes default test index
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
412 @param repo_location:
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
413 @param full_index:
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
414 """
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
415 from pylons_app.lib.indexers.daemon import WhooshIndexingDaemon
541
fb0c3af6031b Implemented locking for task, to prevent for running the same tasks,
Marcin Kuzminski <marcin@python-works.com>
parents: 535
diff changeset
416 from pylons_app.lib.pidlock import DaemonLock, LockHeld
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
417 from pylons_app.lib.indexers import IDX_LOCATION
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
418 import shutil
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
419
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
420 if os.path.exists(IDX_LOCATION):
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
421 shutil.rmtree(IDX_LOCATION)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
422
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
423 try:
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
424 l = DaemonLock()
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
425 WhooshIndexingDaemon(repo_location=repo_location)\
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
426 .run(full_index=full_index)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
427 l.release()
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
428 except LockHeld:
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
429 pass
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
430
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
431 def create_test_env(repos_test_path, config):
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
432 """Makes a fresh database and
517
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
433 install test repository into tmp dir
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
434 """
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
435 from pylons_app.lib.db_manage import DbManage
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
436 import tarfile
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
437 import shutil
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
438 from os.path import dirname as dn, join as jn, abspath
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
439
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
440 log = logging.getLogger('TestEnvCreator')
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
441 # create logger
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
442 log.setLevel(logging.DEBUG)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
443 log.propagate = True
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
444 # create console handler and set level to debug
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
445 ch = logging.StreamHandler()
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
446 ch.setLevel(logging.DEBUG)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
447
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
448 # create formatter
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
449 formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
517
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
450
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
451 # add formatter to ch
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
452 ch.setFormatter(formatter)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
453
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
454 # add ch to logger
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
455 log.addHandler(ch)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
456
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
457 #PART ONE create db
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
458 log.debug('making test db')
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
459 dbname = config['sqlalchemy.db1.url'].split('/')[-1]
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
460 dbmanage = DbManage(log_sql=True, dbname=dbname, tests=True)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
461 dbmanage.create_tables(override=True)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
462 dbmanage.config_prompt(repos_test_path)
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
463 dbmanage.create_default_user()
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
464 dbmanage.admin_prompt()
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
465 dbmanage.create_permissions()
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
466 dbmanage.populate_default_permissions()
517
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
467
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
468 #PART TWO make test repo
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
469 log.debug('making test vcs repo')
517
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
470 if os.path.isdir('/tmp/vcs_test'):
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
471 shutil.rmtree('/tmp/vcs_test')
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
472
535
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 533
diff changeset
473 cur_dir = dn(dn(abspath(__file__)))
533
460ad816820d fixed bug when new repo had no last commiter,
Marcin Kuzminski <marcin@python-works.com>
parents: 517
diff changeset
474 tar = tarfile.open(jn(cur_dir, 'tests', "vcs_test.tar.gz"))
517
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
475 tar.extractall('/tmp')
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 428
diff changeset
476 tar.close()