##// END OF EJS Templates
ruff: code-cleanups
super-admin -
r1100:bb0b5a8e python3
parent child Browse files
Show More
@@ -164,7 +164,7 b' class SettingsMaker(object):'
164 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf)
164 'file does not exist.... specify path using logging.logging_conf_file= config setting. ', logging_conf)
165 return
165 return
166
166
167 with open(logging_conf, 'rb') as f:
167 with open(logging_conf, 'rt') as f:
168 ini_template = textwrap.dedent(f.read())
168 ini_template = textwrap.dedent(f.read())
169 ini_template = string.Template(ini_template).safe_substitute(
169 ini_template = string.Template(ini_template).safe_substitute(
170 RC_LOGGING_LEVEL=os.environ.get('RC_LOGGING_LEVEL', '') or level,
170 RC_LOGGING_LEVEL=os.environ.get('RC_LOGGING_LEVEL', '') or level,
@@ -75,6 +75,7 b' def _store_exception(exc_id, exc_info, p'
75 detailed_tb = getattr(exc_value, '_org_exc_tb', None)
75 detailed_tb = getattr(exc_value, '_org_exc_tb', None)
76
76
77 if detailed_tb:
77 if detailed_tb:
78 remote_tb = detailed_tb
78 if isinstance(detailed_tb, str):
79 if isinstance(detailed_tb, str):
79 remote_tb = [detailed_tb]
80 remote_tb = [detailed_tb]
80
81
@@ -16,7 +16,9 b''
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
18 import logging
18 import logging
19
19 from dogpile.cache import register_backend
20 from dogpile.cache import register_backend
21
20 module_name = 'vcsserver'
22 module_name = 'vcsserver'
21
23
22 register_backend(
24 register_backend(
@@ -40,8 +42,12 b' log = logging.getLogger(__name__)'
40
42
41 from . import region_meta
43 from . import region_meta
42 from .utils import (
44 from .utils import (
43 get_default_cache_settings, backend_key_generator, get_or_create_region,
45 backend_key_generator,
44 clear_cache_namespace, make_region)
46 clear_cache_namespace,
47 get_default_cache_settings,
48 get_or_create_region,
49 make_region,
50 )
45
51
46
52
47 def configure_dogpile_cache(settings):
53 def configure_dogpile_cache(settings):
@@ -15,30 +15,29 b''
15 # along with this program; if not, write to the Free Software Foundation,
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
18 import errno
19 import fcntl
20 import functools
21 import logging
22 import pickle
18 import time
23 import time
19 import errno
20 import logging
21 import functools
22
24
23 import msgpack
25 import msgpack
24 import redis
26 import redis
25 import pickle
27
26 import fcntl
27 flock_org = fcntl.flock
28 flock_org = fcntl.flock
28 from typing import Union
29 from typing import Union
29
30
31 from dogpile.cache.api import Deserializer, Serializer
32 from dogpile.cache.backends import file as file_backend
30 from dogpile.cache.backends import memory as memory_backend
33 from dogpile.cache.backends import memory as memory_backend
31 from dogpile.cache.backends import file as file_backend
32 from dogpile.cache.backends import redis as redis_backend
34 from dogpile.cache.backends import redis as redis_backend
33 from dogpile.cache.backends.file import FileLock
35 from dogpile.cache.backends.file import FileLock
34 from dogpile.cache.util import memoized_property
36 from dogpile.cache.util import memoized_property
35 from dogpile.cache.api import Serializer, Deserializer
36
37 from pyramid.settings import asbool
37 from pyramid.settings import asbool
38
38
39 from vcsserver.lib.memory_lru_dict import LRUDict, LRUDictDebug
39 from vcsserver.lib.memory_lru_dict import LRUDict, LRUDictDebug
40 from vcsserver.str_utils import safe_str, safe_bytes
40 from vcsserver.str_utils import safe_bytes, safe_str
41
42
41
43 _default_max_size = 1024
42 _default_max_size = 1024
44
43
@@ -15,17 +15,17 b''
15 # along with this program; if not, write to the Free Software Foundation,
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
18 import functools
19 import logging
18 import os
20 import os
19 import time
21 import time
20 import logging
22
21 import functools
22 import decorator
23 import decorator
23
24 from dogpile.cache import CacheRegion
24 from dogpile.cache import CacheRegion
25
25
26 from vcsserver.lib.rc_cache import region_meta
26 from vcsserver.str_utils import safe_bytes
27 from vcsserver.str_utils import safe_bytes
27 from vcsserver.utils import sha1
28 from vcsserver.utils import sha1
28 from vcsserver.lib.rc_cache import region_meta
29
29
30 log = logging.getLogger(__name__)
30 log = logging.getLogger(__name__)
31
31
@@ -41,7 +41,7 b' class RhodeCodeCacheRegion(CacheRegion):'
41 condition=True):
41 condition=True):
42 """
42 """
43 Custom conditional decorator, that will not touch any dogpile internals if
43 Custom conditional decorator, that will not touch any dogpile internals if
44 condition isn't meet. This works a bit different than should_cache_fn
44 condition isn't meet. This works a bit different from should_cache_fn
45 And it's faster in cases we don't ever want to compute cached values
45 And it's faster in cases we don't ever want to compute cached values
46 """
46 """
47 expiration_time_is_callable = callable(expiration_time)
47 expiration_time_is_callable = callable(expiration_time)
@@ -150,7 +150,7 b' def key_generator(backend, namespace, fn'
150 backend_prefix = getattr(backend, 'key_prefix', None) or 'backend_prefix'
150 backend_prefix = getattr(backend, 'key_prefix', None) or 'backend_prefix'
151 namespace_pref = namespace or 'default_namespace'
151 namespace_pref = namespace or 'default_namespace'
152 arg_key = compute_key_from_params(*args)
152 arg_key = compute_key_from_params(*args)
153 final_key = "{}:{}:{}_{}".format(backend_prefix, namespace_pref, fname, arg_key)
153 final_key = f"{backend_prefix}:{namespace_pref}:{fname}_{arg_key}"
154
154
155 return final_key
155 return final_key
156
156
@@ -1,3 +1,20 b''
1 # RhodeCode VCSServer provides access to different vcs backends via network.
2 # Copyright (C) 2014-2020 RhodeCode GmbH
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software Foundation,
16 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
1 from vcsserver.lib._vendor.statsd import client_from_config
18 from vcsserver.lib._vendor.statsd import client_from_config
2
19
3
20
@@ -70,7 +70,7 b' def reraise_safe_exceptions(func):'
70 exc = exceptions.VcsException(org_exc=e)
70 exc = exceptions.VcsException(org_exc=e)
71 raise exc(safe_str(e))
71 raise exc(safe_str(e))
72 except Exception as e:
72 except Exception as e:
73 # NOTE(marcink): becuase of how dulwich handles some exceptions
73 # NOTE(marcink): because of how dulwich handles some exceptions
74 # (KeyError on empty repos), we cannot track this and catch all
74 # (KeyError on empty repos), we cannot track this and catch all
75 # exceptions, it's an exceptions from other handlers
75 # exceptions, it's an exceptions from other handlers
76 #if not hasattr(e, '_vcs_kind'):
76 #if not hasattr(e, '_vcs_kind'):
@@ -422,6 +422,7 b' class GitRemote(RemoteBase):'
422 def branch(self, wire, commit_id):
422 def branch(self, wire, commit_id):
423 cache_on, context_uid, repo_id = self._cache_on(wire)
423 cache_on, context_uid, repo_id = self._cache_on(wire)
424 region = self._region(wire)
424 region = self._region(wire)
425
425 @region.conditional_cache_on_arguments(condition=cache_on)
426 @region.conditional_cache_on_arguments(condition=cache_on)
426 def _branch(_context_uid, _repo_id, _commit_id):
427 def _branch(_context_uid, _repo_id, _commit_id):
427 regex = re.compile('^refs/heads')
428 regex = re.compile('^refs/heads')
@@ -438,6 +439,7 b' class GitRemote(RemoteBase):'
438 def commit_branches(self, wire, commit_id):
439 def commit_branches(self, wire, commit_id):
439 cache_on, context_uid, repo_id = self._cache_on(wire)
440 cache_on, context_uid, repo_id = self._cache_on(wire)
440 region = self._region(wire)
441 region = self._region(wire)
442
441 @region.conditional_cache_on_arguments(condition=cache_on)
443 @region.conditional_cache_on_arguments(condition=cache_on)
442 def _commit_branches(_context_uid, _repo_id, _commit_id):
444 def _commit_branches(_context_uid, _repo_id, _commit_id):
443 repo_init = self._factory.repo_libgit2(wire)
445 repo_init = self._factory.repo_libgit2(wire)
@@ -944,6 +946,7 b' class GitRemote(RemoteBase):'
944 def message(self, wire, commit_id):
946 def message(self, wire, commit_id):
945 cache_on, context_uid, repo_id = self._cache_on(wire)
947 cache_on, context_uid, repo_id = self._cache_on(wire)
946 region = self._region(wire)
948 region = self._region(wire)
949
947 @region.conditional_cache_on_arguments(condition=cache_on)
950 @region.conditional_cache_on_arguments(condition=cache_on)
948 def _message(_repo_id, _commit_id):
951 def _message(_repo_id, _commit_id):
949 repo_init = self._factory.repo_libgit2(wire)
952 repo_init = self._factory.repo_libgit2(wire)
@@ -1183,7 +1186,7 b' class GitRemote(RemoteBase):'
1183
1186
1184 @reraise_safe_exceptions
1187 @reraise_safe_exceptions
1185 def node_annotate_legacy(self, wire, commit_id, path):
1188 def node_annotate_legacy(self, wire, commit_id, path):
1186 #note: replaced by pygit2 impelementation
1189 # note: replaced by pygit2 implementation
1187 cmd = ['blame', '-l', '--root', '-r', commit_id, '--', path]
1190 cmd = ['blame', '-l', '--root', '-r', commit_id, '--', path]
1188 # -l ==> outputs long shas (and we need all 40 characters)
1191 # -l ==> outputs long shas (and we need all 40 characters)
1189 # --root ==> doesn't put '^' character for boundaries
1192 # --root ==> doesn't put '^' character for boundaries
@@ -28,12 +28,13 b' import urllib.parse'
28 import urllib.error
28 import urllib.error
29 import traceback
29 import traceback
30
30
31 import svn.client
31
32 import svn.core
32 import svn.client # noqa
33 import svn.delta
33 import svn.core # noqa
34 import svn.diff
34 import svn.delta # noqa
35 import svn.fs
35 import svn.diff # noqa
36 import svn.repos
36 import svn.fs # noqa
37 import svn.repos # noqa
37
38
38 from vcsserver import svn_diff, exceptions, subprocessio, settings
39 from vcsserver import svn_diff, exceptions, subprocessio, settings
39 from vcsserver.base import RepoFactory, raise_from_original, ArchiveNode, archive_repo, BinaryEnvelope
40 from vcsserver.base import RepoFactory, raise_from_original, ArchiveNode, archive_repo, BinaryEnvelope
@@ -274,6 +275,7 b' class SvnRemote(RemoteBase):'
274 def node_properties(self, wire, path, revision):
275 def node_properties(self, wire, path, revision):
275 cache_on, context_uid, repo_id = self._cache_on(wire)
276 cache_on, context_uid, repo_id = self._cache_on(wire)
276 region = self._region(wire)
277 region = self._region(wire)
278
277 @region.conditional_cache_on_arguments(condition=cache_on)
279 @region.conditional_cache_on_arguments(condition=cache_on)
278 def _node_properties(_repo_id, _path, _revision):
280 def _node_properties(_repo_id, _path, _revision):
279 repo = self._factory.repo(wire)
281 repo = self._factory.repo(wire)
@@ -313,6 +315,7 b' class SvnRemote(RemoteBase):'
313
315
314 cache_on, context_uid, repo_id = self._cache_on(wire)
316 cache_on, context_uid, repo_id = self._cache_on(wire)
315 region = self._region(wire)
317 region = self._region(wire)
318
316 @region.conditional_cache_on_arguments(condition=cache_on)
319 @region.conditional_cache_on_arguments(condition=cache_on)
317 def _get_node_type(_repo_id, _path, _revision):
320 def _get_node_type(_repo_id, _path, _revision):
318 repo = self._factory.repo(wire)
321 repo = self._factory.repo(wire)
General Comments 0
You need to be logged in to leave comments. Login now