##// END OF EJS Templates
backends: don't detect backends when initializing db based vcs-instance....
marcink -
r1127:ed2556a8 default
parent child Browse files
Show More

The requested changes are too big and content was truncated. Show full diff

@@ -1,87 +1,95 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2014-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 """
22 22 VCS Backends module
23 23 """
24 24
25 import os
25 26 import logging
26 27
27 28 from pprint import pformat
28 29
29 30 from rhodecode.lib.vcs.conf import settings
30 31 from rhodecode.lib.vcs.exceptions import VCSError
31 32 from rhodecode.lib.vcs.utils.helpers import get_scm
32 33 from rhodecode.lib.vcs.utils.imports import import_class
33 34
34 35
35 36 log = logging.getLogger(__name__)
36 37
37 38
38 39 def get_vcs_instance(repo_path, *args, **kwargs):
39 40 """
40 41 Given a path to a repository an instance of the corresponding vcs backend
41 42 repository class is created and returned. If no repository can be found
42 43 for the path it returns None. Arguments and keyword arguments are passed
43 44 to the vcs backend repository class.
44 45 """
46 explicit_vcs_alias = kwargs.pop('_vcs_alias', None)
45 47 try:
46 vcs_alias = get_scm(repo_path)[0]
48 vcs_alias = explicit_vcs_alias or get_scm(repo_path)[0]
47 49 log.debug(
48 50 'Creating instance of %s repository from %s', vcs_alias, repo_path)
49 51 backend = get_backend(vcs_alias)
52
53 if explicit_vcs_alias:
54 # do final verification of existance of the path, this does the
55 # same as get_scm() call which we skip in explicit_vcs_alias
56 if not os.path.isdir(repo_path):
57 raise VCSError("Given path %s is not a directory" % repo_path)
50 58 except VCSError:
51 59 log.exception(
52 60 'Perhaps this repository is in db and not in '
53 61 'filesystem run rescan repositories with '
54 62 '"destroy old data" option from admin panel')
55 63 return None
56 64
57 65 return backend(repo_path=repo_path, *args, **kwargs)
58 66
59 67
60 68 def get_backend(alias):
61 69 """
62 70 Returns ``Repository`` class identified by the given alias or raises
63 71 VCSError if alias is not recognized or backend class cannot be imported.
64 72 """
65 73 if alias not in settings.BACKENDS:
66 74 raise VCSError(
67 75 "Given alias '%s' is not recognized! Allowed aliases:\n%s" %
68 76 (alias, pformat(settings.BACKENDS.keys())))
69 77 backend_path = settings.BACKENDS[alias]
70 78 klass = import_class(backend_path)
71 79 return klass
72 80
73 81
74 82 def get_supported_backends():
75 83 """
76 84 Returns list of aliases of supported backends.
77 85 """
78 86 return settings.BACKENDS.keys()
79 87
80 88
81 89 def get_vcsserver_version():
82 90 from rhodecode.lib.vcs import connection
83 91 data = connection.Service.get_vcsserver_service_data()
84 92 if data and 'version' in data:
85 93 return data['version']
86 94
87 95 return None
1 NO CONTENT: modified file
The requested commit or file is too big and content was truncated. Show full diff
General Comments 0
You need to be logged in to leave comments. Login now