##// END OF EJS Templates
chore(deps): bumped pytest related deps
chore(deps): bumped pytest related deps

File last commit:

r1152:a0c49580 default
r1218:5a5e18ae tip default
Show More
base.py
193 lines | 6.3 KiB | text/x-python | PythonLexer
initial commit
r0 # RhodeCode VCSServer provides access to different vcs backends via network.
source-code: updated copyrights to 2023
r1126 # Copyright (C) 2014-2023 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
archive-caches: refactor and use cachedir based archive generation
r1122 import tempfile
initial commit
r0 import logging
py3: import/code fixes
r987 import urllib.parse
initial commit
r0
archive-caches: refactor and use cachedir based archive generation
r1122 from vcsserver.lib.rc_cache.archive_cache import get_archival_cache_store
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
exc-tracking: use more rich style tracebacks.
r1144 from vcsserver.lib.exc_tracking import format_exc
initial commit
r0 log = logging.getLogger(__name__)
lint: auto-fixes
r1152 class RepoFactory:
initial commit
r0 """
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):
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 pass
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(
python3: fixes and code optimization for python3.11
r1114 k, f'={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.
"""
exc-tracking: use more rich style tracebacks.
r1144 exc_info = sys.exc_info()
exc_type, exc_value, exc_traceback = 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
exc-tracking: use more rich style tracebacks.
r1144 new_exc._org_exc_tb = format_exc(exc_info)
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
lint: auto-fixes
r1152 class ArchiveNode:
archive: implemented efficient way to perform archive for each repository.
r894 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
archive-caches: refactor and use cachedir based archive generation
r1122 def store_archive_in_cache(node_walker, archive_key, kind, mtime, archive_at_path, archive_dir_name,
commit_id, write_metadata=True, extra_metadata=None, cache_config=None):
archive: implemented efficient way to perform archive for each repository.
r894 """
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 Function that would store generate archive and send it to a dedicated backend store
archive-caches: refactor and use cachedir based archive generation
r1122 In here we use diskcache
:param node_walker: a generator returning nodes to add to archive
:param archive_key: key used to store the path
:param kind: archive kind
:param mtime: time of creation
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 :param archive_at_path: default '/' the path at archive was started.
If this is not '/' it means it's a partial archive
archive-caches: refactor and use cachedir based archive generation
r1122 :param archive_dir_name: inside dir name when creating an archive
:param commit_id: commit sha of revision archive was created at
:param write_metadata:
:param extra_metadata:
:param cache_config:
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 walker should be a file walker, for example,
archive-caches: refactor and use cachedir based archive generation
r1122 def node_walker():
archive: implemented efficient way to perform archive for each repository.
r894 for file_info in files:
yield ArchiveNode(fn, mode, is_link, ctx[fn].data)
"""
extra_metadata = extra_metadata or {}
archive-caches: refactor and use cachedir based archive generation
r1122
d_cache = get_archival_cache_store(config=cache_config)
if archive_key in d_cache:
with d_cache as d_cache_reader:
reader, tag = d_cache_reader.get(archive_key, read=True, tag=True, retry=True)
return reader.name
archive_tmp_path = safe_bytes(tempfile.mkstemp()[1])
log.debug('Creating new temp archive in %s', archive_tmp_path)
archive: implemented efficient way to perform archive for each repository.
r894
if kind == "tgz":
archive-caches: refactor and use cachedir based archive generation
r1122 archiver = archival.tarit(archive_tmp_path, mtime, b"gz")
archive: implemented efficient way to perform archive for each repository.
r894 elif kind == "tbz2":
archive-caches: refactor and use cachedir based archive generation
r1122 archiver = archival.tarit(archive_tmp_path, mtime, b"bz2")
archive: implemented efficient way to perform archive for each repository.
r894 elif kind == 'zip':
archive-caches: refactor and use cachedir based archive generation
r1122 archiver = archival.zipit(archive_tmp_path, mtime)
archive: implemented efficient way to perform archive for each repository.
r894 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
archive-caches: refactor and use cachedir based archive generation
r1122 for f in node_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"
caches: use of global cache prefixes so we can keep compatability when switching from OLD rc to new python3 based
r1135 # directories which are not 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
archive-caches: refactor and use cachedir based archive generation
r1122 archiver.done()
# ensure set & get are atomic
with d_cache.transact():
with open(archive_tmp_path, 'rb') as archive_file:
add_result = d_cache.set(archive_key, archive_file, read=True, tag='db-name', retry=True)
if not add_result:
log.error('Failed to store cache for key=%s', archive_key)
os.remove(archive_tmp_path)
reader, tag = d_cache.get(archive_key, read=True, tag=True, retry=True)
if not reader:
raise AssertionError(f'empty reader on key={archive_key} added={add_result}')
return reader.name
protocol: introduced binaryEnvelope to return raw bytes via msgpack
r1089
lint: auto-fixes
r1152 class BinaryEnvelope:
archive-caches: refactor and use cachedir based archive generation
r1122 def __init__(self, val):
self.val = val
core: make binary envelope behave like bytes type object for serialization and internal API usage....
r1094
archive-caches: refactor and use cachedir based archive generation
r1122 class BytesEnvelope(bytes):
def __new__(cls, content):
if isinstance(content, bytes):
return super().__new__(cls, content)
else:
blame: use BinaryEnvelope wrapper to handle raw non-ascii content of files
r1139 raise TypeError('BytesEnvelope content= param must be bytes. Use BinaryEnvelope to wrap other types')
core: make binary envelope behave like bytes type object for serialization and internal API usage....
r1094
archive-caches: refactor and use cachedir based archive generation
r1122
class BinaryBytesEnvelope(BytesEnvelope):
pass