Mercurial > kallithea
annotate rhodecode/lib/utils.py @ 1039:51b70569c330 beta
extended admin rescan to show what repositories was added and what removed
fixed found bugs, added expunge to cached getter since it introduce some more problems.
Added some relationship to properly clean related objects from database.
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Sun, 13 Feb 2011 01:38:39 +0100 |
parents | 2e9f2bd28143 |
children | bc3dafd0e24c |
rev | line source |
---|---|
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
1 # -*- coding: utf-8 -*- |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
2 """ |
833
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
807
diff
changeset
|
3 rhodecode.lib.utils |
9753e0907827
added dbmigrate package, added model changes
Marcin Kuzminski <marcin@python-works.com>
parents:
807
diff
changeset
|
4 ~~~~~~~~~~~~~~~~~~~ |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
5 |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
6 Utilities library for RhodeCode |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
7 |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
8 :created_on: Apr 18, 2010 |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
9 :author: marcink |
902
07a6e8c65526
fixed copyright year to 2011
Marcin Kuzminski <marcin@python-works.com>
parents:
878
diff
changeset
|
10 :copyright: (C) 2009-2011 Marcin Kuzminski <marcin@python-works.com> |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
11 :license: GPLv3, see COPYING for more details. |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
12 """ |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
13 # 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
|
14 # 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
|
15 # as published by the Free Software Foundation; version 2 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
16 # 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
|
17 # |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
18 # 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
|
19 # 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
|
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
21 # GNU General Public License for more details. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
22 # |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
23 # 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
|
24 # 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
|
25 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
26 # MA 02110-1301, USA. |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
27 |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
28 import os |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
29 import logging |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
30 import datetime |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
31 import traceback |
1022
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
32 import paste |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
33 import beaker |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
34 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
35 from paste.script.command import Command, BadCommand |
633
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
36 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
37 from UserDict import DictMixin |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
38 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
39 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
|
40 from mercurial.error import RepoError |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
41 |
1022
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
42 from webhelpers.text import collapse, remove_formatting, strip_tags |
785
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
43 |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
44 from vcs.backends.base import BaseChangeset |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
45 from vcs.utils.lazy import LazyProperty |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
46 |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
47 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
|
48 from rhodecode.model.caching_query import FromCache |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
49 from rhodecode.model.db import Repository, User, RhodeCodeUi, UserLog, Group |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
50 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
|
51 from rhodecode.model.user import UserModel |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
52 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
53 log = logging.getLogger(__name__) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
54 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
55 |
1022
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
56 def recursive_replace(str, replace=' '): |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
57 """Recursive replace of given sign to just one instance |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
58 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
59 :param str: given string |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
60 :param replace: char to find and replace multiple instances |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
61 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
62 Examples:: |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
63 >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-') |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
64 'Mighty-Mighty-Bo-sstones' |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
65 """ |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
66 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
67 if str.find(replace * 2) == -1: |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
68 return str |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
69 else: |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
70 str = str.replace(replace * 2, replace) |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
71 return recursive_replace(str, replace) |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
72 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
73 def repo_name_slug(value): |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
74 """Return slug of name of repository |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
75 This function is called on each creation/modification |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
76 of repository to prevent bad names in repo |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
77 """ |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
78 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
79 slug = remove_formatting(value) |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
80 slug = strip_tags(slug) |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
81 |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
82 for c in """=[]\;'"<>,/~!@#$%^&*()+{}|: """: |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
83 slug = slug.replace(c, '-') |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
84 slug = recursive_replace(slug, '-') |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
85 slug = collapse(slug, '-') |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
86 return slug |
4f834b0abcd3
Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents:
1007
diff
changeset
|
87 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
88 def get_repo_slug(request): |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
89 return request.environ['pylons.routes_dict'].get('repo_name') |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
90 |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
91 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
|
92 """ |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
93 Action logger for various actions 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
|
94 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
95 :param user: user that made this action, can be a unique username string or |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
96 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
|
97 :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
|
98 easy translations |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
99 :param repo: string name of repository or object containing repo_id, |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
100 that action was made on |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
101 :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
|
102 :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
|
103 |
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
|
104 """ |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
105 |
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
|
106 if not sa: |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
107 sa = meta.Session() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
108 |
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 try: |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
110 um = UserModel() |
537
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
111 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
|
112 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
|
113 elif isinstance(user, basestring): |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
114 user_obj = um.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
|
115 else: |
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
116 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
|
117 |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
118 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
119 rm = RepoModel() |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
120 if hasattr(repo, 'repo_id'): |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
121 repo_obj = rm.get(repo.repo_id, cache=False) |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
122 repo_name = repo_obj.repo_name |
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
123 elif isinstance(repo, basestring): |
689
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
124 repo_name = repo.lstrip('/') |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
125 repo_obj = rm.get_by_repo_name(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
|
126 else: |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
127 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
|
128 |
ecc566f8b69f
fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents:
688
diff
changeset
|
129 |
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
|
130 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
|
131 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
|
132 user_log.action = action |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
133 |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
134 user_log.repository_id = repo_obj.repo_id |
537
48be953851fc
extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents:
536
diff
changeset
|
135 user_log.repository_name = repo_name |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
136 |
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
|
137 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
|
138 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
|
139 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
|
140 sa.commit() |
621
9893c2fc846b
removed raise from log user action
Marcin Kuzminski <marcin@python-works.com>
parents:
604
diff
changeset
|
141 |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
142 log.info('Adding user %s, action %s on %s', user_obj, action, repo) |
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
|
143 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
|
144 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
|
145 sa.rollback() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
146 |
877
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
147 def get_repos(path, recursive=False): |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
148 """ |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
149 Scans given path for repos and return (name,(type,path)) tuple |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
150 |
877
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
151 :param path: path to scann for repositories |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
152 :param recursive: recursive search and return names with subdirs in front |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
153 """ |
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
154 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
|
155 from vcs.exceptions import VCSError |
633
fcf599cd3404
Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents:
631
diff
changeset
|
156 |
877
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
157 if path.endswith('/'): |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
158 #add ending slash for better results |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
159 path = path[:-1] |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
160 |
877
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
161 def _get_repos(p): |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
162 for dirpath in os.listdir(p): |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
163 if os.path.isfile(os.path.join(p, dirpath)): |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
164 continue |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
165 cur_path = os.path.join(p, dirpath) |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
166 try: |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
167 scm_info = get_scm(cur_path) |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
168 yield scm_info[1].split(path)[-1].lstrip('/'), scm_info |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
169 except VCSError: |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
170 if not recursive: |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
171 continue |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
172 #check if this dir containts other repos for recursive scan |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
173 rec_path = os.path.join(p, dirpath) |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
174 if os.path.isdir(rec_path): |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
175 for inner_scm in _get_repos(rec_path): |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
176 yield inner_scm |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
177 |
bc9a73adc216
Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents:
860
diff
changeset
|
178 return _get_repos(path) |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
179 |
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
|
180 def check_repo_fast(repo_name, base_path): |
761
56c2850a5b5f
ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
181 """ |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
182 Check given path for existence of directory |
761
56c2850a5b5f
ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
183 :param repo_name: |
56c2850a5b5f
ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
184 :param base_path: |
56c2850a5b5f
ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
185 |
56c2850a5b5f
ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
186 :return False: if this directory is present |
56c2850a5b5f
ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents:
756
diff
changeset
|
187 """ |
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
|
188 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
|
189 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
|
190 |
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
|
191 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
|
192 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
193 repo_path = os.path.join(base_path, repo_name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
194 |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
195 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
|
196 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
|
197 return False |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
198 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
|
199 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
|
200 hg.verify(r) |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
201 #here we hnow that repo exists it was verified |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
202 log.info('%s repo is already created', repo_name) |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
203 return False |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
204 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
|
205 #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
|
206 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
|
207 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
|
208 |
351
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
209 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
|
210 while True: |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
211 ok = raw_input(prompt) |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
212 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
|
213 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
|
214 retries = retries - 1 |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
215 if retries < 0: raise IOError |
d09381593b12
updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents:
350
diff
changeset
|
216 print complaint |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
217 |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
218 #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
|
219 ui_sections = ['alias', 'auth', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
220 'decode/encode', 'defaults', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
221 'diff', 'email', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
222 'extensions', 'format', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
223 'merge-patterns', 'merge-tools', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
224 'hooks', 'http_proxy', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
225 'smtp', 'patch', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
226 'paths', 'profiling', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
227 'server', 'trusted', |
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
228 'ui', 'web', ] |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
229 |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
230 def make_ui(read_from='file', path=None, checkpaths=True): |
930
f9016563f987
Added sql session into test hg script
Marcin Kuzminski <marcin@python-works.com>
parents:
902
diff
changeset
|
231 """A function that will read python rc files or database |
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
|
232 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
|
233 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
234 :param path: path to mercurial config file |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
235 :param checkpaths: check the path |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
236 :param read_from: read from 'file' or 'db' |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
237 """ |
386
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
238 |
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
|
239 baseui = ui.ui() |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
240 |
724
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
241 #clean the baseui object |
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
242 baseui._ocfg = config.config() |
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
243 baseui._ucfg = config.config() |
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
244 baseui._tcfg = config.config() |
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
245 |
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
|
246 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
|
247 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
|
248 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
|
249 return False |
388
3bcf9529d221
Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents:
386
diff
changeset
|
250 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
|
251 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
|
252 cfg.read(path) |
386
a9a607a58b1c
moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents:
381
diff
changeset
|
253 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
|
254 for k, v in cfg.items(section): |
724
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
255 log.debug('settings ui from file[%s]%s:%s', section, 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
|
256 baseui.setconfig(section, k, v) |
724
a9bc513a1fe3
fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents:
692
diff
changeset
|
257 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
258 |
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
|
259 elif read_from == 'db': |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
260 sa = meta.Session() |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
261 ret = sa.query(RhodeCodeUi)\ |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
262 .options(FromCache("sql_cache_short", |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
263 "get_hg_ui_settings")).all() |
773
876776983c3c
disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
264 |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
265 hg_ui = ret |
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
|
266 for ui_ in hg_ui: |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
388
diff
changeset
|
267 if ui_.ui_active: |
773
876776983c3c
disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
268 log.debug('settings ui from db[%s]%s:%s', ui_.ui_section, |
876776983c3c
disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
269 ui_.ui_key, ui_.ui_value) |
392
b27d32cb3157
Implemented hooks system,
Marcin Kuzminski <marcin@python-works.com>
parents:
388
diff
changeset
|
270 baseui.setconfig(ui_.ui_section, ui_.ui_key, ui_.ui_value) |
773
876776983c3c
disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
271 |
876776983c3c
disabled dotencode format for mercurial 1.7 usage and hg <=1.6 compatibility
Marcin Kuzminski <marcin@python-works.com>
parents:
761
diff
changeset
|
272 meta.Session.remove() |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
273 return baseui |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
274 |
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 |
548
b75b77ef649d
renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
547
diff
changeset
|
276 def set_rhodecode_config(config): |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
277 """Updates pylons config with new settings from database |
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
278 |
756
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
279 :param config: |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
280 """ |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
281 from rhodecode.model.settings import SettingsModel |
01be209b9828
project refactoring, cleaned up lib.utils from rarly used functions, and place them
Marcin Kuzminski <marcin@python-works.com>
parents:
735
diff
changeset
|
282 hgsettings = SettingsModel().get_app_settings() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
283 |
381
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
284 for k, v in hgsettings.items(): |
55377fdc1fc6
cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents:
367
diff
changeset
|
285 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
|
286 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
287 def invalidate_cache(cache_key, *args): |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
288 """Puts cache invalidation task into db for |
665
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
289 further global cache invalidation |
070f32743632
Moved out reposcan into hg Model.
Marcin Kuzminski <marcin@python-works.com>
parents:
659
diff
changeset
|
290 """ |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
291 |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
292 from rhodecode.model.scm import ScmModel |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
293 |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
294 if cache_key.startswith('get_repo_cached_'): |
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
295 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
|
296 ScmModel().mark_for_invalidation(name) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
297 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
298 class EmptyChangeset(BaseChangeset): |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
299 """ |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
300 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
|
301 an EmptyChangeset |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
302 """ |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
303 |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
304 def __init__(self, cs='0' * 40): |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
305 self._empty_cs = cs |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
306 self.revision = -1 |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
307 self.message = '' |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
308 self.author = '' |
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
309 self.date = '' |
636
ffd07396d315
Fixes for raw_id, needed for git
Marcin Kuzminski <marcin@python-works.com>
parents:
633
diff
changeset
|
310 |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
311 @LazyProperty |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
312 def raw_id(self): |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
313 """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
|
314 representation. |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
315 """ |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
316 |
643
9dc1d92d82ed
updated setup for all newest versions
Marcin Kuzminski <marcin@python-works.com>
parents:
636
diff
changeset
|
317 return self._empty_cs |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
318 |
524
63212fea2471
a lot of fixes in templates,
Marcin Kuzminski <marcin@python-works.com>
parents:
520
diff
changeset
|
319 @LazyProperty |
520
eda96fb85ba7
dohh !! fixed EmptyCHangeset for new vcs
Marcin Kuzminski <marcin@python-works.com>
parents:
497
diff
changeset
|
320 def short_id(self): |
524
63212fea2471
a lot of fixes in templates,
Marcin Kuzminski <marcin@python-works.com>
parents:
520
diff
changeset
|
321 return self.raw_id[:12] |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
322 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
323 def get_file_changeset(self, path): |
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
324 return self |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
325 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
326 def get_file_content(self, path): |
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
327 return u'' |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
328 |
544
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
329 def get_file_size(self, path): |
d8778cde98f0
added limits to single file diffs
Marcin Kuzminski <marcin@python-works.com>
parents:
537
diff
changeset
|
330 return 0 |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
331 |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
332 def map_groups(groups): |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
333 """Checks for groups existence, and creates groups structures. |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
334 It returns last group in structure |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
335 |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
336 :param groups: list of groups structure |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
337 """ |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
338 sa = meta.Session() |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
339 |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
340 parent = None |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
341 group = None |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
342 for lvl, group_name in enumerate(groups[:-1]): |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
343 group = sa.query(Group).filter(Group.group_name == group_name).scalar() |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
344 |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
345 if group is None: |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
346 group = Group(group_name, parent) |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
347 sa.add(group) |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
348 sa.commit() |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
349 |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
350 parent = group |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
351 |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
352 return group |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
353 |
348
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
354 def repo2db_mapper(initial_repo_list, remove_obsolete=False): |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
355 """maps all repos given in initial_repo_list, non existing repositories |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
356 are created, if remove_obsolete is True it also check for db entries |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
357 that are not in initial_repo_list and removes them. |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
358 |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
359 :param initial_repo_list: list of repositories found by scanning methods |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
360 :param remove_obsolete: check for obsolete entries in database |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
361 """ |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
362 |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
363 sa = meta.Session() |
692
cb0d9ce6ac5c
#50 on point cache invalidation changes.
Marcin Kuzminski <marcin@python-works.com>
parents:
689
diff
changeset
|
364 rm = RepoModel() |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
365 user = sa.query(User).filter(User.admin == True).first() |
1039
51b70569c330
extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents:
1032
diff
changeset
|
366 added = [] |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
367 for name, repo in initial_repo_list.items(): |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
368 group = map_groups(name.split('/')) |
735
dbec976d9975
added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents:
724
diff
changeset
|
369 if not rm.get_by_repo_name(name, cache=False): |
631
05528ad948c4
Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents:
629
diff
changeset
|
370 log.info('repository %s not found creating default', name) |
1039
51b70569c330
extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents:
1032
diff
changeset
|
371 added.append(name) |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
372 form_data = { |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
373 'repo_name':name, |
652
37dc1e8d84d8
changed repo type to use alias
Marcin Kuzminski <marcin@python-works.com>
parents:
643
diff
changeset
|
374 '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
|
375 '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
|
376 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
|
377 '%s repository' % name, |
878
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
378 'private':False, |
859bc9e7a15d
Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents:
877
diff
changeset
|
379 'group_id':getattr(group, 'group_id', None) |
297
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
380 } |
a074dec6ee40
restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents:
295
diff
changeset
|
381 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
|
382 |
1039
51b70569c330
extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents:
1032
diff
changeset
|
383 removed = [] |
348
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
384 if remove_obsolete: |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
385 #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
|
386 for repo in sa.query(Repository).all(): |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
387 if repo.repo_name not in initial_repo_list.keys(): |
1039
51b70569c330
extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents:
1032
diff
changeset
|
388 removed.append(repo.repo_name) |
348
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
389 sa.delete(repo) |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
390 sa.commit() |
e8fc875467bd
implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents:
345
diff
changeset
|
391 |
1039
51b70569c330
extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents:
1032
diff
changeset
|
392 return added, removed |
358
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
393 class OrderedDict(dict, DictMixin): |
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 __init__(self, *args, **kwds): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
396 if len(args) > 1: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
397 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
|
398 try: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
399 self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
400 except AttributeError: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
401 self.clear() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
402 self.update(*args, **kwds) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
403 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
404 def clear(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
405 self.__end = end = [] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
406 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
|
407 self.__map = {} # key --> [key, prev, next] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
408 dict.clear(self) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
409 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
410 def __setitem__(self, key, value): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
411 if key not in self: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
412 end = self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
413 curr = end[1] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
414 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
|
415 dict.__setitem__(self, key, value) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
416 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
417 def __delitem__(self, key): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
418 dict.__delitem__(self, key) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
419 key, prev, next = self.__map.pop(key) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
420 prev[2] = next |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
421 next[1] = prev |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
422 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
423 def __iter__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
424 end = self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
425 curr = end[2] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
426 while curr is not end: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
427 yield curr[0] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
428 curr = curr[2] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
429 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
430 def __reversed__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
431 end = self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
432 curr = end[1] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
433 while curr is not end: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
434 yield curr[0] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
435 curr = curr[1] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
436 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
437 def popitem(self, last=True): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
438 if not self: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
439 raise KeyError('dictionary is empty') |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
440 if last: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
441 key = reversed(self).next() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
442 else: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
443 key = iter(self).next() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
444 value = self.pop(key) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
445 return key, value |
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 __reduce__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
448 items = [[k, self[k]] for k in self] |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
449 tmp = self.__map, self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
450 del self.__map, self.__end |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
451 inst_dict = vars(self).copy() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
452 self.__map, self.__end = tmp |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
453 if inst_dict: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
454 return (self.__class__, (items,), inst_dict) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
455 return self.__class__, (items,) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
456 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
457 def keys(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
458 return list(self) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
459 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
460 setdefault = DictMixin.setdefault |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
461 update = DictMixin.update |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
462 pop = DictMixin.pop |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
463 values = DictMixin.values |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
464 items = DictMixin.items |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
465 iterkeys = DictMixin.iterkeys |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
466 itervalues = DictMixin.itervalues |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
467 iteritems = DictMixin.iteritems |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
468 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
469 def __repr__(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
470 if not self: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
471 return '%s()' % (self.__class__.__name__,) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
472 return '%s(%r)' % (self.__class__.__name__, self.items()) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
473 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
474 def copy(self): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
475 return self.__class__(self) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
476 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
477 @classmethod |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
478 def fromkeys(cls, iterable, value=None): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
479 d = cls() |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
480 for key in iterable: |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
481 d[key] = value |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
482 return d |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
483 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
484 def __eq__(self, other): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
485 if isinstance(other, OrderedDict): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
486 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
|
487 return dict.__eq__(self, other) |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
488 |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
489 def __ne__(self, other): |
23e720be5f44
Added implementation of Ordered Dict.
Marcin Kuzminski <marcin@python-works.com>
parents:
351
diff
changeset
|
490 return not self == other |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
491 |
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
|
492 |
785
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
493 #set cache regions for beaker so celery can utilise it |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
494 def add_cache(settings): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
495 cache_settings = {'regions':None} |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
496 for key in settings.keys(): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
497 for prefix in ['beaker.cache.', 'cache.']: |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
498 if key.startswith(prefix): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
499 name = key.split(prefix)[1].strip() |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
500 cache_settings[name] = settings[key].strip() |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
501 if cache_settings['regions']: |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
502 for region in cache_settings['regions'].split(','): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
503 region = region.strip() |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
504 region_settings = {} |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
505 for key, value in cache_settings.items(): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
506 if key.startswith(region): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
507 region_settings[key.split('.')[1]] = value |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
508 region_settings['expire'] = int(region_settings.get('expire', |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
509 60)) |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
510 region_settings.setdefault('lock_dir', |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
511 cache_settings.get('lock_dir')) |
1032
2e9f2bd28143
fixed add cache defaults missing data_dir
Marcin Kuzminski <marcin@python-works.com>
parents:
1022
diff
changeset
|
512 region_settings.setdefault('data_dir', |
2e9f2bd28143
fixed add cache defaults missing data_dir
Marcin Kuzminski <marcin@python-works.com>
parents:
1022
diff
changeset
|
513 cache_settings.get('data_dir')) |
2e9f2bd28143
fixed add cache defaults missing data_dir
Marcin Kuzminski <marcin@python-works.com>
parents:
1022
diff
changeset
|
514 |
785
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
515 if 'type' not in region_settings: |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
516 region_settings['type'] = cache_settings.get('type', |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
517 'memory') |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
518 beaker.cache.cache_regions[region] = region_settings |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
519 |
807
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
520 def get_current_revision(): |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
521 """Returns tuple of (number, id) from repository containing this package |
807
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
522 or None if repository could not be found. |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
523 """ |
860
5f7731e3ab4d
fixed spelling mistakes, and some minor docs bugs
Marcin Kuzminski <marcin@python-works.com>
parents:
837
diff
changeset
|
524 |
807
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
525 try: |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
526 from vcs import get_repo |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
527 from vcs.utils.helpers import get_scm |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
528 from vcs.exceptions import RepositoryError, VCSError |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
529 repopath = os.path.join(os.path.dirname(__file__), '..', '..') |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
530 scm = get_scm(repopath)[0] |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
531 repo = get_repo(path=repopath, alias=scm) |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
532 tip = repo.get_changeset() |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
533 return (tip.revision, tip.short_id) |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
534 except (ImportError, RepositoryError, VCSError), err: |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
535 logging.debug("Cannot retrieve rhodecode's revision. Original error " |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
536 "was: %s" % err) |
e8c9ff1da9ba
added revision into version for beta
Marcin Kuzminski <marcin@python-works.com>
parents:
785
diff
changeset
|
537 return None |
785
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
538 |
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
|
539 #=============================================================================== |
629
7e536d1af60d
Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents:
621
diff
changeset
|
540 # 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
|
541 #=============================================================================== |
fefffd6fd5f4
Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents:
489
diff
changeset
|
542 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
|
543 """Makes default test index |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
544 :param repo_location: |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
545 :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
|
546 """ |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
544
diff
changeset
|
547 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon |
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
544
diff
changeset
|
548 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
|
549 import shutil |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
550 |
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
|
551 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
|
552 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
|
553 shutil.rmtree(index_location) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
554 |
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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 .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
|
560 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
|
561 except LockHeld: |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
562 pass |
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
563 |
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
|
564 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
|
565 """Makes a fresh database and |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
566 install test repository into tmp dir |
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
567 """ |
547
1e757ac98988
renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents:
544
diff
changeset
|
568 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
|
569 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
|
570 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
|
571 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
|
572 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
|
573 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
|
574 |
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
|
575 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
|
576 # 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
|
577 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
|
578 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
|
579 # 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
|
580 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
|
581 ch.setLevel(logging.DEBUG) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
582 |
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
|
583 # 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
|
584 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
|
585 |
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
|
586 # 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
|
587 ch.setFormatter(formatter) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
588 |
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
|
589 # 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
|
590 log.addHandler(ch) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
591 |
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
|
592 #PART ONE create db |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
593 dbconf = config['sqlalchemy.db1.url'] |
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
594 log.debug('making test db %s', dbconf) |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
595 |
783
71113f64b2d8
fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents:
773
diff
changeset
|
596 dbmanage = DbManage(log_sql=True, dbconf=dbconf, root=config['here'], |
552
2642f128ad46
removed egg info, update files for distutils build
Marcin Kuzminski <marcin@python-works.com>
parents:
549
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 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
|
603 dbmanage.populate_default_permissions() |
604
5cc96df705b9
fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents:
569
diff
changeset
|
604 |
473
6b934c9607e7
Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents:
395
diff
changeset
|
605 #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
|
606 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
|
607 |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
608 #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
|
609 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
|
610 |
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
|
611 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
|
612 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
|
613 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
|
614 |
8acbfa837180
Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents:
684
diff
changeset
|
615 #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
|
616 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
|
617 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
|
618 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
|
619 tar.close() |
684
2abb398cd9a7
upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents:
665
diff
changeset
|
620 |
785
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
621 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
622 #============================================================================== |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
623 # PASTER COMMANDS |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
624 #============================================================================== |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
625 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
626 class BasePasterCommand(Command): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
627 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
628 Abstract Base Class for paster commands. |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
629 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
630 The celery commands are somewhat aggressive about loading |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
631 celery.conf, and since our module sets the `CELERY_LOADER` |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
632 environment variable to our loader, we have to bootstrap a bit and |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
633 make sure we've had a chance to load the pylons config off of the |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
634 command line, otherwise everything fails. |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
635 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
636 min_args = 1 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
637 min_args_error = "Please provide a paster config file as an argument." |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
638 takes_config_file = 1 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
639 requires_config_file = True |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
640 |
837
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
641 def notify_msg(self, msg, log=False): |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
642 """Make a notification to user, additionally if logger is passed |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
643 it logs this action using given logger |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
644 |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
645 :param msg: message that will be printed to user |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
646 :param log: logging instance, to use to additionally log this message |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
647 |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
648 """ |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
649 if log and isinstance(log, logging): |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
650 log(msg) |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
651 |
60cbde084047
fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents:
833
diff
changeset
|
652 |
785
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
653 def run(self, args): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
654 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
655 Overrides Command.run |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
656 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
657 Checks for a config file argument and loads it. |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
658 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
659 if len(args) < self.min_args: |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
660 raise BadCommand( |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
661 self.min_args_error % {'min_args': self.min_args, |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
662 'actual_args': len(args)}) |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
663 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
664 # Decrement because we're going to lob off the first argument. |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
665 # @@ This is hacky |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
666 self.min_args -= 1 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
667 self.bootstrap_config(args[0]) |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
668 self.update_parser() |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
669 return super(BasePasterCommand, self).run(args[1:]) |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
670 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
671 def update_parser(self): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
672 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
673 Abstract method. Allows for the class's parser to be updated |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
674 before the superclass's `run` method is called. Necessary to |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
675 allow options/arguments to be passed through to the underlying |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
676 celery command. |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
677 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
678 raise NotImplementedError("Abstract Method.") |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
679 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
680 def bootstrap_config(self, conf): |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
681 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
682 Loads the pylons configuration. |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
683 """ |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
684 from pylons import config as pylonsconfig |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
685 |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
686 path_to_ini_file = os.path.realpath(conf) |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
687 conf = paste.deploy.appconfig('config:' + path_to_ini_file) |
277427ac29a9
complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents:
783
diff
changeset
|
688 pylonsconfig.init_app(conf.global_conf, conf.local_conf) |