Show More
@@ -1,95 +1,98 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 | 25 | import os |
|
26 | 26 | import logging |
|
27 | 27 | |
|
28 | 28 | from pprint import pformat |
|
29 | 29 | |
|
30 | 30 | from rhodecode.lib.vcs.conf import settings |
|
31 | 31 | from rhodecode.lib.vcs.exceptions import VCSError |
|
32 | 32 | from rhodecode.lib.vcs.utils.helpers import get_scm |
|
33 | 33 | from rhodecode.lib.vcs.utils.imports import import_class |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | log = logging.getLogger(__name__) |
|
37 | 37 | |
|
38 | 38 | |
|
39 | 39 | def get_vcs_instance(repo_path, *args, **kwargs): |
|
40 | 40 | """ |
|
41 | 41 | Given a path to a repository an instance of the corresponding vcs backend |
|
42 | 42 | repository class is created and returned. If no repository can be found |
|
43 | 43 | for the path it returns None. Arguments and keyword arguments are passed |
|
44 | 44 | to the vcs backend repository class. |
|
45 | 45 | """ |
|
46 | from rhodecode.lib.utils2 import safe_str | |
|
47 | ||
|
46 | 48 | explicit_vcs_alias = kwargs.pop('_vcs_alias', None) |
|
47 | 49 | try: |
|
48 | vcs_alias = explicit_vcs_alias or get_scm(repo_path)[0] | |
|
50 | vcs_alias = safe_str(explicit_vcs_alias or get_scm(repo_path)[0]) | |
|
49 | 51 | log.debug( |
|
50 |
'Creating instance of %s repository from %s', vcs_alias, |
|
|
52 | 'Creating instance of %s repository from %s', vcs_alias, | |
|
53 | safe_str(repo_path)) | |
|
51 | 54 | backend = get_backend(vcs_alias) |
|
52 | 55 | |
|
53 | 56 | if explicit_vcs_alias: |
|
54 | 57 | # do final verification of existance of the path, this does the |
|
55 | 58 | # same as get_scm() call which we skip in explicit_vcs_alias |
|
56 | 59 | if not os.path.isdir(repo_path): |
|
57 | 60 | raise VCSError("Given path %s is not a directory" % repo_path) |
|
58 | 61 | except VCSError: |
|
59 | 62 | log.exception( |
|
60 | 63 | 'Perhaps this repository is in db and not in ' |
|
61 | 64 | 'filesystem run rescan repositories with ' |
|
62 | 65 | '"destroy old data" option from admin panel') |
|
63 | 66 | return None |
|
64 | 67 | |
|
65 | 68 | return backend(repo_path=repo_path, *args, **kwargs) |
|
66 | 69 | |
|
67 | 70 | |
|
68 | 71 | def get_backend(alias): |
|
69 | 72 | """ |
|
70 | 73 | Returns ``Repository`` class identified by the given alias or raises |
|
71 | 74 | VCSError if alias is not recognized or backend class cannot be imported. |
|
72 | 75 | """ |
|
73 | 76 | if alias not in settings.BACKENDS: |
|
74 | 77 | raise VCSError( |
|
75 | 78 | "Given alias '%s' is not recognized! Allowed aliases:\n%s" % |
|
76 | 79 | (alias, pformat(settings.BACKENDS.keys()))) |
|
77 | 80 | backend_path = settings.BACKENDS[alias] |
|
78 | 81 | klass = import_class(backend_path) |
|
79 | 82 | return klass |
|
80 | 83 | |
|
81 | 84 | |
|
82 | 85 | def get_supported_backends(): |
|
83 | 86 | """ |
|
84 | 87 | Returns list of aliases of supported backends. |
|
85 | 88 | """ |
|
86 | 89 | return settings.BACKENDS.keys() |
|
87 | 90 | |
|
88 | 91 | |
|
89 | 92 | def get_vcsserver_version(): |
|
90 | 93 | from rhodecode.lib.vcs import connection |
|
91 | 94 | data = connection.Service.get_vcsserver_service_data() |
|
92 | 95 | if data and 'version' in data: |
|
93 | 96 | return data['version'] |
|
94 | 97 | |
|
95 | 98 | return None |
General Comments 0
You need to be logged in to leave comments.
Login now