##// END OF EJS Templates
linting
linting

File last commit:

r1094:0553d498 python3
r1095:268c6aa4 python3
Show More
base.py
178 lines | 5.5 KiB | text/x-python | PythonLexer
initial commit
r0 # RhodeCode VCSServer provides access to different vcs backends via network.
code: update copyrights to 2020
r850 # Copyright (C) 2014-2020 RhodeCode GmbH
initial commit
r0 #
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
archive: implemented efficient way to perform archive for each repository.
r894 import os
exception-handling: better handling of remote exception and logging....
r171 import sys
import traceback
initial commit
r0 import logging
py3: import/code fixes
r987 import urllib.parse
initial commit
r0
caches: replaced beaker with dogpile cache.
r483 from vcsserver.lib.rc_cache import region_meta
initial commit
r0
archive: implemented efficient way to perform archive for each repository.
r894 from vcsserver import exceptions
from vcsserver.exceptions import NoContentException
vcsserver: fixed archival calls
r1072 from vcsserver.hgcompat import archival
core: various fixes of bytes vs str usage based on rhodecode-ce tests outputs
r1070 from vcsserver.str_utils import safe_bytes
caches: allow regional per repo caches, and invalidate caches via a remote call.
r961
initial commit
r0 log = logging.getLogger(__name__)
class RepoFactory(object):
"""
Utility to create instances of repository
It provides internal caching of the `repo` object based on
the :term:`call context`.
"""
caches: replaced beaker with dogpile cache.
r483 repo_type = None
initial commit
r0
caches: replaced beaker with dogpile cache.
r483 def __init__(self):
self._cache_region = region_meta.dogpile_cache_regions['repo_object']
initial commit
r0
def _create_config(self, path, config):
config = {}
return config
def _create_repo(self, wire, create):
raise NotImplementedError()
def repo(self, wire, create=False):
git: switched most git operations to libgit2
r725 raise NotImplementedError()
remote-clone: obfuscate also given query string paramas that RhodeCode uses. Fixes #4668
r106
def obfuscate_qs(query_string):
parse_qs: improved parsing of query string for obfuscation.
r107 if query_string is None:
return None
remote-clone: obfuscate also given query string paramas that RhodeCode uses. Fixes #4668
r106 parsed = []
py3: import/code fixes
r987 for k, v in urllib.parse.parse_qsl(query_string, keep_blank_values=True):
remote-clone: obfuscate also given query string paramas that RhodeCode uses. Fixes #4668
r106 if k in ['auth_token', 'api_key']:
v = "*****"
parsed.append((k, v))
parse_qs: improved parsing of query string for obfuscation.
r107 return '&'.join('{}{}'.format(
k, '={}'.format(v) if v else '') for k, v in parsed)
exception-handling: better handling of remote exception and logging....
r171
python3: code change for py3 support...
r1048 def raise_from_original(new_type, org_exc: Exception):
exception-handling: better handling of remote exception and logging....
r171 """
Raise a new exception type with original args and traceback.
"""
python3: code change for py3 support...
r1048
exception-handling: better handling of remote exception and logging....
r171 exc_type, exc_value, exc_traceback = sys.exc_info()
exception: store orginal tb and exc inside the new exception passed to rhodecode from vcsserver.
r621 new_exc = new_type(*exc_value.args)
python3: code change for py3 support...
r1048
exception: store orginal tb and exc inside the new exception passed to rhodecode from vcsserver.
r621 # store the original traceback into the new exc
python3: code change for py3 support...
r1048 new_exc._org_exc_tb = traceback.format_tb(exc_traceback)
exception-handling: better handling of remote exception and logging....
r171
try:
py3: import/code fixes
r987 raise new_exc.with_traceback(exc_traceback)
exception-handling: better handling of remote exception and logging....
r171 finally:
del exc_traceback
archive: implemented efficient way to perform archive for each repository.
r894
class ArchiveNode(object):
def __init__(self, path, mode, is_link, raw_bytes):
self.path = path
self.mode = mode
self.is_link = is_link
self.raw_bytes = raw_bytes
def archive_repo(walker, archive_dest_path, kind, mtime, archive_at_path,
archive_dir_name, commit_id, write_metadata=True, extra_metadata=None):
"""
walker should be a file walker, for example:
def walker():
for file_info in files:
yield ArchiveNode(fn, mode, is_link, ctx[fn].data)
"""
extra_metadata = extra_metadata or {}
vcsserver: fixed archival calls
r1072 archive_dest_path = safe_bytes(archive_dest_path)
archive: implemented efficient way to perform archive for each repository.
r894
if kind == "tgz":
vcsserver: fixed archival calls
r1072 archiver = archival.tarit(archive_dest_path, mtime, b"gz")
archive: implemented efficient way to perform archive for each repository.
r894 elif kind == "tbz2":
vcsserver: fixed archival calls
r1072 archiver = archival.tarit(archive_dest_path, mtime, b"bz2")
archive: implemented efficient way to perform archive for each repository.
r894 elif kind == 'zip':
archiver = archival.zipit(archive_dest_path, mtime)
else:
raise exceptions.ArchiveException()(
vcsserver: fixed archival calls
r1072 f'Remote does not support: "{kind}" archive type.')
archive: implemented efficient way to perform archive for each repository.
r894
for f in walker(commit_id, archive_at_path):
core: few python3 fixes found during ce tests runs
r1085 f_path = os.path.join(safe_bytes(archive_dir_name), safe_bytes(f.path).lstrip(b'/'))
archive: implemented efficient way to perform archive for each repository.
r894 try:
archiver.addfile(f_path, f.mode, f.is_link, f.raw_bytes())
except NoContentException:
# NOTE(marcink): this is a special case for SVN so we can create "empty"
# directories which arent supported by archiver
core: few python3 fixes found during ce tests runs
r1085 archiver.addfile(os.path.join(f_path, b'.dir'), f.mode, f.is_link, b'')
archive: implemented efficient way to perform archive for each repository.
r894
if write_metadata:
metadata = dict([
('commit_id', commit_id),
('mtime', mtime),
])
metadata.update(extra_metadata)
core: various fixes of bytes vs str usage based on rhodecode-ce tests outputs
r1070 meta = [safe_bytes(f"{f_name}:{value}") for f_name, value in metadata.items()]
f_path = os.path.join(safe_bytes(archive_dir_name), b'.archival.txt')
archiver.addfile(f_path, 0o644, False, b'\n'.join(meta))
archive: implemented efficient way to perform archive for each repository.
r894
return archiver.done()
protocol: introduced binaryEnvelope to return raw bytes via msgpack
r1089
class BinaryEnvelope(object):
def __init__(self, value, bin_type=True):
self.value = value
self.bin_type = bin_type
core: make binary envelope behave like bytes type object for serialization and internal API usage....
r1094
def __len__(self):
return len(self.value)
def __getitem__(self, index):
return self.value[index]
def __iter__(self):
return iter(self.value)
def __str__(self):
return str(self.value)
def __repr__(self):
return repr(self.value)
def __eq__(self, other):
if isinstance(other, BinaryEnvelope):
return self.value == other.value
return False
def __ne__(self, other):
return not self.__eq__(other)
def __add__(self, other):
if isinstance(other, BinaryEnvelope):
return BinaryEnvelope(self.value + other.value)
raise TypeError(f"unsupported operand type(s) for +: 'BinaryEnvelope' and '{type(other)}'")
def __radd__(self, other):
if isinstance(other, BinaryEnvelope):
return BinaryEnvelope(other.value + self.value)
raise TypeError(f"unsupported operand type(s) for +: '{type(other)}' and 'BinaryEnvelope'")