Mercurial > kallithea
annotate rhodecode/lib/utils.py @ 708:b9bbc0d6e9f3 beta
added cache reset, stats reset, and delete into repository settings in admin.
Some small template fixes
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 18 Nov 2010 01:55:51 +0100 |
parents | cb0d9ce6ac5c |
children | a9bc513a1fe3 |
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 |
569
000b675e7c1d
bumped version, some spelling fixes
Marcin Kuzminski <marcin@python-works.com>
parents:
567
diff
changeset
|
3 # Utilities for RhodeCode |
297
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. |
633
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
19 """ |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
20 Created on April 18, 2010 |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
21 Utilities for RhodeCode |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
22 @author: marcink |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
23 """ |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
24 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
25 from UserDict import DictMixin |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
26 from mercurial import ui, config, hg |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
27 from mercurial.error import RepoError |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
28 from rhodecode.model import meta |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
29 from rhodecode.model.caching_query import FromCache |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
30 from rhodecode.model.db import Repository, User, RhodeCodeUi, RhodeCodeSettings, \ |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
31 UserLog |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
32 from rhodecode.model.repo import RepoModel |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
33 from rhodecode.model.user import UserModel |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
34 from vcs.backends.base import BaseChangeset |
684
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
35 from paste.script import command |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
36 import ConfigParser |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
37 from vcs.utils.lazy import LazyProperty |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
38 import traceback |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
39 import datetime |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
40 import logging |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
41 import os |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
42 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
43 log = logging.getLogger(__name__) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
44 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
45 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
46 def get_repo_slug(request): |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
47 return request.environ['pylons.routes_dict'].get('repo_name') |
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 is_mercurial(environ): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
50 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
51 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
|
52 ``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
|
53 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
54 http_accept = environ.get('HTTP_ACCEPT') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
55 if http_accept and http_accept.startswith('application/mercurial'): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
56 return True |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
57 return False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
58 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
59 def is_git(environ): |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
60 """ |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
61 Returns True if request's target is git server. ``HTTP_USER_AGENT`` would |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
62 then have git client version given. |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
63 |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
64 :param environ: |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
65 """ |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
66 http_user_agent = environ.get('HTTP_USER_AGENT') |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
67 if http_user_agent and http_user_agent.startswith('git'): |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
68 return True |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
69 return False |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
70 |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
71 def action_logger(user, action, repo, ipaddr='', sa=None): |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
72 """ |
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
73 Action logger for various action made by users |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
74 |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
75 :param user: user that made this action, can be a string unique username or |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
76 object containing user_id attribute |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
77 :param action: action to log, should be on of predefined unique actions for |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
78 easy translations |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
79 :param repo: repository that action was made on |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
80 :param ipaddr: optional ip address from what the action was made |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
81 :param sa: optional sqlalchemy session |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
82 |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
83 """ |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
84 |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
85 if not sa: |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
86 sa = meta.Session() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
87 |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
88 try: |
537
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
89 if hasattr(user, 'user_id'): |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
90 user_obj = user |
537
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
91 elif isinstance(user, basestring): |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
92 user_obj = UserModel().get_by_username(user, cache=False) |
537
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
93 else: |
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
94 raise Exception('You have to provide user object or username') |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
95 |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
96 |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
97 if repo: |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
98 repo_name = repo.lstrip('/') |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
99 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
100 repository = RepoModel().get(repo_name, cache=False) |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
101 if not repository: |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
102 raise Exception('You have to provide valid repository') |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
103 else: |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
104 raise Exception('You have to provide repository to action logger') |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
105 |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
106 |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
107 user_log = UserLog() |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
108 user_log.user_id = user_obj.user_id |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
109 user_log.action = action |
537
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
110 user_log.repository_name = repo_name |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
111 user_log.repository = repository |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
112 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:
524
diff
changeset
|
113 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:
524
diff
changeset
|
114 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:
524
diff
changeset
|
115 sa.commit() |
621
9893c2fc846b
removed raise from log user action
Marcin Kuzminski <marcin@python-works.com>
parents:
604
diff
changeset
|
116 |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
117 log.info('Adding user %s, action %s on %s', |
654
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
118 user_obj.username, action, repo) |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
119 except: |
7f5976da192c
#48 rewrite action loggers into hooks with all changesets that are inside a push
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
120 log.error(traceback.format_exc()) |
536
39203995f2c4
made action logger more global, to be used in other places to log other actions.
Marcin Kuzminski <marcin@python-works.com>
parents:
524
diff
changeset
|
121 sa.rollback() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
122 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
123 def get_repos(path, recursive=False, initial=False): |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
124 """ |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
125 Scans given path for repos and return (name,(type,path)) tuple |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
126 :param prefix: |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
127 :param path: |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
128 :param recursive: |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
129 :param initial: |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
130 """ |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
131 from vcs.utils.helpers import get_scm |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
132 from vcs.exceptions import VCSError |
633
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
133 |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
134 try: |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
135 scm = get_scm(path) |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
136 except: |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
137 pass |
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
138 else: |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
139 raise Exception('The given path %s should not be a repository got %s', |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
140 path, scm) |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
141 |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
142 for dirpath in os.listdir(path): |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
143 try: |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
144 yield dirpath, get_scm(os.path.join(path, dirpath)) |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
145 except VCSError: |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
146 pass |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
147 |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
148 if __name__ == '__main__': |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
149 get_repos('', '/home/marcink/workspace-python') |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
150 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
151 |
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
|
152 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
|
153 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
|
154 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
|
155 |
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
|
156 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
|
157 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
158 repo_path = os.path.join(base_path, repo_name) |
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 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
|
161 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
|
162 return False |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
163 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
|
164 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
|
165 hg.verify(r) |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
166 #here we hnow that repo exists it was verified |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
167 log.info('%s repo is already created', repo_name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
168 return False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
169 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
|
170 #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
|
171 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
|
172 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
|
173 |
351
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
174 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:
350
diff
changeset
|
175 while True: |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
176 ok = raw_input(prompt) |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
177 if ok in ('y', 'ye', 'yes'): return True |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
178 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:
350
diff
changeset
|
179 retries = retries - 1 |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
180 if retries < 0: raise IOError |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
181 print complaint |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
182 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
183 def get_hg_ui_cached(): |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
184 try: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
185 sa = meta.Session |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
186 ret = sa.query(RhodeCodeUi)\ |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
187 .options(FromCache("sql_cache_short", "get_hg_ui_settings"))\ |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
188 .all() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
189 except: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
190 pass |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
191 finally: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
192 meta.Session.remove() |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
193 return ret |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
194 |
343
6484963056cd
implemented cache for repeated queries in simplehg mercurial requests
Marcin Kuzminski <marcin@python-works.com>
parents:
341
diff
changeset
|
195 |
345
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
343
diff
changeset
|
196 def get_hg_settings(): |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
197 try: |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
198 sa = meta.Session() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
199 ret = sa.query(RhodeCodeSettings)\ |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
200 .options(FromCache("sql_cache_short", "get_hg_settings"))\ |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
201 .all() |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
202 except: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
203 pass |
350
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
204 finally: |
664a5b8c551a
Added application settings, are now customizable from database
Marcin Kuzminski <marcin@python-works.com>
parents:
348
diff
changeset
|
205 meta.Session.remove() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
206 |
345
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
343
diff
changeset
|
207 if not ret: |
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
343
diff
changeset
|
208 raise Exception('Could not get application settings !') |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
209 settings = {} |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
210 for each in ret: |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
211 settings['rhodecode_' + each.app_settings_name] = each.app_settings_value |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
212 |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
213 return settings |
386
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
214 |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
215 def get_hg_ui_settings(): |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
216 try: |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
217 sa = meta.Session() |
549
f99075170eb4
more renames for rhode code !!
Marcin Kuzminski <marcin@python-works.com>
parents:
548
diff
changeset
|
218 ret = sa.query(RhodeCodeUi).all() |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
219 except: |
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
220 pass |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
221 finally: |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
222 meta.Session.remove() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
223 |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
224 if not ret: |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
225 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:
386
diff
changeset
|
226 settings = {} |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
227 for each in ret: |
395
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
228 k = each.ui_key |
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
229 v = each.ui_value |
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
230 if k == '/': |
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
231 k = 'root_path' |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
232 |
395
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
233 if k.find('.') != -1: |
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
234 k = k.replace('.', '_') |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
235 |
395
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
236 if each.ui_section == 'hooks': |
e8af467b5a60
Added hooks managment into application settings
Marcin Kuzminski <marcin@python-works.com>
parents:
392
diff
changeset
|
237 v = each.ui_active |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
238 |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
239 settings[each.ui_section + '_' + k] = v |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
240 |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
241 return settings |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
242 |
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
243 #propagated from mercurial documentation |
386
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
244 ui_sections = ['alias', 'auth', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
245 'decode/encode', 'defaults', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
246 'diff', 'email', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
247 'extensions', 'format', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
248 'merge-patterns', 'merge-tools', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
249 'hooks', 'http_proxy', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
250 'smtp', 'patch', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
251 'paths', 'profiling', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
252 'server', 'trusted', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
253 'ui', 'web', ] |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
254 |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
255 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
|
256 """ |
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
|
257 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
|
258 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
|
259 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
260 :param path: path to mercurial config file |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
261 :param checkpaths: check the path |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
262 :param read_from: read from 'file' or 'db' |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
263 """ |
386
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
264 |
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
|
265 baseui = ui.ui() |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
266 |
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
|
267 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
|
268 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
|
269 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
|
270 return False |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
271 log.debug('reading hgrc from %s', path) |
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
|
272 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
|
273 cfg.read(path) |
386
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
274 for section in ui_sections: |
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
|
275 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
|
276 baseui.setconfig(section, k, v) |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
277 log.debug('settings ui from file[%s]%s:%s', section, k, v) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
278 |
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
|
279 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
|
280 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
|
281 for ui_ in hg_ui: |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
388
diff
changeset
|
282 if ui_.ui_active: |
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
388
diff
changeset
|
283 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:
388
diff
changeset
|
284 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
285 |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
286 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
287 return baseui |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
288 |
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
|
289 |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
290 def set_rhodecode_config(config): |
345
bb8f45f6d8f9
updated hg-app db manage and global settings
Marcin Kuzminski <marcin@python-works.com>
parents:
343
diff
changeset
|
291 hgsettings = get_hg_settings() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
292 |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
293 for k, v in hgsettings.items(): |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
294 config[k] = v |
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
|
295 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
296 def invalidate_cache(cache_key, *args): |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
297 """ |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
298 Puts cache invalidation task into db for |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
299 further global cache invalidation |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
300 """ |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
301 from rhodecode.model.scm import ScmModel |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
302 |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
303 if cache_key.startswith('get_repo_cached_'): |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
304 name = cache_key.split('get_repo_cached_')[-1] |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
305 ScmModel().mark_for_invalidation(name) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
306 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
307 class EmptyChangeset(BaseChangeset): |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
308 """ |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
309 An dummy empty changeset. It's possible to pass hash when creating |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
310 an EmptyChangeset |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
311 """ |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
312 |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
313 def __init__(self, cs='0' * 40): |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
314 self._empty_cs = cs |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
315 self.revision = -1 |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
316 self.message = '' |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
317 self.author = '' |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
318 self.date = '' |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
633
diff
changeset
|
319 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
320 @LazyProperty |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
321 def raw_id(self): |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
322 """ |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
323 Returns raw string identifying this changeset, useful for web |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
324 representation. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
325 """ |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
326 return self._empty_cs |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
327 |
524
63212fea2471
a lot of fixes in templates,
Marcin Kuzminski <marcin@python-works.com>
parents:
520
diff
changeset
|
328 @LazyProperty |
520
eda96fb85ba7
dohh !! fixed EmptyCHangeset for new vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
497
diff
changeset
|
329 def short_id(self): |
524
63212fea2471
a lot of fixes in templates,
Marcin Kuzminski <marcin@python-works.com>
parents:
520
diff
changeset
|
330 return self.raw_id[:12] |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
331 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
332 def get_file_changeset(self, path): |
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
333 return self |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
334 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
335 def get_file_content(self, path): |
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
336 return u'' |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
337 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
338 def get_file_size(self, path): |
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
339 return 0 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
340 |
348
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
341 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
|
342 """ |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
343 maps all found repositories into db |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
344 """ |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
345 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
346 sa = meta.Session() |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
347 rm = RepoModel() |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
348 user = sa.query(User).filter(User.admin == True).first() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
349 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
350 for name, repo in initial_repo_list.items(): |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
351 if not rm.get(name, cache=False): |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
352 log.info('repository %s not found creating default', name) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
353 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
354 form_data = { |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
355 'repo_name':name, |
652
37dc1e8d84d8
changed repo type to use alias
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
356 'repo_type':repo.alias, |
659
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
656
diff
changeset
|
357 'description':repo.description \ |
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
656
diff
changeset
|
358 if repo.description != 'unknown' else \ |
758f64f3fbda
extended repo creation by repo type. fixed fork creation to maintain repo type.
Marcin Kuzminski <marcin@python-works.com>
parents:
656
diff
changeset
|
359 '%s repository' % name, |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
360 'private':False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
361 } |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
362 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
|
363 |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
364 if remove_obsolete: |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
365 #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
|
366 for repo in sa.query(Repository).all(): |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
367 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
|
368 sa.delete(repo) |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
369 sa.commit() |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
370 |
358
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
371 class OrderedDict(dict, DictMixin): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
372 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
373 def __init__(self, *args, **kwds): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
374 if len(args) > 1: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
375 raise TypeError('expected at most 1 arguments, got %d' % len(args)) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
376 try: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
377 self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
378 except AttributeError: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
379 self.clear() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
380 self.update(*args, **kwds) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
381 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
382 def clear(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
383 self.__end = end = [] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
384 end += [None, end, end] # sentinel node for doubly linked list |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
385 self.__map = {} # key --> [key, prev, next] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
386 dict.clear(self) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
387 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
388 def __setitem__(self, key, value): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
389 if key not in self: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
390 end = self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
391 curr = end[1] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
392 curr[2] = end[1] = self.__map[key] = [key, curr, end] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
393 dict.__setitem__(self, key, value) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
394 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
395 def __delitem__(self, key): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
396 dict.__delitem__(self, key) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
397 key, prev, next = self.__map.pop(key) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
398 prev[2] = next |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
399 next[1] = prev |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
400 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
401 def __iter__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
402 end = self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
403 curr = end[2] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
404 while curr is not end: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
405 yield curr[0] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
406 curr = curr[2] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
407 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
408 def __reversed__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
409 end = self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
410 curr = end[1] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
411 while curr is not end: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
412 yield curr[0] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
413 curr = curr[1] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
414 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
415 def popitem(self, last=True): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
416 if not self: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
417 raise KeyError('dictionary is empty') |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
418 if last: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
419 key = reversed(self).next() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
420 else: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
421 key = iter(self).next() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
422 value = self.pop(key) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
423 return key, value |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
424 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
425 def __reduce__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
426 items = [[k, self[k]] for k in self] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
427 tmp = self.__map, self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
428 del self.__map, self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
429 inst_dict = vars(self).copy() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
430 self.__map, self.__end = tmp |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
431 if inst_dict: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
432 return (self.__class__, (items,), inst_dict) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
433 return self.__class__, (items,) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
434 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
435 def keys(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
436 return list(self) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
437 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
438 setdefault = DictMixin.setdefault |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
439 update = DictMixin.update |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
440 pop = DictMixin.pop |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
441 values = DictMixin.values |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
442 items = DictMixin.items |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
443 iterkeys = DictMixin.iterkeys |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
444 itervalues = DictMixin.itervalues |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
445 iteritems = DictMixin.iteritems |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
446 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
447 def __repr__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
448 if not self: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
449 return '%s()' % (self.__class__.__name__,) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
450 return '%s(%r)' % (self.__class__.__name__, self.items()) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
451 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
452 def copy(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
453 return self.__class__(self) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
454 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
455 @classmethod |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
456 def fromkeys(cls, iterable, value=None): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
457 d = cls() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
458 for key in iterable: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
459 d[key] = value |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
460 return d |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
461 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
462 def __eq__(self, other): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
463 if isinstance(other, OrderedDict): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
464 return len(self) == len(other) and self.items() == other.items() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
465 return dict.__eq__(self, other) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
466 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
467 def __ne__(self, other): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
468 return not self == other |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
469 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
470 |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
471 #=============================================================================== |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
472 # TEST FUNCTIONS AND CREATORS |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
473 #=============================================================================== |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
474 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:
489
diff
changeset
|
475 """Makes default test index |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
476 :param repo_location: |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
477 :param full_index: |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
478 """ |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
544
diff
changeset
|
479 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
544
diff
changeset
|
480 from rhodecode.lib.pidlock import DaemonLock, LockHeld |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
481 import shutil |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
482 |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
483 index_location = os.path.join(repo_location, 'index') |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
484 if os.path.exists(index_location): |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
485 shutil.rmtree(index_location) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
486 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
487 try: |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
488 l = DaemonLock() |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
489 WhooshIndexingDaemon(index_location=index_location, |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
490 repo_location=repo_location)\ |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
491 .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:
489
diff
changeset
|
492 l.release() |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
493 except LockHeld: |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
494 pass |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
495 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
496 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:
489
diff
changeset
|
497 """Makes a fresh database and |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
498 install test repository into tmp dir |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
499 """ |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
544
diff
changeset
|
500 from rhodecode.lib.db_manage import DbManage |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
501 from rhodecode.tests import HG_REPO, GIT_REPO, NEW_HG_REPO, NEW_GIT_REPO, \ |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
502 HG_FORK, GIT_FORK, TESTS_TMP_PATH |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
503 import tarfile |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
504 import shutil |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
505 from os.path import dirname as dn, join as jn, abspath |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
506 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
507 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:
489
diff
changeset
|
508 # create logger |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
509 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:
489
diff
changeset
|
510 log.propagate = True |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
511 # 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:
489
diff
changeset
|
512 ch = logging.StreamHandler() |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
513 ch.setLevel(logging.DEBUG) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
514 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
515 # create formatter |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
516 formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
517 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
518 # 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:
489
diff
changeset
|
519 ch.setFormatter(formatter) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
520 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
521 # 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:
489
diff
changeset
|
522 log.addHandler(ch) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
523 |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
524 #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:
489
diff
changeset
|
525 dbname = config['sqlalchemy.db1.url'].split('/')[-1] |
567
80dc0a23edf7
fixed whoosh failure on new repository
Marcin Kuzminski <marcin@python-works.com>
parents:
552
diff
changeset
|
526 log.debug('making test db %s', dbname) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
527 |
552
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
528 dbmanage = DbManage(log_sql=True, dbname=dbname, root=config['here'], |
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
529 tests=True) |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
530 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:
489
diff
changeset
|
531 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:
489
diff
changeset
|
532 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:
489
diff
changeset
|
533 dbmanage.admin_prompt() |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
534 dbmanage.create_permissions() |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
535 dbmanage.populate_default_permissions() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
536 |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
537 #PART TWO make test repo |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
538 log.debug('making test vcs repositories') |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
539 |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
540 #remove old one from previos tests |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
541 for r in [HG_REPO, GIT_REPO, NEW_HG_REPO, NEW_GIT_REPO, HG_FORK, GIT_FORK]: |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
542 |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
543 if os.path.isdir(jn(TESTS_TMP_PATH, r)): |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
544 log.debug('removing %s', r) |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
545 shutil.rmtree(jn(TESTS_TMP_PATH, r)) |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
546 |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
547 #CREATE DEFAULT HG REPOSITORY |
491
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
548 cur_dir = dn(dn(abspath(__file__))) |
688
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
549 tar = tarfile.open(jn(cur_dir, 'tests', "vcs_test_hg.tar.gz")) |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
550 tar.extractall(jn(TESTS_TMP_PATH, HG_REPO)) |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
551 tar.close() |
684
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
552 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
553 class UpgradeDb(command.Command): |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
554 """Command used for paster to upgrade our database to newer version |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
555 """ |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
556 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
557 max_args = 1 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
558 min_args = 1 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
559 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
560 usage = "CONFIG_FILE" |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
561 summary = "Upgrades current db to newer version given configuration file" |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
562 group_name = "RhodeCode" |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
563 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
564 parser = command.Command.standard_parser(verbose=True) |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
565 |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
566 parser.add_option('--sql', |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
567 action='store_true', |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
568 dest='just_sql', |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
569 help="Prints upgrade sql for further investigation", |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
570 default=False) |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
571 def command(self): |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
572 config_name = self.args[0] |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
573 p = config_name.split('/') |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
574 root = '.' if len(p) == 1 else '/'.join(p[:-1]) |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
575 config = ConfigParser.ConfigParser({'here':root}) |
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
576 config.read(config_name) |