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