##// END OF EJS Templates
libs: more python3 reformats
super-admin -
r5091:9ce86a18 default
parent child Browse files
Show More
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -95,7 +93,7 b' def connect_vcs(server_and_port, protoco'
95 if protocol == 'http':
93 if protocol == 'http':
96 connect_http(server_and_port)
94 connect_http(server_and_port)
97 else:
95 else:
98 raise Exception('Invalid vcs server protocol "{}"'.format(protocol))
96 raise Exception(f'Invalid vcs server protocol "{protocol}"')
99
97
100
98
101 class CurlSession(object):
99 class CurlSession(object):
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -247,7 +247,7 b' class MergeResponse(object):'
247 self.metadata = metadata or {}
247 self.metadata = metadata or {}
248
248
249 def __repr__(self):
249 def __repr__(self):
250 return '<MergeResponse:{} {}>'.format(self.label, self.failure_reason)
250 return f'<MergeResponse:{self.label} {self.failure_reason}>'
251
251
252 def __eq__(self, other):
252 def __eq__(self, other):
253 same_instance = isinstance(other, self.__class__)
253 same_instance = isinstance(other, self.__class__)
@@ -320,8 +320,8 b' class BaseRepository(object):'
320 """
320 """
321
321
322 DEFAULT_BRANCH_NAME = None
322 DEFAULT_BRANCH_NAME = None
323 DEFAULT_CONTACT = u"Unknown"
323 DEFAULT_CONTACT = "Unknown"
324 DEFAULT_DESCRIPTION = u"unknown"
324 DEFAULT_DESCRIPTION = "unknown"
325 EMPTY_COMMIT_ID = '0' * 40
325 EMPTY_COMMIT_ID = '0' * 40
326 COMMIT_ID_PAT = re.compile(r'[0-9a-fA-F]{40}')
326 COMMIT_ID_PAT = re.compile(r'[0-9a-fA-F]{40}')
327
327
@@ -347,7 +347,7 b' class BaseRepository(object):'
347 raise NotImplementedError
347 raise NotImplementedError
348
348
349 def __repr__(self):
349 def __repr__(self):
350 return '<%s at %s>' % (self.__class__.__name__, self.path)
350 return '<{} at {}>'.format(self.__class__.__name__, self.path)
351
351
352 def __len__(self):
352 def __len__(self):
353 return self.count()
353 return self.count()
@@ -716,7 +716,7 b' class BaseRepository(object):'
716 """
716 """
717 return os.path.join(
717 return os.path.join(
718 os.path.dirname(repo_path),
718 os.path.dirname(repo_path),
719 '.__shadow_%s_%s' % (os.path.basename(repo_path), workspace_id))
719 '.__shadow_{}_{}'.format(os.path.basename(repo_path), workspace_id))
720
720
721 @classmethod
721 @classmethod
722 def _get_shadow_repository_path(cls, repo_path, repo_id, workspace_id):
722 def _get_shadow_repository_path(cls, repo_path, repo_id, workspace_id):
@@ -728,7 +728,7 b' class BaseRepository(object):'
728 else:
728 else:
729 return os.path.join(
729 return os.path.join(
730 os.path.dirname(repo_path),
730 os.path.dirname(repo_path),
731 '.__shadow_repo_%s_%s' % (repo_id, workspace_id))
731 '.__shadow_repo_{}_{}'.format(repo_id, workspace_id))
732
732
733 def cleanup_merge_workspace(self, repo_id, workspace_id):
733 def cleanup_merge_workspace(self, repo_id, workspace_id):
734 """
734 """
@@ -806,7 +806,7 b' class BaseRepository(object):'
806
806
807 def _validate_branch_name(self, branch_name):
807 def _validate_branch_name(self, branch_name):
808 if branch_name and branch_name not in self.branches_all:
808 if branch_name and branch_name not in self.branches_all:
809 msg = ("Branch %s not found in %s" % (branch_name, self))
809 msg = ("Branch {} not found in {}".format(branch_name, self))
810 raise BranchDoesNotExistError(msg)
810 raise BranchDoesNotExistError(msg)
811
811
812 #
812 #
@@ -1342,7 +1342,7 b' class BaseCommit(object):'
1342 """
1342 """
1343 Returns total number of bytes from contents of all filenodes.
1343 Returns total number of bytes from contents of all filenodes.
1344 """
1344 """
1345 return sum((node.size for node in self.get_filenodes_generator()))
1345 return sum(node.size for node in self.get_filenodes_generator())
1346
1346
1347 def walk(self, topurl=''):
1347 def walk(self, topurl=''):
1348 """
1348 """
@@ -1369,16 +1369,14 b' class BaseCommit(object):'
1369 for dir_node in top_node.dirs:
1369 for dir_node in top_node.dirs:
1370 if has_default_pre_load:
1370 if has_default_pre_load:
1371 dir_node.default_pre_load = default_pre_load
1371 dir_node.default_pre_load = default_pre_load
1372 for tup in self.walk(dir_node):
1372 yield from self.walk(dir_node)
1373 yield tup
1374
1373
1375 def get_filenodes_generator(self):
1374 def get_filenodes_generator(self):
1376 """
1375 """
1377 Returns generator that yields *all* file nodes.
1376 Returns generator that yields *all* file nodes.
1378 """
1377 """
1379 for topnode, dirs, files in self.walk():
1378 for topnode, dirs, files in self.walk():
1380 for node in files:
1379 yield from files
1381 yield node
1382
1380
1383 #
1381 #
1384 # Utilities for sub classes to support consistent behavior
1382 # Utilities for sub classes to support consistent behavior
@@ -1426,7 +1424,7 b' class BaseChangeset(BaseCommit, metaclas'
1426 def __new__(cls, *args, **kwargs):
1424 def __new__(cls, *args, **kwargs):
1427 warnings.warn(
1425 warnings.warn(
1428 "Use BaseCommit instead of BaseChangeset", DeprecationWarning)
1426 "Use BaseCommit instead of BaseChangeset", DeprecationWarning)
1429 return super(BaseChangeset, cls).__new__(cls, *args, **kwargs)
1427 return super().__new__(cls, *args, **kwargs)
1430
1428
1431
1429
1432 class BaseInMemoryCommit(object):
1430 class BaseInMemoryCommit(object):
@@ -1585,7 +1583,7 b' class BaseInMemoryCommit(object):'
1585 pass
1583 pass
1586 else:
1584 else:
1587 raise NodeAlreadyExistsError(
1585 raise NodeAlreadyExistsError(
1588 "Node `%s` already exists at %s" % (node.path, p))
1586 "Node `{}` already exists at {}".format(node.path, p))
1589
1587
1590 # Check nodes marked as changed
1588 # Check nodes marked as changed
1591 missing = set(self.changed)
1589 missing = set(self.changed)
@@ -1668,7 +1666,7 b' class BaseInMemoryChangeset(BaseInMemory'
1668 def __new__(cls, *args, **kwargs):
1666 def __new__(cls, *args, **kwargs):
1669 warnings.warn(
1667 warnings.warn(
1670 "Use BaseCommit instead of BaseInMemoryCommit", DeprecationWarning)
1668 "Use BaseCommit instead of BaseInMemoryCommit", DeprecationWarning)
1671 return super(BaseInMemoryChangeset, cls).__new__(cls, *args, **kwargs)
1669 return super().__new__(cls, *args, **kwargs)
1672
1670
1673
1671
1674 class EmptyCommit(BaseCommit):
1672 class EmptyCommit(BaseCommit):
@@ -1745,7 +1743,7 b' class EmptyChangeset(EmptyCommit, metacl'
1745 warnings.warn(
1743 warnings.warn(
1746 "Parameter requested_revision not supported anymore",
1744 "Parameter requested_revision not supported anymore",
1747 DeprecationWarning)
1745 DeprecationWarning)
1748 super(EmptyChangeset, self).__init__(
1746 super().__init__(
1749 commit_id=cs, repo=repo, alias=alias, idx=revision,
1747 commit_id=cs, repo=repo, alias=alias, idx=revision,
1750 message=message, author=author, date=date)
1748 message=message, author=author, date=date)
1751
1749
@@ -1832,7 +1830,7 b' class Config(object):'
1832 return clone
1830 return clone
1833
1831
1834 def __repr__(self):
1832 def __repr__(self):
1835 return '<Config(%s sections) at %s>' % (
1833 return '<Config({} sections) at {}>'.format(
1836 len(self._values), hex(id(self)))
1834 len(self._values), hex(id(self)))
1837
1835
1838 def items(self, section):
1836 def items(self, section):
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -476,8 +474,7 b' class GitCommit(base.BaseCommit):'
476 # ConfigParser fails if there are whitespaces, also it needs an iterable
474 # ConfigParser fails if there are whitespaces, also it needs an iterable
477 # file like content
475 # file like content
478 def iter_content(_content):
476 def iter_content(_content):
479 for line in _content.splitlines():
477 yield from _content.splitlines()
480 yield line
481
478
482 parser = configparser.RawConfigParser()
479 parser = configparser.RawConfigParser()
483 parser.read_file(iter_content(submodules_node.content))
480 parser.read_file(iter_content(submodules_node.content))
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -55,7 +53,7 b' class GitRepository(BaseRepository):'
55 Git repository backend.
53 Git repository backend.
56 """
54 """
57 DEFAULT_BRANCH_NAME = os.environ.get('GIT_DEFAULT_BRANCH_NAME') or 'master'
55 DEFAULT_BRANCH_NAME = os.environ.get('GIT_DEFAULT_BRANCH_NAME') or 'master'
58 DEFAULT_REF = 'branch:{}'.format(DEFAULT_BRANCH_NAME)
56 DEFAULT_REF = f'branch:{DEFAULT_BRANCH_NAME}'
59
57
60 contact = BaseRepository.DEFAULT_CONTACT
58 contact = BaseRepository.DEFAULT_CONTACT
61
59
@@ -95,8 +93,8 b' class GitRepository(BaseRepository):'
95 return commit_ids
93 return commit_ids
96
94
97 def _rebuild_cache(self, commit_ids):
95 def _rebuild_cache(self, commit_ids):
98 self._commit_ids = dict((commit_id, index)
96 self._commit_ids = {commit_id: index
99 for index, commit_id in enumerate(commit_ids))
97 for index, commit_id in enumerate(commit_ids)}
100
98
101 def run_git_command(self, cmd, **opts):
99 def run_git_command(self, cmd, **opts):
102 """
100 """
@@ -375,7 +373,7 b' class GitRepository(BaseRepository):'
375 if name in self.tags:
373 if name in self.tags:
376 raise TagAlreadyExistError("Tag %s already exists" % name)
374 raise TagAlreadyExistError("Tag %s already exists" % name)
377 commit = self.get_commit(commit_id=commit_id)
375 commit = self.get_commit(commit_id=commit_id)
378 message = message or "Added tag %s for commit %s" % (name, commit.raw_id)
376 message = message or "Added tag {} for commit {}".format(name, commit.raw_id)
379
377
380 self._remote.set_refs('refs/tags/%s' % name, commit.raw_id)
378 self._remote.set_refs('refs/tags/%s' % name, commit.raw_id)
381
379
@@ -421,7 +419,7 b' class GitRepository(BaseRepository):'
421 return tree
419 return tree
422
420
423 def get_remote_ref(self, ref_name):
421 def get_remote_ref(self, ref_name):
424 ref_key = 'refs/remotes/origin/{}'.format(safe_str(ref_name))
422 ref_key = f'refs/remotes/origin/{safe_str(ref_name)}'
425 try:
423 try:
426 return self._refs[ref_key]
424 return self._refs[ref_key]
427 except Exception:
425 except Exception:
@@ -643,7 +641,7 b' class GitRepository(BaseRepository):'
643 else:
641 else:
644 output, __ = repo1.run_git_command(
642 output, __ = repo1.run_git_command(
645 ['log', '--reverse', '--pretty=format: %H', '-s',
643 ['log', '--reverse', '--pretty=format: %H', '-s',
646 '%s..%s' % (commit_id1, commit_id2)])
644 '{}..{}'.format(commit_id1, commit_id2)])
647 commits = [
645 commits = [
648 repo1.get_commit(commit_id=commit_id, pre_load=pre_load)
646 repo1.get_commit(commit_id=commit_id, pre_load=pre_load)
649 for commit_id in self.COMMIT_ID_PAT.findall(output)]
647 for commit_id in self.COMMIT_ID_PAT.findall(output)]
@@ -797,7 +795,7 b' class GitRepository(BaseRepository):'
797 self.run_git_command(cmd, fail_on_stderr=False)
795 self.run_git_command(cmd, fail_on_stderr=False)
798
796
799 def _local_reset(self, branch_name):
797 def _local_reset(self, branch_name):
800 branch_name = '{}'.format(branch_name)
798 branch_name = f'{branch_name}'
801 cmd = ['reset', '--hard', branch_name, '--']
799 cmd = ['reset', '--hard', branch_name, '--']
802 self.run_git_command(cmd, fail_on_stderr=False)
800 self.run_git_command(cmd, fail_on_stderr=False)
803
801
@@ -880,7 +878,7 b' class GitRepository(BaseRepository):'
880 files = self.run_git_command(['diff', '--name-only', '--diff-filter', 'U'],
878 files = self.run_git_command(['diff', '--name-only', '--diff-filter', 'U'],
881 fail_on_stderr=False)[0].splitlines()
879 fail_on_stderr=False)[0].splitlines()
882 # NOTE(marcink): we add U notation for consistent with HG backend output
880 # NOTE(marcink): we add U notation for consistent with HG backend output
883 unresolved = ['U {}'.format(f) for f in files]
881 unresolved = [f'U {f}' for f in files]
884
882
885 # Cleanup any merge leftovers
883 # Cleanup any merge leftovers
886 self._remote.invalidate_vcs_cache()
884 self._remote.invalidate_vcs_cache()
@@ -914,7 +912,7 b' class GitRepository(BaseRepository):'
914 target_repo._local_pull(self.path, source_branch)
912 target_repo._local_pull(self.path, source_branch)
915 else:
913 else:
916 cmd = ['push', os.path.abspath(repository_path),
914 cmd = ['push', os.path.abspath(repository_path),
917 '%s:%s' % (source_branch, target_branch)]
915 '{}:{}'.format(source_branch, target_branch)]
918 gitenv = {}
916 gitenv = {}
919 if rc_scm_data:
917 if rc_scm_data:
920 gitenv.update({'RC_SCM_DATA': rc_scm_data})
918 gitenv.update({'RC_SCM_DATA': rc_scm_data})
@@ -924,7 +922,7 b' class GitRepository(BaseRepository):'
924 self.run_git_command(cmd, fail_on_stderr=False, extra_env=gitenv)
922 self.run_git_command(cmd, fail_on_stderr=False, extra_env=gitenv)
925
923
926 def _get_new_pr_branch(self, source_branch, target_branch):
924 def _get_new_pr_branch(self, source_branch, target_branch):
927 prefix = 'pr_%s-%s_' % (source_branch, target_branch)
925 prefix = 'pr_{}-{}_'.format(source_branch, target_branch)
928 pr_branches = []
926 pr_branches = []
929 for branch in self.branches:
927 for branch in self.branches:
930 if branch.startswith(prefix):
928 if branch.startswith(prefix):
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -291,7 +289,7 b' class MercurialCommit(base.BaseCommit):'
291
289
292 if self._get_kind(path) != NodeKind.DIR:
290 if self._get_kind(path) != NodeKind.DIR:
293 raise CommitError(
291 raise CommitError(
294 "Directory does not exist for idx %s at '%s'" % (self.raw_id, path))
292 "Directory does not exist for idx {} at '{}'".format(self.raw_id, path))
295 path = self._fix_path(path)
293 path = self._fix_path(path)
296
294
297 filenodes = [
295 filenodes = [
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -104,8 +102,8 b' class MercurialRepository(BaseRepository'
104 return commit_ids
102 return commit_ids
105
103
106 def _rebuild_cache(self, commit_ids):
104 def _rebuild_cache(self, commit_ids):
107 self._commit_ids = dict((commit_id, index)
105 self._commit_ids = {commit_id: index
108 for index, commit_id in enumerate(commit_ids))
106 for index, commit_id in enumerate(commit_ids)}
109
107
110 @CachedProperty
108 @CachedProperty
111 def branches(self):
109 def branches(self):
@@ -180,7 +178,7 b' class MercurialRepository(BaseRepository'
180 local = kwargs.setdefault('local', False)
178 local = kwargs.setdefault('local', False)
181
179
182 if message is None:
180 if message is None:
183 message = "Added tag %s for commit %s" % (name, commit.short_id)
181 message = "Added tag {} for commit {}".format(name, commit.short_id)
184
182
185 date, tz = date_to_timestamp_plus_offset(date)
183 date, tz = date_to_timestamp_plus_offset(date)
186
184
@@ -531,17 +529,17 b' class MercurialRepository(BaseRepository'
531 commit_filter = []
529 commit_filter = []
532
530
533 if branch_name and not branch_ancestors:
531 if branch_name and not branch_ancestors:
534 commit_filter.append('branch("%s")' % (branch_name,))
532 commit_filter.append('branch("{}")'.format(branch_name))
535 elif branch_name and branch_ancestors:
533 elif branch_name and branch_ancestors:
536 commit_filter.append('ancestors(branch("%s"))' % (branch_name,))
534 commit_filter.append('ancestors(branch("{}"))'.format(branch_name))
537
535
538 if start_date and not end_date:
536 if start_date and not end_date:
539 commit_filter.append('date(">%s")' % (start_date,))
537 commit_filter.append('date(">{}")'.format(start_date))
540 if end_date and not start_date:
538 if end_date and not start_date:
541 commit_filter.append('date("<%s")' % (end_date,))
539 commit_filter.append('date("<{}")'.format(end_date))
542 if start_date and end_date:
540 if start_date and end_date:
543 commit_filter.append(
541 commit_filter.append(
544 'date(">%s") and date("<%s")' % (start_date, end_date))
542 'date(">{}") and date("<{}")'.format(start_date, end_date))
545
543
546 if not show_hidden:
544 if not show_hidden:
547 commit_filter.append('not obsolete()')
545 commit_filter.append('not obsolete()')
@@ -659,7 +657,7 b' class MercurialRepository(BaseRepository'
659 unresolved = None
657 unresolved = None
660 if use_rebase:
658 if use_rebase:
661 try:
659 try:
662 bookmark_name = 'rcbook%s%s' % (source_ref_commit_id, target_ref_commit_id)
660 bookmark_name = 'rcbook{}{}'.format(source_ref_commit_id, target_ref_commit_id)
663 self.bookmark(bookmark_name, revision=source_ref.commit_id)
661 self.bookmark(bookmark_name, revision=source_ref.commit_id)
664 self._remote.rebase(
662 self._remote.rebase(
665 source=source_ref_commit_id, dest=target_ref_commit_id)
663 source=source_ref_commit_id, dest=target_ref_commit_id)
@@ -689,7 +687,7 b' class MercurialRepository(BaseRepository'
689 self._remote.invalidate_vcs_cache()
687 self._remote.invalidate_vcs_cache()
690 self._remote.commit(
688 self._remote.commit(
691 message=safe_str(merge_message),
689 message=safe_str(merge_message),
692 username=safe_str('%s <%s>' % (user_name, user_email)))
690 username=safe_str('{} <{}>'.format(user_name, user_email)))
693 self._remote.invalidate_vcs_cache()
691 self._remote.invalidate_vcs_cache()
694 return self._identify(), True
692 return self._identify(), True
695 except RepositoryError as e:
693 except RepositoryError as e:
@@ -716,11 +714,11 b' class MercurialRepository(BaseRepository'
716 commit needs to be pushed.
714 commit needs to be pushed.
717 """
715 """
718 self._update(source_ref.commit_id)
716 self._update(source_ref.commit_id)
719 message = close_message or "Closing branch: `{}`".format(source_ref.name)
717 message = close_message or f"Closing branch: `{source_ref.name}`"
720 try:
718 try:
721 self._remote.commit(
719 self._remote.commit(
722 message=safe_str(message),
720 message=safe_str(message),
723 username=safe_str('%s <%s>' % (user_name, user_email)),
721 username=safe_str('{} <{}>'.format(user_name, user_email)),
724 close_branch=True)
722 close_branch=True)
725 self._remote.invalidate_vcs_cache()
723 self._remote.invalidate_vcs_cache()
726 return self._identify(), True
724 return self._identify(), True
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -55,7 +53,7 b' class SubversionCommit(base.BaseCommit):'
55 # which knows how to translate commit index and commit id
53 # which knows how to translate commit index and commit id
56 self.raw_id = commit_id
54 self.raw_id = commit_id
57 self.short_id = commit_id
55 self.short_id = commit_id
58 self.id = 'r%s' % (commit_id, )
56 self.id = 'r{}'.format(commit_id)
59
57
60 # TODO: Implement the following placeholder attributes
58 # TODO: Implement the following placeholder attributes
61 self.nodes = {}
59 self.nodes = {}
@@ -201,7 +199,7 b' class SubversionCommit(base.BaseCommit):'
201 return nodes.NodeKind.DIR
199 return nodes.NodeKind.DIR
202 else:
200 else:
203 raise CommitError(
201 raise CommitError(
204 "Node does not exist at the given path '%s'" % (path, ))
202 "Node does not exist at the given path '{}'".format(path))
205
203
206 @LazyProperty
204 @LazyProperty
207 def _changes_cache(self):
205 def _changes_cache(self):
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -223,7 +221,7 b' class SubversionRepository(base.BaseRepo'
223 commit_idx = svn_rev - 1
221 commit_idx = svn_rev - 1
224 if commit_idx >= len(self.commit_ids):
222 if commit_idx >= len(self.commit_ids):
225 raise CommitDoesNotExistError(
223 raise CommitDoesNotExistError(
226 "Commit at index %s does not exist." % (commit_idx, ))
224 "Commit at index {} does not exist.".format(commit_idx))
227 return commit_idx
225 return commit_idx
228
226
229 @staticmethod
227 @staticmethod
@@ -247,7 +245,7 b' class SubversionRepository(base.BaseRepo'
247
245
248 def _check_path(self):
246 def _check_path(self):
249 if not os.path.exists(self.path):
247 if not os.path.exists(self.path):
250 raise VCSError('Path "%s" does not exist!' % (self.path, ))
248 raise VCSError('Path "{}" does not exist!'.format(self.path))
251 if not self._remote.is_path_valid_repository(self.path):
249 if not self._remote.is_path_valid_repository(self.path):
252 raise VCSError(
250 raise VCSError(
253 'Path "%s" does not contain a Subversion repository' %
251 'Path "%s" does not contain a Subversion repository' %
@@ -286,7 +284,7 b' class SubversionRepository(base.BaseRepo'
286 try:
284 try:
287 commit_id = self.commit_ids[commit_idx]
285 commit_id = self.commit_ids[commit_idx]
288 except IndexError:
286 except IndexError:
289 raise CommitDoesNotExistError('No commit with idx: {}'.format(commit_idx))
287 raise CommitDoesNotExistError(f'No commit with idx: {commit_idx}')
290
288
291 commit_id = self._sanitize_commit_id(commit_id)
289 commit_id = self._sanitize_commit_id(commit_id)
292 commit = SubversionCommit(repository=self, commit_id=commit_id)
290 commit = SubversionCommit(repository=self, commit_id=commit_id)
@@ -343,11 +341,11 b' class SubversionRepository(base.BaseRepo'
343 return commit_id
341 return commit_id
344 else:
342 else:
345 raise CommitDoesNotExistError(
343 raise CommitDoesNotExistError(
346 "Commit %s does not exist." % (commit_id, ))
344 "Commit {} does not exist.".format(commit_id))
347 if commit_id not in [
345 if commit_id not in [
348 None, 'HEAD', 'tip', self.DEFAULT_BRANCH_NAME]:
346 None, 'HEAD', 'tip', self.DEFAULT_BRANCH_NAME]:
349 raise CommitDoesNotExistError(
347 raise CommitDoesNotExistError(
350 "Commit id %s not understood." % (commit_id, ))
348 "Commit id {} not understood.".format(commit_id))
351 svn_rev = self._remote.lookup('HEAD')
349 svn_rev = self._remote.lookup('HEAD')
352 return str(svn_rev)
350 return str(svn_rev)
353
351
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2016-2023 RhodeCode GmbH
1 # Copyright (C) 2016-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -68,7 +66,7 b' def _remote_call(url, payload, exception'
68 log.warning(f'Received a "Connection reset by peer" error. '
66 log.warning(f'Received a "Connection reset by peer" error. '
69 f'Retrying... ({attempt + 1}/{retries})')
67 f'Retrying... ({attempt + 1}/{retries})')
70 continue # Retry if connection reset error.
68 continue # Retry if connection reset error.
71 msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc())
69 msg = f'{e}. \npycurl traceback: {traceback.format_exc()}'
72 raise exceptions.HttpVCSCommunicationError(msg)
70 raise exceptions.HttpVCSCommunicationError(msg)
73 except Exception as e:
71 except Exception as e:
74 message = getattr(e, 'message', '')
72 message = getattr(e, 'message', '')
@@ -130,7 +128,7 b' def _streaming_remote_call(url, payload,'
130 response = session.post(url, data=msgpack.packb(payload), headers=headers)
128 response = session.post(url, data=msgpack.packb(payload), headers=headers)
131 except pycurl.error as e:
129 except pycurl.error as e:
132 error_code, error_message = e.args
130 error_code, error_message = e.args
133 msg = '{}. \npycurl traceback: {}'.format(e, traceback.format_exc())
131 msg = f'{e}. \npycurl traceback: {traceback.format_exc()}'
134 raise exceptions.HttpVCSCommunicationError(msg)
132 raise exceptions.HttpVCSCommunicationError(msg)
135 except Exception as e:
133 except Exception as e:
136 message = getattr(e, 'message', '')
134 message = getattr(e, 'message', '')
@@ -180,7 +178,7 b' class RemoteVCSMaker(object):'
180
178
181 @classmethod
179 @classmethod
182 def init_cache_region(cls, repo_id):
180 def init_cache_region(cls, repo_id):
183 cache_namespace_uid = 'repo.{}'.format(repo_id)
181 cache_namespace_uid = f'repo.{repo_id}'
184 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
182 region = rc_cache.get_or_create_region('cache_repo', cache_namespace_uid)
185 return region, cache_namespace_uid
183 return region, cache_namespace_uid
186
184
@@ -403,8 +401,7 b' class VcsHttpProxy(object):'
403 unpacker = msgpack.Unpacker()
401 unpacker = msgpack.Unpacker()
404 for line in result.iter_content(chunk_size=self.CHUNK_SIZE):
402 for line in result.iter_content(chunk_size=self.CHUNK_SIZE):
405 unpacker.feed(line)
403 unpacker.feed(line)
406 for chunk in unpacker:
404 yield from unpacker
407 yield chunk
408
405
409 def _get_result(self, result):
406 def _get_result(self, result):
410 iterator = self._iterate(result)
407 iterator = self._iterate(result)
@@ -1,4 +1,3 b''
1
2 # Copyright (C) 2010-2023 RhodeCode GmbH
1 # Copyright (C) 2010-2023 RhodeCode GmbH
3 #
2 #
4 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -56,8 +54,8 b" HOOKS_HOST = '127.0.0.1'"
56
54
57
55
58 MERGE_MESSAGE_TMPL = (
56 MERGE_MESSAGE_TMPL = (
59 u'Merge pull request !{pr_id} from {source_repo} {source_ref_name}\n\n '
57 'Merge pull request !{pr_id} from {source_repo} {source_ref_name}\n\n '
60 u'{pr_title}')
58 '{pr_title}')
61 MERGE_DRY_RUN_MESSAGE = 'dry_run_merge_message_from_rhodecode'
59 MERGE_DRY_RUN_MESSAGE = 'dry_run_merge_message_from_rhodecode'
62 MERGE_DRY_RUN_USER = 'Dry-Run User'
60 MERGE_DRY_RUN_USER = 'Dry-Run User'
63 MERGE_DRY_RUN_EMAIL = 'dry-run-merge@rhodecode.com'
61 MERGE_DRY_RUN_EMAIL = 'dry-run-merge@rhodecode.com'
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -222,7 +220,7 b' def map_vcs_exceptions(func):'
222 # replace the first argument with a prefix exc name
220 # replace the first argument with a prefix exc name
223 args = ['{}:{}'.format(exc_name, _args[0] if _args else '?')] + _args[1:]
221 args = ['{}:{}'.format(exc_name, _args[0] if _args else '?')] + _args[1:]
224 else:
222 else:
225 args = [__traceback_info__ or '{}: UnhandledException'.format(exc_name)]
223 args = [__traceback_info__ or f'{exc_name}: UnhandledException']
226 if debug or __traceback_info__ and kind not in ['unhandled', 'lookup']:
224 if debug or __traceback_info__ and kind not in ['unhandled', 'lookup']:
227 # for other than unhandled errors also log the traceback
225 # for other than unhandled errors also log the traceback
228 # can be useful for debugging
226 # can be useful for debugging
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2016-2023 RhodeCode GmbH
1 # Copyright (C) 2016-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -355,7 +355,7 b' class FileNode(Node):'
355 self._set_bulk_properties(pre_load)
355 self._set_bulk_properties(pre_load)
356
356
357 def __eq__(self, other):
357 def __eq__(self, other):
358 eq = super(FileNode, self).__eq__(other)
358 eq = super().__eq__(other)
359 if eq is not None:
359 if eq is not None:
360 return eq
360 return eq
361 return self.content == other.content
361 return self.content == other.content
@@ -365,7 +365,7 b' class FileNode(Node):'
365 return hash((self.path, raw_id))
365 return hash((self.path, raw_id))
366
366
367 def __lt__(self, other):
367 def __lt__(self, other):
368 lt = super(FileNode, self).__lt__(other)
368 lt = super().__lt__(other)
369 if lt is not None:
369 if lt is not None:
370 return lt
370 return lt
371 return self.content < other.content
371 return self.content < other.content
@@ -751,17 +751,16 b' class DirNode(Node):'
751 """
751 """
752 if nodes and commit:
752 if nodes and commit:
753 raise NodeError("Cannot use both nodes and commit")
753 raise NodeError("Cannot use both nodes and commit")
754 super(DirNode, self).__init__(path, NodeKind.DIR)
754 super().__init__(path, NodeKind.DIR)
755 self.commit = commit
755 self.commit = commit
756 self._nodes = nodes
756 self._nodes = nodes
757 self.default_pre_load = default_pre_load or ['is_binary', 'size']
757 self.default_pre_load = default_pre_load or ['is_binary', 'size']
758
758
759 def __iter__(self):
759 def __iter__(self):
760 for node in self.nodes:
760 yield from self.nodes
761 yield node
762
761
763 def __eq__(self, other):
762 def __eq__(self, other):
764 eq = super(DirNode, self).__eq__(other)
763 eq = super().__eq__(other)
765 if eq is not None:
764 if eq is not None:
766 return eq
765 return eq
767 # check without entering each dir
766 # check without entering each dir
@@ -770,7 +769,7 b' class DirNode(Node):'
770 return self_nodes_paths == other_nodes_paths
769 return self_nodes_paths == other_nodes_paths
771
770
772 def __lt__(self, other):
771 def __lt__(self, other):
773 lt = super(DirNode, self).__lt__(other)
772 lt = super().__lt__(other)
774 if lt is not None:
773 if lt is not None:
775 return lt
774 return lt
776 # check without entering each dir
775 # check without entering each dir
@@ -788,16 +787,16 b' class DirNode(Node):'
788 nodes = self.commit.get_nodes(self.path, pre_load=self.default_pre_load)
787 nodes = self.commit.get_nodes(self.path, pre_load=self.default_pre_load)
789 else:
788 else:
790 nodes = self._nodes
789 nodes = self._nodes
791 self._nodes_dict = dict((node.path, node) for node in nodes)
790 self._nodes_dict = {node.path: node for node in nodes}
792 return sorted(nodes)
791 return sorted(nodes)
793
792
794 @LazyProperty
793 @LazyProperty
795 def files(self):
794 def files(self):
796 return sorted((node for node in self.nodes if node.is_file()))
795 return sorted(node for node in self.nodes if node.is_file())
797
796
798 @LazyProperty
797 @LazyProperty
799 def dirs(self):
798 def dirs(self):
800 return sorted((node for node in self.nodes if node.is_dir()))
799 return sorted(node for node in self.nodes if node.is_dir())
801
800
802 def get_node(self, path):
801 def get_node(self, path):
803 """
802 """
@@ -873,7 +872,7 b' class RootNode(DirNode):'
873 """
872 """
874
873
875 def __init__(self, nodes=(), commit=None):
874 def __init__(self, nodes=(), commit=None):
876 super(RootNode, self).__init__(path=b'', nodes=nodes, commit=commit)
875 super().__init__(path=b'', nodes=nodes, commit=commit)
877
876
878 def __repr__(self):
877 def __repr__(self):
879 return f'<{self.__class__.__name__}>'
878 return f'<{self.__class__.__name__}>'
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,4 +1,3 b''
1
2 # Copyright (C) 2010-2023 RhodeCode GmbH
1 # Copyright (C) 2010-2023 RhodeCode GmbH
3 #
2 #
4 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,5 +1,3 b''
1
2
3 # Copyright (C) 2014-2023 RhodeCode GmbH
1 # Copyright (C) 2014-2023 RhodeCode GmbH
4 #
2 #
5 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -51,9 +49,9 b' def get_scm(path):'
51 found_scms = [(scm, path) for scm in get_scms_for_path(path)]
49 found_scms = [(scm, path) for scm in get_scms_for_path(path)]
52
50
53 if len(found_scms) > 1:
51 if len(found_scms) > 1:
54 found = ', '.join((x[0] for x in found_scms))
52 found = ', '.join(x[0] for x in found_scms)
55 raise VCSError(
53 raise VCSError(
56 'More than one [%s] scm found at given path %s' % (found, path))
54 'More than one [{}] scm found at given path {}'.format(found, path))
57
55
58 if len(found_scms) == 0:
56 if len(found_scms) == 0:
59 raise VCSError('No scm found at given path %s' % path)
57 raise VCSError('No scm found at given path %s' % path)
@@ -1,4 +1,3 b''
1
2 # Copyright (C) 2010-2023 RhodeCode GmbH
1 # Copyright (C) 2010-2023 RhodeCode GmbH
3 #
2 #
4 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
@@ -1,4 +1,3 b''
1
2 # Copyright (C) 2010-2023 RhodeCode GmbH
1 # Copyright (C) 2010-2023 RhodeCode GmbH
3 #
2 #
4 # This program is free software: you can redistribute it and/or modify
3 # This program is free software: you can redistribute it and/or modify
General Comments 0
You need to be logged in to leave comments. Login now