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