annotate rhodecode/lib/utils.py @ 4147:1c8f818787b3 rhodecode-2.2.5-gpl

old style: show the full link box on summary page - no overlap or truncation
author Mads Kiilerich <madski@unity3d.com>
date Wed, 02 Jul 2014 19:03:23 -0400
parents ffd45b185016
children 7e5f8c12a3fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 -*-
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
2 # This program is free software: you can redistribute it and/or modify
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
3 # it under the terms of the GNU General Public License as published by
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
4 # the Free Software Foundation, either version 3 of the License, or
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
5 # (at your option) any later version.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
6 #
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
7 # 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
8 # 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
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
10 # GNU General Public License for more details.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
11 #
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
12 # You should have received a copy of the GNU General Public License
1206
a671db5bdd58 fixed license issue #149
Marcin Kuzminski <marcin@python-works.com>
parents: 1203
diff changeset
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
14 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
15 rhodecode.lib.utils
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
16 ~~~~~~~~~~~~~~~~~~~
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
17
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
18 Utilities library for RhodeCode
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
19
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
20 :created_on: Apr 18, 2010
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
21 :author: marcink
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
22 :copyright: (c) 2013 RhodeCode GmbH.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
23 :license: GPLv3, see LICENSE for more details.
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
24 """
783
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
25
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
26 import os
2069
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
27 import re
783
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
28 import logging
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
29 import datetime
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
30 import traceback
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
31 import paste
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
32 import beaker
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
33 import tarfile
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
34 import shutil
3061
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
35 import decorator
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
36 import warnings
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
37 from os.path import abspath
1354
ed309b1fbaa4 fixes issue #197 Relative paths for pidlocks
Marcin Kuzminski <marcin@python-works.com>
parents: 1337
diff changeset
38 from os.path import dirname as dn, join as jn
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
39
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
40 from paste.script.command import Command, BadCommand
633
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
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
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
43 from beaker.cache import _cache_decorate
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
44
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1991
diff changeset
45 from rhodecode.lib.vcs import get_backend
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1991
diff changeset
46 from rhodecode.lib.vcs.backends.base import BaseChangeset
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1991
diff changeset
47 from rhodecode.lib.vcs.utils.lazy import LazyProperty
3941
3208aaefc9ca Moved all Mercurial imports into hgcompat from vcs
Marcin Kuzminski <marcin@python-works.com>
parents: 3888
diff changeset
48 from rhodecode.lib.vcs.utils.hgcompat import ui, config
2007
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1991
diff changeset
49 from rhodecode.lib.vcs.utils.helpers import get_scm
324ac367a4da Added VCS into rhodecode core for faster and easier deployments of new versions
Marcin Kuzminski <marcin@python-works.com>
parents: 1991
diff changeset
50 from rhodecode.lib.vcs.exceptions import VCSError
783
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
51
1669
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
52 from rhodecode.lib.caching_query import FromCache
f522f4d3bf93 moved caching query to libs
Marcin Kuzminski <marcin@python-works.com>
parents: 1634
diff changeset
53
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
54 from rhodecode.model import meta
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
55 from rhodecode.model.db import Repository, User, RhodeCodeUi, \
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
56 UserLog, RepoGroup, RhodeCodeSetting, CacheInvalidation, UserGroup
1734
48d4fcf04a29 another major refactoring with session management
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
57 from rhodecode.model.meta import Session
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
58 from rhodecode.model.repo_group import RepoGroupModel
4012
55dbc440878b Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents: 4001
diff changeset
59 from rhodecode.lib.utils2 import safe_str, safe_unicode, get_current_rhodecode_user
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
60 from rhodecode.lib.vcs.utils.fakemod import create_module
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
61 from rhodecode.model.user_group import UserGroupModel
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
62
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
63 log = logging.getLogger(__name__)
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
64
2069
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
65 REMOVED_REPO_PAT = re.compile(r'rm__\d{8}_\d{6}_\d{6}__.*')
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
66
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
67
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
68 def recursive_replace(str_, replace=' '):
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
69 """
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
70 Recursive replace of given sign to just one instance
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
71
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
72 :param str_: given string
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
73 :param replace: char to find and replace multiple instances
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
74
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
75 Examples::
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
76 >>> recursive_replace("Mighty---Mighty-Bo--sstones",'-')
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
77 'Mighty-Mighty-Bo-sstones'
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
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
80 if str_.find(replace * 2) == -1:
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
81 return str_
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
82 else:
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
83 str_ = str_.replace(replace * 2, replace)
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
84 return recursive_replace(str_, replace)
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
85
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
86
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
87 def repo_name_slug(value):
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
88 """
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
89 Return slug of name of repository
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
90 This function is called on each creation/modification
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
91 of repository to prevent bad names in repo
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
92 """
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
93
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
94 slug = remove_formatting(value)
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
95 slug = strip_tags(slug)
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
96
2786
ffaaeb5a5a69 Filter more special chars in validation of repo name
Marcin Kuzminski <marcin@python-works.com>
parents: 2717
diff changeset
97 for c in """`?=[]\;'"<>,/~!@#$%^&*()+{}|: """:
1022
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
98 slug = slug.replace(c, '-')
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
99 slug = recursive_replace(slug, '-')
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
100 slug = collapse(slug, '-')
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
101 return slug
4f834b0abcd3 Code refactor number 2
Marcin Kuzminski <marcin@python-works.com>
parents: 1007
diff changeset
102
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
103
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
104 #==============================================================================
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
105 # PERM DECORATOR HELPERS FOR EXTRACTING NAMES FOR PERM CHECKS
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
106 #==============================================================================
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
107 def get_repo_slug(request):
2055
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
108 _repo = request.environ['pylons.routes_dict'].get('repo_name')
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
109 if _repo:
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
110 _repo = _repo.rstrip('/')
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
111 return _repo
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
112
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
113
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
114 def get_repo_group_slug(request):
2055
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
115 _group = request.environ['pylons.routes_dict'].get('group_name')
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
116 if _group:
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
117 _group = _group.rstrip('/')
c8a8684efc74 fixed issue #370
Marcin Kuzminski <marcin@python-works.com>
parents: 2019
diff changeset
118 return _group
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
119
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
120
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
121 def get_user_group_slug(request):
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
122 _group = request.environ['pylons.routes_dict'].get('id')
3734
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
123 try:
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
124 _group = UserGroup.get(_group)
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
125 if _group:
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
126 _group = _group.users_group_name
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
127 except Exception:
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
128 log.debug(traceback.format_exc())
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
129 #catch all failures here
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
130 pass
a8f520540ab0 New default permissions definition for user group create
Marcin Kuzminski <marcin@python-works.com>
parents: 3714
diff changeset
131
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
132 return _group
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
133
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
134
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
135 def _extract_id_from_repo_name(repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
136 if repo_name.startswith('/'):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
137 repo_name = repo_name.lstrip('/')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
138 by_id_match = re.match(r'^_(\d{1,})', repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
139 if by_id_match:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
140 return by_id_match.groups()[0]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
141
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
142
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
143 def get_repo_by_id(repo_name):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
144 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
145 Extracts repo_name by id from special urls. Example url is _11/repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
146
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
147 :param repo_name:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
148 :return: repo_name if matched else None
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
149 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
150 try:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
151 _repo_id = _extract_id_from_repo_name(repo_name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
152 if _repo_id:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
153 from rhodecode.model.db import Repository
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
154 return Repository.get(_repo_id).repo_name
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
155 except Exception:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
156 log.debug('Failed to extract repo_name from URL %s' % (
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
157 traceback.format_exc()))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
158 return
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
159
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
160
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
161 def action_logger(user, action, repo, ipaddr='', sa=None, commit=False):
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
162 """
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
163 Action logger for various actions made by users
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
164
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
165 :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
166 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
167 :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
168 easy translations
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
169 :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
170 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
171 :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
172 :param sa: optional sqlalchemy session
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
173
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
174 """
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
175
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
176 if not sa:
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
177 sa = meta.Session()
4001
5ee341209d7f action logger will try to get IP address automatically based
Marcin Kuzminski <marcin@python-works.com>
parents: 3981
diff changeset
178 # if we don't get explicit IP address try to get one from registered user
5ee341209d7f action logger will try to get IP address automatically based
Marcin Kuzminski <marcin@python-works.com>
parents: 3981
diff changeset
179 # in tmpl context var
4012
55dbc440878b Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents: 4001
diff changeset
180 if not ipaddr:
55dbc440878b Fixed bug with log_delete hook didn't properly store
Marcin Kuzminski <marcin@python-works.com>
parents: 4001
diff changeset
181 ipaddr = getattr(get_current_rhodecode_user(), 'ip_addr', '')
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
182
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
183 try:
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
184 if getattr(user, 'user_id', None):
3063
ca2b21819dfd Implemented better support for Wildcard queries
Marcin Kuzminski <marcin@python-works.com>
parents: 3061
diff changeset
185 user_obj = User.get(user.user_id)
537
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 536
diff changeset
186 elif isinstance(user, basestring):
1530
04027bdb876c Refactoring of model get functions
Marcin Kuzminski <marcin@python-works.com>
parents: 1528
diff changeset
187 user_obj = User.get_by_username(user)
537
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 536
diff changeset
188 else:
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
189 raise Exception('You have to provide a user object or a username')
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
190
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
191 if getattr(repo, 'repo_id', None):
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
192 repo_obj = Repository.get(repo.repo_id)
735
dbec976d9975 added action loggers to following repositories,
Marcin Kuzminski <marcin@python-works.com>
parents: 724
diff changeset
193 repo_name = repo_obj.repo_name
4001
5ee341209d7f action logger will try to get IP address automatically based
Marcin Kuzminski <marcin@python-works.com>
parents: 3981
diff changeset
194 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
195 repo_name = repo.lstrip('/')
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
196 repo_obj = Repository.get_by_repo_name(repo_name)
689
ecc566f8b69f fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents: 688
diff changeset
197 else:
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2249
diff changeset
198 repo_obj = None
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2249
diff changeset
199 repo_name = ''
689
ecc566f8b69f fixes #59, notifications for user registrations + some changes to mailer
Marcin Kuzminski <marcin@python-works.com>
parents: 688
diff changeset
200
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
201 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
202 user_log.user_id = user_obj.user_id
3063
ca2b21819dfd Implemented better support for Wildcard queries
Marcin Kuzminski <marcin@python-works.com>
parents: 3061
diff changeset
203 user_log.username = user_obj.username
2249
a3eb31cc4ab4 fixed UnicodeWarning on pushing from sqlalchemy
Marcin Kuzminski <marcin@python-works.com>
parents: 2147
diff changeset
204 user_log.action = safe_unicode(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
205
2375
bc2d8c03c050 Implemented #467 Journal logs comments on changesets
Marcin Kuzminski <marcin@python-works.com>
parents: 2249
diff changeset
206 user_log.repository = repo_obj
537
48be953851fc extended user logs to create/delete/fork repositories for auditing
Marcin Kuzminski <marcin@python-works.com>
parents: 536
diff changeset
207 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
208
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
209 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
210 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
211 sa.add(user_log)
621
9893c2fc846b removed raise from log user action
Marcin Kuzminski <marcin@python-works.com>
parents: 604
diff changeset
212
3545
e2fad0c6b19a better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 3458
diff changeset
213 log.info('Logging action:%s on %s by user:%s ip:%s' %
e2fad0c6b19a better logging
Marcin Kuzminski <marcin@python-works.com>
parents: 3458
diff changeset
214 (action, safe_unicode(repo), user_obj, ipaddr))
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
215 if commit:
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
216 sa.commit()
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3607
diff changeset
217 except Exception:
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
218 log.error(traceback.format_exc())
1722
e7eef7a1db6a #235 forking page repo group selection
Marcin Kuzminski <marcin@python-works.com>
parents: 1717
diff changeset
219 raise
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
220
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
221
3649
24e24661c0eb util: remove attempt of renaming get_filesystem_repos while remaining backward compatible
Mads Kiilerich <madski@unity3d.com>
parents: 3631
diff changeset
222 def get_filesystem_repos(path, recursive=False, skip_removed_repos=True):
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
223 """
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
224 Scans given path for repos and return (name,(type,path)) tuple
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
225
1836
445861e156d1 normalize path using os.sep
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
226 :param path: path to scan for repositories
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
227 :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
228 """
633
fcf599cd3404 Move changes for git implementation
Marcin Kuzminski <marcin@python-works.com>
parents: 631
diff changeset
229
1820
9130fa3c6d61 fixes issue #331 RC mangles repository names if the a repository group contains the "full path" to the repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
230 # remove ending slash for better results
1836
445861e156d1 normalize path using os.sep
Marcin Kuzminski <marcin@python-works.com>
parents: 1824
diff changeset
231 path = path.rstrip(os.sep)
3228
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
232 log.debug('now scanning in %s location recursive:%s...' % (path, recursive))
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
233
877
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
234 def _get_repos(p):
3980
3648a2b2e17a accept that repos are read-only - very convenient for testing.
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
235 if not os.access(p, os.R_OK) or not os.access(p, os.X_OK):
3981
4c78da22dbbb use consistent string formatting
Marcin Kuzminski <marcin@python-works.com>
parents: 3980
diff changeset
236 log.warn('ignoring repo path without access: %s' % (p,))
3980
3648a2b2e17a accept that repos are read-only - very convenient for testing.
Marcin Kuzminski <marcin@python-works.com>
parents: 3960
diff changeset
237 return
1221
e4784e2b03f7 strip os.sep instead of '/' in repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 1206
diff changeset
238 if not os.access(p, os.W_OK):
3981
4c78da22dbbb use consistent string formatting
Marcin Kuzminski <marcin@python-works.com>
parents: 3980
diff changeset
239 log.warn('repo path without write access: %s' % (p,))
877
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
240 for dirpath in os.listdir(p):
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
241 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
242 continue
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
243 cur_path = os.path.join(p, dirpath)
3228
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
244
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
245 # skip removed repos
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
246 if skip_removed_repos and REMOVED_REPO_PAT.match(dirpath):
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
247 continue
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
248
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
249 #skip .<somethin> dirs
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
250 if dirpath.startswith('.'):
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
251 continue
ba2e2514a01a reposcann should skip directories with starting with '.'
Marcin Kuzminski <marcin@python-works.com>
parents: 3149
diff changeset
252
877
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
253 try:
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
254 scm_info = get_scm(cur_path)
1820
9130fa3c6d61 fixes issue #331 RC mangles repository names if the a repository group contains the "full path" to the repositories
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
255 yield scm_info[1].split(path, 1)[-1].lstrip(os.sep), scm_info
877
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
256 except VCSError:
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
257 if not recursive:
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
258 continue
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
259 #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
260 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
261 if os.path.isdir(rec_path):
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
262 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
263 yield inner_scm
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
264
bc9a73adc216 Added recursive scanning for repositories in directory
Marcin Kuzminski <marcin@python-works.com>
parents: 860
diff changeset
265 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
266
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
267
2716
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
268 def is_valid_repo(repo_name, base_path, scm=None):
761
56c2850a5b5f ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
269 """
2716
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
270 Returns True if given path is a valid repository False otherwise.
2815
acc05c33cc0c White space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 2809
diff changeset
271 If scm param is given also compare if given scm is the same as expected
2716
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
272 from scm parameter
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2069
diff changeset
273
761
56c2850a5b5f ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
274 :param repo_name:
56c2850a5b5f ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
275 :param base_path:
2716
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
276 :param scm:
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
277
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
278 :return True: if given path is a valid repository
761
56c2850a5b5f ldap auth rewrite, moved split authfunc into two functions,
Marcin Kuzminski <marcin@python-works.com>
parents: 756
diff changeset
279 """
2100
f0649c7cf94a fixed some unicode problems with waitress
Marcin Kuzminski <marcin@python-works.com>
parents: 2069
diff changeset
280 full_path = os.path.join(safe_str(base_path), safe_str(repo_name))
1528
1d7a621d396f fixed action logger
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
281
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
282 try:
2716
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
283 scm_ = get_scm(full_path)
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
284 if scm:
4c71667160e5 use os.environ as a fallback for getting special info from hooks, this will allow
Marcin Kuzminski <marcin@python-works.com>
parents: 2689
diff changeset
285 return scm_[0] == scm
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
286 return True
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
287 except VCSError:
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
288 return False
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
289
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
290
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
291 def is_valid_repo_group(repo_group_name, base_path, skip_path_check=False):
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
292 """
3653
4c78a0855a17 Fix 'repos group' - it is 'repository group'
Mads Kiilerich <madski@unity3d.com>
parents: 3649
diff changeset
293 Returns True if given path is a repository group False otherwise
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
294
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
295 :param repo_name:
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
296 :param base_path:
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
297 """
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
298 full_path = os.path.join(safe_str(base_path), safe_str(repo_group_name))
1528
1d7a621d396f fixed action logger
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
299
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
300 # check if it's not a repo
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
301 if is_valid_repo(repo_group_name, base_path):
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
302 return False
1528
1d7a621d396f fixed action logger
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
303
2497
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
304 try:
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
305 # we need to check bare git repos at higher level
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
306 # since we might match branches/hooks/info/objects or possible
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
307 # other things inside bare git repo
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
308 get_scm(os.path.dirname(full_path))
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
309 return False
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
310 except VCSError:
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
311 pass
5a8c19c4dbe1 Fixed bug in repos group discovery, when inner folder of bare git repos were detected as a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
312
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
313 # check if it's a valid path
3458
0ad025ee005e better detection of deleting groups with subgroups inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3397
diff changeset
314 if skip_path_check or os.path.isdir(full_path):
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
315 return True
1528
1d7a621d396f fixed action logger
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
316
1505
bb6ba7442293 Fixed methods for checking if path in routes is a repo
Marcin Kuzminski <marcin@python-works.com>
parents: 1483
diff changeset
317 return False
1528
1d7a621d396f fixed action logger
Marcin Kuzminski <marcin@python-works.com>
parents: 1507
diff changeset
318
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
319
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
320 def ask_ok(prompt, retries=4, complaint='Yes or no please!'):
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
321 while True:
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
322 ok = raw_input(prompt)
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
323 if ok in ('y', 'ye', 'yes'):
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
324 return True
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
325 if ok in ('n', 'no', 'nop', 'nope'):
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
326 return False
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
327 retries = retries - 1
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
328 if retries < 0:
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
329 raise IOError
351
d09381593b12 updated db manage script, and remove broken test
Marcin Kuzminski <marcin@python-works.com>
parents: 350
diff changeset
330 print complaint
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
331
388
3bcf9529d221 Added new application settings,Push ssl and repositories path
Marcin Kuzminski <marcin@python-works.com>
parents: 386
diff changeset
332 #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
333 ui_sections = ['alias', 'auth',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
334 'decode/encode', 'defaults',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
335 'diff', 'email',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
336 'extensions', 'format',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
337 'merge-patterns', 'merge-tools',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
338 'hooks', 'http_proxy',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
339 'smtp', 'patch',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
340 'paths', 'profiling',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
341 'server', 'trusted',
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
342 'ui', 'web', ]
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
343
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
344
2717
dd240b2b7a12 Added optional flag to make_ui to not clean sqlalchemy Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
345 def make_ui(read_from='file', path=None, checkpaths=True, clear_session=True):
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
346 """
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
347 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
348 and make an mercurial ui object from read options
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
349
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
350 :param path: path to mercurial config file
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
351 :param checkpaths: check the path
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
352 :param read_from: read from 'file' or 'db'
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
353 """
386
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
354
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
355 baseui = ui.ui()
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
356
1991
9e0db8d8d616 changed warning log message for reading hgrc files, it was confusing. It's just an indication of the fact
Marcin Kuzminski <marcin@python-works.com>
parents: 1985
diff changeset
357 # clean the baseui object
724
a9bc513a1fe3 fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
358 baseui._ocfg = config.config()
a9bc513a1fe3 fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
359 baseui._ucfg = config.config()
a9bc513a1fe3 fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
360 baseui._tcfg = config.config()
a9bc513a1fe3 fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
361
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
362 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
363 if not os.path.isfile(path):
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
364 log.debug('hgrc file is not present at %s, skipping...' % 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
365 return False
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1836
diff changeset
366 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
367 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
368 cfg.read(path)
386
a9a607a58b1c moved out ui_sections out of make ui function
Marcin Kuzminski <marcin@python-works.com>
parents: 381
diff changeset
369 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
370 for k, v in cfg.items(section):
3133
95b4242a275e logging: make 'settings ui from db' look more like Mercurial ini file notation
Mads Kiilerich <madski@unity3d.com>
parents: 3115
diff changeset
371 log.debug('settings ui from file: [%s] %s=%s' % (section, k, v))
2989
190e2ff4595d fix for issue #602, enforce str when setting mercurial UI object. When this is used together with mercurial internal translation system
Marcin Kuzminski <marcin@python-works.com>
parents: 2911
diff changeset
372 baseui.setconfig(safe_str(section), safe_str(k), safe_str(v))
724
a9bc513a1fe3 fixed nasty bug with ui()
Marcin Kuzminski <marcin@python-works.com>
parents: 692
diff changeset
373
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
374 elif read_from == 'db':
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
375 sa = meta.Session()
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
376 ret = sa.query(RhodeCodeUi)\
1991
9e0db8d8d616 changed warning log message for reading hgrc files, it was confusing. It's just an indication of the fact
Marcin Kuzminski <marcin@python-works.com>
parents: 1985
diff changeset
377 .options(FromCache("sql_cache_short", "get_hg_ui_settings"))\
9e0db8d8d616 changed warning log message for reading hgrc files, it was confusing. It's just an indication of the fact
Marcin Kuzminski <marcin@python-works.com>
parents: 1985
diff changeset
378 .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
379
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
380 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
381 for ui_ in hg_ui:
2689
73cfc54c87d5 fixed the push_ssl issues after mercurial 2.3 upgrade.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
382 if ui_.ui_active:
3133
95b4242a275e logging: make 'settings ui from db' look more like Mercurial ini file notation
Mads Kiilerich <madski@unity3d.com>
parents: 3115
diff changeset
383 log.debug('settings ui from db: [%s] %s=%s', ui_.ui_section,
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
384 ui_.ui_key, ui_.ui_value)
2989
190e2ff4595d fix for issue #602, enforce str when setting mercurial UI object. When this is used together with mercurial internal translation system
Marcin Kuzminski <marcin@python-works.com>
parents: 2911
diff changeset
385 baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key),
190e2ff4595d fix for issue #602, enforce str when setting mercurial UI object. When this is used together with mercurial internal translation system
Marcin Kuzminski <marcin@python-works.com>
parents: 2911
diff changeset
386 safe_str(ui_.ui_value))
2689
73cfc54c87d5 fixed the push_ssl issues after mercurial 2.3 upgrade.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
387 if ui_.ui_key == 'push_ssl':
73cfc54c87d5 fixed the push_ssl issues after mercurial 2.3 upgrade.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
388 # force set push_ssl requirement to False, rhodecode
73cfc54c87d5 fixed the push_ssl issues after mercurial 2.3 upgrade.
Marcin Kuzminski <marcin@python-works.com>
parents: 2684
diff changeset
389 # handles that
2989
190e2ff4595d fix for issue #602, enforce str when setting mercurial UI object. When this is used together with mercurial internal translation system
Marcin Kuzminski <marcin@python-works.com>
parents: 2911
diff changeset
390 baseui.setconfig(safe_str(ui_.ui_section), safe_str(ui_.ui_key),
190e2ff4595d fix for issue #602, enforce str when setting mercurial UI object. When this is used together with mercurial internal translation system
Marcin Kuzminski <marcin@python-works.com>
parents: 2911
diff changeset
391 False)
2717
dd240b2b7a12 Added optional flag to make_ui to not clean sqlalchemy Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
392 if clear_session:
dd240b2b7a12 Added optional flag to make_ui to not clean sqlalchemy Session.
Marcin Kuzminski <marcin@python-works.com>
parents: 2716
diff changeset
393 meta.Session.remove()
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
394 return baseui
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
395
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
396
548
b75b77ef649d renamed hg_app to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 547
diff changeset
397 def set_rhodecode_config(config):
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
398 """
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
399 Updates pylons config with new settings from database
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
400
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
401 :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
402 """
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1557
diff changeset
403 hgsettings = RhodeCodeSetting.get_app_settings()
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
404
381
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
405 for k, v in hgsettings.items():
55377fdc1fc6 cleared global application settings.
Marcin Kuzminski <marcin@python-works.com>
parents: 367
diff changeset
406 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
407
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
408
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
409 def set_vcs_config(config):
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
410 """
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
411 Patch VCS config with some RhodeCode specific stuff
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
412
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
413 :param config: rhodecode.CONFIG
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
414 """
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
415 import rhodecode
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
416 from rhodecode.lib.vcs import conf
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
417 from rhodecode.lib.utils2 import aslist
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
418 conf.settings.BACKENDS = {
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
419 'hg': 'rhodecode.lib.vcs.backends.hg.MercurialRepository',
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
420 'git': 'rhodecode.lib.vcs.backends.git.GitRepository',
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
421 }
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
422
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
423 conf.settings.GIT_EXECUTABLE_PATH = config.get('git_path', 'git')
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
424 conf.settings.GIT_REV_FILTER = config.get('git_rev_filter', '--all').strip()
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
425 conf.settings.DEFAULT_ENCODINGS = aslist(config.get('default_encoding',
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
426 'utf8'), sep=',')
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
427
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
428
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
429 def map_groups(path):
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
430 """
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
431 Given a full path to a repository, create all nested groups that this
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
432 repo is inside. This function creates parent-child relationships between
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
433 groups and creates default perms for all new groups.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
434
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
435 :param paths: full path to repository
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
436 """
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
437 sa = meta.Session()
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
438 groups = path.split(Repository.url_sep())
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
439 parent = None
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
440 group = None
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
441
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
442 # last element is repo in nested groups structure
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
443 groups = groups[:-1]
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
444 rgm = RepoGroupModel(sa)
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
445 owner = User.get_first_admin()
1538
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
446 for lvl, group_name in enumerate(groups):
27be8f94c207 implements #226 repo groups available by path
Marcin Kuzminski <marcin@python-works.com>
parents: 1530
diff changeset
447 group_name = '/'.join(groups[:lvl] + [group_name])
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
448 group = RepoGroup.get_by_group_name(group_name)
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
449 desc = '%s group' % group_name
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
450
2069
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
451 # skip folders that are now removed repos
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
452 if REMOVED_REPO_PAT.match(group_name):
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
453 break
003c504da933 fixed issues with removed repos was accidentally added as groups, after
Marcin Kuzminski <marcin@python-works.com>
parents: 2055
diff changeset
454
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
455 if group is None:
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
456 log.debug('creating group level: %s group_name: %s'
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
457 % (lvl, group_name))
1633
2c0d35e336b5 refactoring of models names for repoGroup permissions
Marcin Kuzminski <marcin@python-works.com>
parents: 1557
diff changeset
458 group = RepoGroup(group_name, parent)
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
459 group.group_description = desc
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
460 group.user = owner
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
461 sa.add(group)
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
462 perm_obj = rgm._create_default_perms(group)
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
463 sa.add(perm_obj)
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
464 sa.flush()
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
465
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
466 parent = group
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
467 return group
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
468
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
469
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
470 def repo2db_mapper(initial_repo_list, remove_obsolete=False,
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
471 install_git_hook=False):
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
472 """
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
473 maps all repos given in initial_repo_list, non existing repositories
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
474 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
475 that are not in initial_repo_list and removes them.
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
476
878
859bc9e7a15d Extended repo2db mapper with group creation via directory structures
Marcin Kuzminski <marcin@python-works.com>
parents: 877
diff changeset
477 :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
478 :param remove_obsolete: check for obsolete entries in database
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
479 :param install_git_hook: if this is True, also check and install githook
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
480 for a repo if missing
297
a074dec6ee40 restored utils, wrongly deleted
Marcin Kuzminski <marcin@python-works.com>
parents: 295
diff changeset
481 """
1634
1d904d972c47 User usermodel instead of db model to manage accounts
Marcin Kuzminski <marcin@python-works.com>
parents: 1633
diff changeset
482 from rhodecode.model.repo import RepoModel
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
483 from rhodecode.model.scm import ScmModel
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
484 sa = meta.Session()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
485 repo_model = RepoModel()
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3705
diff changeset
486 user = User.get_first_admin()
1039
51b70569c330 extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents: 1032
diff changeset
487 added = []
1716
7d1fc253549e notification to commit author + gardening
Marcin Kuzminski <marcin@python-works.com>
parents: 1669
diff changeset
488
3115
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
489 ##creation defaults
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
490 defs = RhodeCodeSetting.get_default_repo_settings(strip_prefix=True)
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
491 enable_statistics = defs.get('repo_enable_statistics')
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
492 enable_locking = defs.get('repo_enable_locking')
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
493 enable_downloads = defs.get('repo_enable_downloads')
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
494 private = defs.get('repo_private')
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
495
631
05528ad948c4 Hacking for git support,and new faster repo scan
Marcin Kuzminski <marcin@python-works.com>
parents: 629
diff changeset
496 for name, repo in initial_repo_list.items():
2120
d5527cebf76a Resolve error occurring during recursive group creation in API create-repo function
Marcin Kuzminski <marcin@python-works.com>
parents: 2109
diff changeset
497 group = map_groups(name)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
498 unicode_name = safe_unicode(name)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
499 db_repo = repo_model.get_by_repo_name(unicode_name)
2622
0ffcbeb76e4f Do cleanup on repo2db mapper
Marcin Kuzminski <marcin@python-works.com>
parents: 2620
diff changeset
500 # found repo that is on filesystem not in RhodeCode database
2620
cd207411cf22 fixed python2.5 compat and repo mapper issue
Marcin Kuzminski <marcin@python-works.com>
parents: 2619
diff changeset
501 if not db_repo:
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
502 log.info('repository %s not found, creating now' % 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
503 added.append(name)
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
504 desc = (repo.description
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
505 if repo.description != 'unknown'
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
506 else '%s repository' % name)
3115
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
507
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
508 new_repo = repo_model._create_repo(
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
509 repo_name=name,
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
510 repo_type=repo.alias,
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
511 description=desc,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
512 repo_group=getattr(group, 'group_id', None),
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
513 owner=user,
3115
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
514 enable_locking=enable_locking,
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
515 enable_downloads=enable_downloads,
ebd76deee70d Default parameters are now also used for creating repos using API calls, and initial repo scanner
Marcin Kuzminski <marcin@python-works.com>
parents: 3063
diff changeset
516 enable_statistics=enable_statistics,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
517 private=private,
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
518 state=Repository.STATE_CREATED
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
519 )
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
520 sa.commit()
2622
0ffcbeb76e4f Do cleanup on repo2db mapper
Marcin Kuzminski <marcin@python-works.com>
parents: 2620
diff changeset
521 # we added that repo just now, and make sure it has githook
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
522 # installed, and updated server info
2622
0ffcbeb76e4f Do cleanup on repo2db mapper
Marcin Kuzminski <marcin@python-works.com>
parents: 2620
diff changeset
523 if new_repo.repo_type == 'git':
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
524 git_repo = new_repo.scm_instance
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
525 ScmModel().install_git_hook(git_repo)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
526 # update repository server-info
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
527 log.debug('Running update server info')
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
528 git_repo._update_server_info()
3147
8182ebed2922 Added full last changeset info to lightweight dashboard
Marcin Kuzminski <marcin@python-works.com>
parents: 3136
diff changeset
529 new_repo.update_changeset_cache()
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
530 elif install_git_hook:
2620
cd207411cf22 fixed python2.5 compat and repo mapper issue
Marcin Kuzminski <marcin@python-works.com>
parents: 2619
diff changeset
531 if db_repo.repo_type == 'git':
cd207411cf22 fixed python2.5 compat and repo mapper issue
Marcin Kuzminski <marcin@python-works.com>
parents: 2619
diff changeset
532 ScmModel().install_git_hook(db_repo.scm_instance)
3020
00498b3e4c88 Cleaned the way cache keys are invalidated
Marcin Kuzminski <marcin@python-works.com>
parents: 2997
diff changeset
533
1039
51b70569c330 extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents: 1032
diff changeset
534 removed = []
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
535 if remove_obsolete:
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2120
diff changeset
536 # remove from database those repositories that are not in the filesystem
348
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
537 for repo in sa.query(Repository).all():
e8fc875467bd implemented manual repo rescann and remapping
Marcin Kuzminski <marcin@python-works.com>
parents: 345
diff changeset
538 if repo.repo_name not in initial_repo_list.keys():
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
539 log.debug("Removing non-existing repository found in db `%s`" %
2147
d25bd432bc3e - #347 when running multiple RhodeCode instances, properly invalidates cache
Marcin Kuzminski <marcin@python-works.com>
parents: 2120
diff changeset
540 repo.repo_name)
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
541 try:
3694
34093903b505 repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents: 3693
diff changeset
542 removed.append(repo.repo_name)
34093903b505 repo rescann should detach forks of zombie repos,
Marcin Kuzminski <marcin@python-works.com>
parents: 3693
diff changeset
543 RepoModel(sa).delete(repo, forks='detach', fs_remove=False)
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
544 sa.commit()
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3607
diff changeset
545 except Exception:
2619
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
546 #don't hold further removals on error
f1dfd3a2a193 Added option to re-install githooks to repo2db mapper, and catch exception on removal so it doesn't break
Marcin Kuzminski <marcin@python-works.com>
parents: 2529
diff changeset
547 log.error(traceback.format_exc())
2635
d6fa7805e687 we must rollback if repo2db mapper cleanup fails ! Session blows up, and that code still throws an error without it
Marcin Kuzminski <marcin@python-works.com>
parents: 2622
diff changeset
548 sa.rollback()
1039
51b70569c330 extended admin rescan to show what repositories was added and what removed
Marcin Kuzminski <marcin@python-works.com>
parents: 1032
diff changeset
549 return added, removed
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
550
1982
87f0800abc7b #227 Initial version of repository groups permissions system
Marcin Kuzminski <marcin@python-works.com>
parents: 1976
diff changeset
551
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
552 # set cache regions for beaker so celery can utilise it
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
553 def add_cache(settings):
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
554 cache_settings = {'regions': None}
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
555 for key in settings.keys():
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
556 for prefix in ['beaker.cache.', 'cache.']:
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
557 if key.startswith(prefix):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
558 name = key.split(prefix)[1].strip()
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
559 cache_settings[name] = settings[key].strip()
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
560 if cache_settings['regions']:
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
561 for region in cache_settings['regions'].split(','):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
562 region = region.strip()
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
563 region_settings = {}
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
564 for key, value in cache_settings.items():
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
565 if key.startswith(region):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
566 region_settings[key.split('.')[1]] = value
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
567 region_settings['expire'] = int(region_settings.get('expire',
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
568 60))
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
569 region_settings.setdefault('lock_dir',
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
570 cache_settings.get('lock_dir'))
1032
2e9f2bd28143 fixed add cache defaults missing data_dir
Marcin Kuzminski <marcin@python-works.com>
parents: 1022
diff changeset
571 region_settings.setdefault('data_dir',
2e9f2bd28143 fixed add cache defaults missing data_dir
Marcin Kuzminski <marcin@python-works.com>
parents: 1022
diff changeset
572 cache_settings.get('data_dir'))
2e9f2bd28143 fixed add cache defaults missing data_dir
Marcin Kuzminski <marcin@python-works.com>
parents: 1022
diff changeset
573
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
574 if 'type' not in region_settings:
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
575 region_settings['type'] = cache_settings.get('type',
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
576 'memory')
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
577 beaker.cache.cache_regions[region] = region_settings
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
578
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
579
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
580 def load_rcextensions(root_path):
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
581 import rhodecode
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
582 from rhodecode.config import conf
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
583
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
584 path = os.path.join(root_path, 'rcextensions', '__init__.py')
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
585 if os.path.isfile(path):
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
586 rcext = create_module('rc', path)
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
587 EXT = rhodecode.EXTENSIONS = rcext
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
588 log.debug('Found rcextensions now loading %s...' % rcext)
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
589
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
590 # Additional mappings that are not present in the pygments lexers
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
591 conf.LANGUAGES_EXTENSIONS_MAP.update(getattr(EXT, 'EXTRA_MAPPINGS', {}))
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
592
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
593 #OVERRIDE OUR EXTENSIONS FROM RC-EXTENSIONS (if present)
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
594
3888
7aa0ff5b4e09 simplified boolean expressions
Marcin Kuzminski <marcin@python-works.com>
parents: 3824
diff changeset
595 if getattr(EXT, 'INDEX_EXTENSIONS', []):
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
596 log.debug('settings custom INDEX_EXTENSIONS')
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
597 conf.INDEX_EXTENSIONS = getattr(EXT, 'INDEX_EXTENSIONS', [])
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
598
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
599 #ADDITIONAL MAPPINGS
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
600 log.debug('adding extra into INDEX_EXTENSIONS')
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
601 conf.INDEX_EXTENSIONS.extend(getattr(EXT, 'EXTRA_INDEX_EXTENSIONS', []))
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
602
3375
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
603 # auto check if the module is not missing any data, set to default if is
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
604 # this will help autoupdate new feature of rcext module
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
605 #from rhodecode.config import rcextensions
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
606 #for k in dir(rcextensions):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
607 # if not k.startswith('_') and not hasattr(EXT, k):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
608 # setattr(EXT, k, getattr(rcextensions, k))
3375
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
609
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
610
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
611 def get_custom_lexer(extension):
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
612 """
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
613 returns a custom lexer if it's defined in rcextensions module, or None
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
614 if there's no custom lexer defined
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
615 """
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
616 import rhodecode
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
617 from pygments import lexers
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
618 #check if we didn't define this extension as other lexer
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
619 if rhodecode.EXTENSIONS and extension in rhodecode.EXTENSIONS.EXTRA_LEXERS:
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
620 _lexer_name = rhodecode.EXTENSIONS.EXTRA_LEXERS[extension]
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
621 return lexers.get_lexer_by_name(_lexer_name)
7000fc4aa569 Add option to define custom lexers for custom extensions for code highlight in rcextension module
Marcin Kuzminski <marcin@python-works.com>
parents: 3340
diff changeset
622
2109
8ecfed1d8f8b utils/conf
Marcin Kuzminski <marcin@python-works.com>
parents: 2102
diff changeset
623
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
624 #==============================================================================
629
7e536d1af60d Code refactoring,models renames
Marcin Kuzminski <marcin@python-works.com>
parents: 621
diff changeset
625 # TEST FUNCTIONS AND CREATORS
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
626 #==============================================================================
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
627 def create_test_index(repo_location, config, full_index):
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
628 """
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
629 Makes default test index
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
630
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
631 :param config: test config
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
632 :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
633 """
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
634
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
635 from rhodecode.lib.indexers.daemon import WhooshIndexingDaemon
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
636 from rhodecode.lib.pidlock import DaemonLock, LockHeld
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
637
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
638 repo_location = repo_location
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
639
1411
90eebc0f040c Fixed whoosh index location bug
Marcin Kuzminski <marcin@python-works.com>
parents: 1406
diff changeset
640 index_location = os.path.join(config['app_conf']['index_dir'])
1401
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
641 if not os.path.exists(index_location):
b7563ad4e7ee Unicode fixes, added safe_str method for global str() operations +better test sandboxing
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
642 os.makedirs(index_location)
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
643
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
644 try:
1540
191f3f08236d fixes #258 RhodeCode 1.2 assumes egg folder is writable
Marcin Kuzminski <marcin@python-works.com>
parents: 1538
diff changeset
645 l = DaemonLock(file_=jn(dn(index_location), 'make_index.lock'))
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
646 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
647 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
648 .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
649 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
650 except LockHeld:
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
651 pass
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
652
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
653
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
654 def create_test_env(repos_test_path, config):
1717
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
655 """
7ff304d3028f Notification fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1716
diff changeset
656 Makes a fresh database and
473
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 395
diff changeset
657 install test repository into tmp dir
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 395
diff changeset
658 """
547
1e757ac98988 renamed project to rhodecode
Marcin Kuzminski <marcin@python-works.com>
parents: 544
diff changeset
659 from rhodecode.lib.db_manage import DbManage
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
660 from rhodecode.tests import HG_REPO, GIT_REPO, TESTS_TMP_PATH
604
5cc96df705b9 fixed @repo into :repo for docs
Marcin Kuzminski <marcin@python-works.com>
parents: 569
diff changeset
661
1416
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1411
diff changeset
662 # PART ONE create db
783
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
663 dbconf = config['sqlalchemy.db1.url']
1976
Marcin Kuzminski <marcin@python-works.com>
parents: 1836
diff changeset
664 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
665
1397
dc960653f8d2 Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents: 1396
diff changeset
666 # create test dir if it doesn't exist
dc960653f8d2 Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents: 1396
diff changeset
667 if not os.path.isdir(repos_test_path):
dc960653f8d2 Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents: 1396
diff changeset
668 log.debug('Creating testdir %s' % repos_test_path)
dc960653f8d2 Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents: 1396
diff changeset
669 os.makedirs(repos_test_path)
dc960653f8d2 Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents: 1396
diff changeset
670
783
71113f64b2d8 fidex corrent variables passed to dnconfig,
Marcin Kuzminski <marcin@python-works.com>
parents: 773
diff changeset
671 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
672 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
673 dbmanage.create_tables(override=True)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
674 # for tests dynamically set new root paths based on generated content
1099
bc3dafd0e24c fixed test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 1039
diff changeset
675 dbmanage.create_settings(dbmanage.config_prompt(repos_test_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
676 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
677 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
678 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
679 dbmanage.populate_default_permissions()
2529
40b3a54391f9 Added functional test create repo with a group
Marcin Kuzminski <marcin@python-works.com>
parents: 2511
diff changeset
680 Session().commit()
1416
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1411
diff changeset
681 # 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
682 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
683
1396
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
684 idx_path = config['app_conf']['index_dir']
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
685 data_path = config['app_conf']['cache_dir']
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
686
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
687 #clean index and data
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
688 if idx_path and os.path.exists(idx_path):
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
689 log.debug('remove %s' % idx_path)
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
690 shutil.rmtree(idx_path)
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
691
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
692 if data_path and os.path.exists(data_path):
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
693 log.debug('remove %s' % data_path)
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
694 shutil.rmtree(data_path)
069ee86e85ad cleanup before start testing suite of index and data cache dirs
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
695
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
696 #CREATE DEFAULT TEST REPOS
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
697 cur_dir = dn(dn(abspath(__file__)))
3824
a5746b83123f moved top-level tests to rhodecode/tests/other.
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
698 tar = tarfile.open(jn(cur_dir, 'tests', 'fixtures', "vcs_test_hg.tar.gz"))
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
699 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
700 tar.close()
684
2abb398cd9a7 upgrade-db command dummy
Marcin Kuzminski <marcin@python-works.com>
parents: 665
diff changeset
701
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
702 cur_dir = dn(dn(abspath(__file__)))
3824
a5746b83123f moved top-level tests to rhodecode/tests/other.
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
703 tar = tarfile.open(jn(cur_dir, 'tests', 'fixtures', "vcs_test_git.tar.gz"))
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
704 tar.extractall(jn(TESTS_TMP_PATH, GIT_REPO))
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
705 tar.close()
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
706
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
707 #LOAD VCS test stuff
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
708 from rhodecode.tests.vcs import setup_package
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
709 setup_package()
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2375
diff changeset
710
1224
e76833cd555a files: fixes error when passing a diff without parameters and caused server crash
Marcin Kuzminski <marcin@python-works.com>
parents: 1221
diff changeset
711
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
712 #==============================================================================
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
713 # PASTER COMMANDS
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
714 #==============================================================================
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
715 class BasePasterCommand(Command):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
716 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
717 Abstract Base Class for paster commands.
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
718
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
719 The celery commands are somewhat aggressive about loading
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
720 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
721 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
722 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
723 command line, otherwise everything fails.
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
724 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
725 min_args = 1
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
726 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
727 takes_config_file = 1
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
728 requires_config_file = True
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
729
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
730 def notify_msg(self, msg, log=False):
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
731 """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
732 it logs this action using given logger
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
733
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
734 :param msg: message that will be printed to user
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
735 :param log: logging instance, to use to additionally log this message
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
736
837
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
737 """
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
738 if log and isinstance(log, logging):
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
739 log(msg)
60cbde084047 fixed wrong migration schema
Marcin Kuzminski <marcin@python-works.com>
parents: 833
diff changeset
740
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
741 def run(self, args):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
742 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
743 Overrides Command.run
1203
6832ef664673 source code cleanup: remove trailing white space, normalize file endings
Marcin Kuzminski <marcin@python-works.com>
parents: 1196
diff changeset
744
785
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
745 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
746 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
747 if len(args) < self.min_args:
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
748 raise BadCommand(
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
749 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
750 'actual_args': len(args)})
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
751
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
752 # 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
753 # @@ This is hacky
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
754 self.min_args -= 1
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
755 self.bootstrap_config(args[0])
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
756 self.update_parser()
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
757 return super(BasePasterCommand, self).run(args[1:])
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
758
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
759 def update_parser(self):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
760 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
761 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
762 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
763 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
764 celery command.
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
765 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
766 raise NotImplementedError("Abstract Method.")
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
767
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
768 def bootstrap_config(self, conf):
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
769 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
770 Loads the pylons configuration.
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
771 """
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
772 from pylons import config as pylonsconfig
277427ac29a9 complete rewrite of paster commands,
Marcin Kuzminski <marcin@python-works.com>
parents: 783
diff changeset
773
2102
04d26165c3d9 Whoosh logging is now controlled by the .ini files logging setup
Marcin Kuzminski <marcin@python-works.com>
parents: 2100
diff changeset
774 self.path_to_ini_file = os.path.realpath(conf)
04d26165c3d9 Whoosh logging is now controlled by the .ini files logging setup
Marcin Kuzminski <marcin@python-works.com>
parents: 2100
diff changeset
775 conf = paste.deploy.appconfig('config:' + self.path_to_ini_file)
1818
cf51bbfb120e auto white-space removal
Marcin Kuzminski <marcin@python-works.com>
parents: 1753
diff changeset
776 pylonsconfig.init_app(conf.global_conf, conf.local_conf)
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
777
3340
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
778 def _init_session(self):
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
779 """
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
780 Inits SqlAlchemy Session
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
781 """
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
782 logging.config.fileConfig(self.path_to_ini_file)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
783 from pylons import config
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
784 from rhodecode.model import init_model
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
785 from rhodecode.lib.utils2 import engine_from_config
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
786
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
787 #get to remove repos !!
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
788 add_cache(config)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
789 engine = engine_from_config(config, 'sqlalchemy.db1.')
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
790 init_model(engine)
f1491bad8339 unified RhodeCode paster commands
Marcin Kuzminski <marcin@python-works.com>
parents: 3228
diff changeset
791
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
792
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
793 def check_git_version():
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
794 """
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
795 Checks what version of git is installed in system, and issues a warning
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
796 if it's too old for RhodeCode to properly work.
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
797 """
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 3375
diff changeset
798 from rhodecode import BACKENDS
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 3375
diff changeset
799 from rhodecode.lib.vcs.backends.git.repository import GitRepository
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
800 from rhodecode.lib.vcs.conf import settings
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
801 from distutils.version import StrictVersion
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
802
3397
64c194492aad --version command should be safe, and bare no modifications
Marcin Kuzminski <marcin@python-works.com>
parents: 3376
diff changeset
803 stdout, stderr = GitRepository._run_git_command('--version', _bare=True,
64c194492aad --version command should be safe, and bare no modifications
Marcin Kuzminski <marcin@python-works.com>
parents: 3376
diff changeset
804 _safe=True)
3376
e67b2ef07a8e git executable is now configurable via .ini files
Marcin Kuzminski <marcin@python-works.com>
parents: 3375
diff changeset
805
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
806 ver = (stdout.split(' ')[-1] or '').strip() or '0.0.0'
2911
b14850a72bc2 fixed check git version function, git sometimes uses 4 element version numbering which breaks the system that function
Marcin Kuzminski <marcin@python-works.com>
parents: 2900
diff changeset
807 if len(ver.split('.')) > 3:
b14850a72bc2 fixed check git version function, git sometimes uses 4 element version numbering which breaks the system that function
Marcin Kuzminski <marcin@python-works.com>
parents: 2900
diff changeset
808 #StrictVersion needs to be only 3 element type
b14850a72bc2 fixed check git version function, git sometimes uses 4 element version numbering which breaks the system that function
Marcin Kuzminski <marcin@python-works.com>
parents: 2900
diff changeset
809 ver = '.'.join(ver.split('.')[:3])
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
810 try:
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
811 _ver = StrictVersion(ver)
3631
10b4e34841a4 Don't catch all exceptions
Marcin Kuzminski <marcin@python-works.com>
parents: 3607
diff changeset
812 except Exception:
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
813 _ver = StrictVersion('0.0.0')
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
814 stderr = traceback.format_exc()
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
815
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
816 req_ver = '1.7.4'
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
817 to_old_git = False
2997
da3926d9e56e fix strict version of git check if we have 1.7.4 it's ok !
Marcin Kuzminski <marcin@python-works.com>
parents: 2989
diff changeset
818 if _ver < StrictVersion(req_ver):
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
819 to_old_git = True
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
820
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
821 if 'git' in BACKENDS:
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
822 log.debug('GIT executable: "%s" version detected: %s'
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3774
diff changeset
823 % (settings.GIT_EXECUTABLE_PATH, stdout))
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
824 if stderr:
3575
ca7785fae354 avoid %r markup of unicode strings in user facing messages
Mads Kiilerich <madski@unity3d.com>
parents: 3545
diff changeset
825 log.warning('Unable to detect git version, org error was: %r' % stderr)
2890
84414d73c233 Add git version detection to warn users that Git used in system is to old. ref #588
Marcin Kuzminski <marcin@python-works.com>
parents: 2815
diff changeset
826 elif to_old_git:
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
827 log.warning('RhodeCode detected git version %s, which is too old '
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
828 'for the system to function properly. Make sure '
2900
8c54b294d3e4 Rephrase the message.
Andrew Shadura <bugzilla@tut.by>
parents: 2899
diff changeset
829 'its version is at least %s' % (ver, req_ver))
2899
c76aa8b06179 Fix typos.
Andrew Shadura <bugzilla@tut.by>
parents: 2890
diff changeset
830 return _ver
3061
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
831
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
832
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
833 @decorator.decorator
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
834 def jsonify(func, *args, **kwargs):
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
835 """Action decorator that formats output for JSON
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
836
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
837 Given a function that will return content, this decorator will turn
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
838 the result into JSON, with a content-type of 'application/json' and
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
839 output it.
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
840
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
841 """
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
842 from pylons.decorators.util import get_pylons
3705
f37d7514e7ab always use json from compat module
Marcin Kuzminski <marcin@python-works.com>
parents: 3694
diff changeset
843 from rhodecode.lib.compat import json
3061
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
844 pylons = get_pylons(args)
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
845 pylons.response.headers['Content-Type'] = 'application/json; charset=utf-8'
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
846 data = func(*args, **kwargs)
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
847 if isinstance(data, (list, tuple)):
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
848 msg = "JSON responses with Array envelopes are susceptible to " \
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
849 "cross-site data leak attacks, see " \
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
850 "http://wiki.pylonshq.com/display/pylonsfaq/Warnings"
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
851 warnings.warn(msg, Warning, 2)
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
852 log.warning(msg)
7727faad5baf fixed issue #671 commenting on pull requests sometimes used old JSON encoder and broke. This changeset replaces it's with RhodeCode json encoder to ensure all data is properly serializable
Marcin Kuzminski <marcin@python-works.com>
parents: 3020
diff changeset
853 log.debug("Returning JSON wrapped action output")
3149
68f9c216377d white space cleanup
Marcin Kuzminski <marcin@python-works.com>
parents: 3147
diff changeset
854 return json.dumps(data, encoding='utf-8')
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
855
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
856
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
857 def conditional_cache(region, prefix, condition, func):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
858 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
859
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
860 Conditional caching function use like::
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
861 def _c(arg):
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
862 #heavy computation function
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
863 return data
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
864
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
865 # denpending from condition the compute is wrapped in cache or not
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
866 compute = conditional_cache('short_term', 'cache_desc', codnition=True, func=func)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
867 return compute(arg)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
868
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
869 :param region: name of cache region
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
870 :param prefix: cache region prefix
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
871 :param condition: condition for cache to be triggered, and return data cached
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
872 :param func: wrapped heavy function to compute
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
873
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
874 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
875 wrapped = func
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
876 if condition:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
877 log.debug('conditional_cache: True, wrapping call of '
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
878 'func: %s into %s region cache' % (region, func))
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
879 wrapped = _cache_decorate((prefix,), None, None, region)(func)
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
880
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4012
diff changeset
881 return wrapped