diff --git a/rhodecode/api/__init__.py b/rhodecode/api/__init__.py --- a/rhodecode/api/__init__.py +++ b/rhodecode/api/__init__.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -114,7 +112,7 @@ def jsonrpc_response(request, result): ) -def jsonrpc_error(request, message, retid=None, code: typing.Optional[int] = None, headers: typing.Optional[dict] = None): +def jsonrpc_error(request, message, retid=None, code: int | None = None, headers: dict | None = None): """ Generate a Response object with a JSON-RPC error body """ @@ -174,9 +172,9 @@ def exception_view(exc, request): statsd = request.registry.statsd if statsd: - exc_type = "{}.{}".format(exc.__class__.__module__, exc.__class__.__name__) + exc_type = f"{exc.__class__.__module__}.{exc.__class__.__name__}" statsd.incr('rhodecode_exception_total', - tags=["exc_source:api", "type:{}".format(exc_type)]) + tags=["exc_source:api", f"type:{exc_type}"]) return jsonrpc_error(request, fault_message, rpc_id) @@ -210,8 +208,8 @@ def request_view(request): if not auth_u.ip_allowed: return jsonrpc_error( request, retid=request.rpc_id, - message='Request from IP:%s not allowed' % ( - request.rpc_ip_addr,)) + message='Request from IP:{} not allowed'.format( + request.rpc_ip_addr)) else: log.info('Access for IP:%s allowed', request.rpc_ip_addr) @@ -357,7 +355,7 @@ def setup_request(request): json_body = ext_json.json.loads(raw_body) except ValueError as e: # catch JSON errors Here - raise JSONRPCError("JSON parse error ERR:%s RAW:%r" % (e, raw_body)) + raise JSONRPCError("JSON parse error ERR:{} RAW:{!r}".format(e, raw_body)) request.rpc_id = json_body.get('id') request.rpc_method = json_body.get('method') diff --git a/rhodecode/api/exc.py b/rhodecode/api/exc.py --- a/rhodecode/api/exc.py +++ b/rhodecode/api/exc.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -22,7 +20,7 @@ class JSONRPCBaseError(Exception): def __init__(self, message='', *args): self.message = message - super(JSONRPCBaseError, self).__init__(message, *args) + super().__init__(message, *args) class JSONRPCError(JSONRPCBaseError): @@ -33,7 +31,7 @@ class JSONRPCValidationError(JSONRPCBase def __init__(self, *args, **kwargs): self.colander_exception = kwargs.pop('colander_exc') - super(JSONRPCValidationError, self).__init__( + super().__init__( message=self.colander_exception, *args) diff --git a/rhodecode/api/utils.py b/rhodecode/api/utils.py --- a/rhodecode/api/utils.py +++ b/rhodecode/api/utils.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2014-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -224,7 +222,7 @@ def get_user_or_error(userid): if user is None: raise JSONRPCError( - 'user `%s` does not exist' % (userid,)) + 'user `{}` does not exist'.format(userid)) return user @@ -247,7 +245,7 @@ def get_repo_or_error(repoid): if repo is None: raise JSONRPCError( - 'repository `%s` does not exist' % (repoid,)) + 'repository `{}` does not exist'.format(repoid)) return repo @@ -270,7 +268,7 @@ def get_repo_group_or_error(repogroupid) if repo_group is None: raise JSONRPCError( - 'repository group `%s` does not exist' % (repogroupid,)) + 'repository group `{}` does not exist'.format(repogroupid)) return repo_group @@ -293,7 +291,7 @@ def get_user_group_or_error(usergroupid) if user_group is None: raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) return user_group @@ -307,9 +305,9 @@ def get_perm_or_error(permid, prefix=Non perm = PermissionModel.cls.get_by_key(permid) if perm is None: - msg = 'permission `{}` does not exist.'.format(permid) + msg = f'permission `{permid}` does not exist.' if prefix: - msg += ' Permission should start with prefix: `{}`'.format(prefix) + msg += f' Permission should start with prefix: `{prefix}`' raise JSONRPCError(msg) if prefix: @@ -329,7 +327,7 @@ def get_gist_or_error(gistid): gist = GistModel.cls.get_by_access_id(gistid) if gist is None: - raise JSONRPCError('gist `%s` does not exist' % (gistid,)) + raise JSONRPCError('gist `{}` does not exist'.format(gistid)) return gist @@ -346,8 +344,8 @@ def get_pull_request_or_error(pullreques except ValueError: raise JSONRPCError('pullrequestid must be an integer') if not pull_request: - raise JSONRPCError('pull request `%s` does not exist' % ( - pullrequestid,)) + raise JSONRPCError('pull request `{}` does not exist'.format( + pullrequestid)) return pull_request @@ -394,7 +392,7 @@ def get_commit_or_error(ref, repo): # once get_commit supports ref_types return get_commit_from_ref_name(repo, ref_hash) except RepositoryError: - raise JSONRPCError('Ref `{ref}` does not exist'.format(ref=ref)) + raise JSONRPCError(f'Ref `{ref}` does not exist') def _get_ref_hash(repo, type_, name): diff --git a/rhodecode/api/views/__init__.py b/rhodecode/api/views/__init__.py --- a/rhodecode/api/views/__init__.py +++ b/rhodecode/api/views/__init__.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2015-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify diff --git a/rhodecode/api/views/deprecated_api.py b/rhodecode/api/views/deprecated_api.py --- a/rhodecode/api/views/deprecated_api.py +++ b/rhodecode/api/views/deprecated_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify diff --git a/rhodecode/api/views/gist_api.py b/rhodecode/api/views/gist_api.py --- a/rhodecode/api/views/gist_api.py +++ b/rhodecode/api/views/gist_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -51,13 +49,13 @@ def get_gist(request, apiuser, gistid, c if not has_superadmin_permission(apiuser): if gist.gist_owner != apiuser.user_id: - raise JSONRPCError('gist `%s` does not exist' % (gistid,)) + raise JSONRPCError('gist `{}` does not exist'.format(gistid)) data = gist.get_api_data() if content: from rhodecode.model.gist import GistModel rev, gist_files = GistModel().get_gist_files(gistid) - data['content'] = dict([(x.path, x.str_content) for x in gist_files]) + data['content'] = {x.path: x.str_content for x in gist_files} return data @@ -242,13 +240,13 @@ def delete_gist(request, apiuser, gistid gist = get_gist_or_error(gistid) if not has_superadmin_permission(apiuser): if gist.gist_owner != apiuser.user_id: - raise JSONRPCError('gist `%s` does not exist' % (gistid,)) + raise JSONRPCError('gist `{}` does not exist'.format(gistid)) try: GistModel().delete(gist) Session().commit() return { - 'msg': 'deleted gist ID:%s' % (gist.gist_access_id,), + 'msg': 'deleted gist ID:{}'.format(gist.gist_access_id), 'gist': None } except Exception: diff --git a/rhodecode/api/views/pull_request_api.py b/rhodecode/api/views/pull_request_api.py --- a/rhodecode/api/views/pull_request_api.py +++ b/rhodecode/api/views/pull_request_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -322,7 +320,7 @@ def merge_pull_request( reasons = ','.join(error_messages) raise JSONRPCError( - 'merge not possible for following reasons: {}'.format(reasons)) + f'merge not possible for following reasons: {reasons}') target_repo = pull_request.target_repo extras = vcs_operation_context( @@ -529,7 +527,7 @@ def comment_pull_request( if not PullRequestModel().check_user_read( pull_request, apiuser, api=True): - raise JSONRPCError('repository `%s` does not exist' % (repoid,)) + raise JSONRPCError('repository `{}` does not exist'.format(repoid)) message = Optional.extract(message) status = Optional.extract(status) commit_id = Optional.extract(commit_id) @@ -758,7 +756,7 @@ def create_pull_request( reviewers = validate_default_reviewers( reviewer_objects, default_reviewers_data) except ValueError as e: - raise JSONRPCError('Reviewers Validation: {}'.format(e)) + raise JSONRPCError(f'Reviewers Validation: {e}') # now MERGE our given with the calculated from the default rules just_observers = [ @@ -770,7 +768,7 @@ def create_pull_request( observers = validate_observers( observer_objects, default_reviewers_data) except ValueError as e: - raise JSONRPCError('Observer Validation: {}'.format(e)) + raise JSONRPCError(f'Observer Validation: {e}') title = Optional.extract(title) if not title: @@ -820,7 +818,7 @@ def create_pull_request( Session().commit() data = { - 'msg': 'Created new pull request `{}`'.format(title), + 'msg': f'Created new pull request `{title}`', 'pull_request_id': pull_request.pull_request_id, } return data @@ -903,12 +901,12 @@ def update_pull_request( if not PullRequestModel().check_user_update( pull_request, apiuser, api=True): raise JSONRPCError( - 'pull request `%s` update failed, no permission to update.' % ( - pullrequestid,)) + 'pull request `{}` update failed, no permission to update.'.format( + pullrequestid)) if pull_request.is_closed(): raise JSONRPCError( - 'pull request `%s` update failed, pull request is closed' % ( - pullrequestid,)) + 'pull request `{}` update failed, pull request is closed'.format( + pullrequestid)) reviewer_objects = Optional.extract(reviewers) or [] observer_objects = Optional.extract(observers) or [] @@ -968,7 +966,7 @@ def update_pull_request( try: reviewers = validate_default_reviewers(reviewer_objects, default_reviewers_data) except ValueError as e: - raise JSONRPCError('Reviewers Validation: {}'.format(e)) + raise JSONRPCError(f'Reviewers Validation: {e}') else: reviewers = [] @@ -976,7 +974,7 @@ def update_pull_request( try: observers = validate_default_reviewers(reviewer_objects, default_reviewers_data) except ValueError as e: - raise JSONRPCError('Observer Validation: {}'.format(e)) + raise JSONRPCError(f'Observer Validation: {e}') else: observers = [] @@ -1023,7 +1021,7 @@ def update_pull_request( request, pr_broadcast_channel, apiuser, msg) data = { - 'msg': 'Updated pull request `{}`'.format(pull_request.pull_request_id), + 'msg': f'Updated pull request `{pull_request.pull_request_id}`', 'pull_request': pull_request.get_api_data(), 'updated_commits': commit_changes, 'updated_reviewers': reviewers_changes, @@ -1084,7 +1082,7 @@ def close_pull_request( if pull_request.is_closed(): raise JSONRPCError( - 'pull request `%s` is already closed' % (pullrequestid,)) + 'pull request `{}` is already closed'.format(pullrequestid)) # only owner or admin or person with write permissions allowed_to_close = PullRequestModel().check_user_update( @@ -1092,8 +1090,8 @@ def close_pull_request( if not allowed_to_close: raise JSONRPCError( - 'pull request `%s` close failed, no permission to close.' % ( - pullrequestid,)) + 'pull request `{}` close failed, no permission to close.'.format( + pullrequestid)) # message we're using to close the PR, else it's automatically generated message = Optional.extract(message) diff --git a/rhodecode/api/views/repo_api.py b/rhodecode/api/views/repo_api.py --- a/rhodecode/api/views/repo_api.py +++ b/rhodecode/api/views/repo_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -265,7 +263,7 @@ def get_repos(request, apiuser, root=Opt parent = RepoGroup.get_by_group_name(root) if not parent: raise JSONRPCError( - 'Root repository group `{}` does not exist'.format(root)) + f'Root repository group `{root}` does not exist') if traverse: repos = RepoModel().get_repos_for_root(root=root, traverse=traverse) @@ -626,7 +624,7 @@ def get_repo_fts_tree(request, apiuser, cache_seconds = rhodecode.ConfigGet().get_int('rc_cache.cache_repo.expiration_time') cache_on = cache_seconds > 0 - cache_namespace_uid = 'repo.{}'.format(repo_id) + cache_namespace_uid = f'repo.{repo_id}' rc_cache.get_or_create_region('cache_repo', cache_namespace_uid) def compute_fts_tree(cache_ver, repo_id, commit_id, root_path): @@ -869,17 +867,17 @@ def create_repo( task_id = get_task_id(task) # no commit, it's done in RepoModel, or async via celery return { - 'msg': "Created new repository `%s`" % (schema_data['repo_name'],), + 'msg': "Created new repository `{}`".format(schema_data['repo_name']), 'success': True, # cannot return the repo data here since fork # can be done async 'task': task_id } except Exception: log.exception( - u"Exception while trying to create the repository %s", + "Exception while trying to create the repository %s", schema_data['repo_name']) raise JSONRPCError( - 'failed to create repository `%s`' % (schema_data['repo_name'],)) + 'failed to create repository `{}`'.format(schema_data['repo_name'])) @jsonrpc_method() @@ -920,13 +918,13 @@ def add_field_to_repo(request, apiuser, field_desc=description) Session().commit() return { - 'msg': "Added new repository field `%s`" % (key,), + 'msg': "Added new repository field `{}`".format(key), 'success': True, } except Exception: log.exception("Exception occurred while trying to add field to repo") raise JSONRPCError( - 'failed to create new field for repository `%s`' % (repoid,)) + 'failed to create new field for repository `{}`'.format(repoid)) @jsonrpc_method() @@ -959,14 +957,14 @@ def remove_field_from_repo(request, apiu RepoModel().delete_repo_field(repo, field_key=key) Session().commit() return { - 'msg': "Deleted repository field `%s`" % (key,), + 'msg': "Deleted repository field `{}`".format(key), 'success': True, } except Exception: log.exception( "Exception occurred while trying to delete field from repo") raise JSONRPCError( - 'failed to delete field for repository `%s`' % (repoid,)) + 'failed to delete field for repository `{}`'.format(repoid)) @jsonrpc_method() @@ -979,7 +977,7 @@ def update_repo( enable_statistics=Optional(False), enable_locking=Optional(False), enable_downloads=Optional(False), fields=Optional('')): - """ + r""" Updates a repository with the given information. This command can only be run using an |authtoken| with at least @@ -1132,12 +1130,12 @@ def update_repo( user=apiuser, repo=repo) Session().commit() return { - 'msg': 'updated repo ID:%s %s' % (repo.repo_id, repo.repo_name), + 'msg': 'updated repo ID:{} {}'.format(repo.repo_id, repo.repo_name), 'repository': repo.get_api_data(include_secrets=include_secrets) } except Exception: log.exception( - u"Exception while trying to update the repository %s", + "Exception while trying to update the repository %s", repoid) raise JSONRPCError('failed to update repo `%s`' % repoid) @@ -1276,7 +1274,7 @@ def fork_repo(request, apiuser, repoid, task_id = get_task_id(task) return { - 'msg': 'Created fork of `%s` as `%s`' % ( + 'msg': 'Created fork of `{}` as `{}`'.format( repo.repo_name, schema_data['repo_name']), 'success': True, # cannot return the repo data here since fork # can be done async @@ -1284,10 +1282,10 @@ def fork_repo(request, apiuser, repoid, } except Exception: log.exception( - u"Exception while trying to create fork %s", + "Exception while trying to create fork %s", schema_data['repo_name']) raise JSONRPCError( - 'failed to fork repository `%s` as `%s`' % ( + 'failed to fork repository `{}` as `{}`'.format( repo_name, schema_data['repo_name'])) @@ -1353,13 +1351,13 @@ def delete_repo(request, apiuser, repoid ScmModel().mark_for_invalidation(repo_name, delete=True) Session().commit() return { - 'msg': 'Deleted repository `%s`%s' % (repo_name, _forks_msg), + 'msg': 'Deleted repository `{}`{}'.format(repo_name, _forks_msg), 'success': True } except Exception: log.exception("Exception occurred while trying to delete repo") raise JSONRPCError( - 'failed to delete repository `%s`' % (repo_name,) + 'failed to delete repository `{}`'.format(repo_name) ) @@ -1414,7 +1412,7 @@ def invalidate_cache(request, apiuser, r try: ScmModel().mark_for_invalidation(repo.repo_name, delete=delete) return { - 'msg': 'Cache for repository `%s` was invalidated' % (repoid,), + 'msg': 'Cache for repository `{}` was invalidated'.format(repoid), 'repository': repo.repo_name } except Exception: @@ -1696,7 +1694,7 @@ def comment_commit( return { 'msg': ( - 'Commented on commit `%s` for repository `%s`' % ( + 'Commented on commit `{}` for repository `{}`'.format( comment.revision, repo.repo_name)), 'status_change': status, 'success': True, @@ -1708,7 +1706,7 @@ def comment_commit( except Exception: log.exception("Exception occurred while trying to comment on commit") raise JSONRPCError( - 'failed to set comment on repository `%s`' % (repo.repo_name,) + 'failed to set comment on repository `{}`'.format(repo.repo_name) ) @@ -1815,14 +1813,14 @@ def get_comment(request, apiuser, commen comment = ChangesetComment.get(comment_id) if not comment: - raise JSONRPCError('comment `%s` does not exist' % (comment_id,)) + raise JSONRPCError('comment `{}` does not exist'.format(comment_id)) perms = ('repository.read', 'repository.write', 'repository.admin') has_comment_perm = HasRepoPermissionAnyApi(*perms)\ (user=apiuser, repo_name=comment.repo.repo_name) if not has_comment_perm: - raise JSONRPCError('comment `%s` does not exist' % (comment_id,)) + raise JSONRPCError('comment `{}` does not exist'.format(comment_id)) return comment @@ -1860,7 +1858,7 @@ def edit_comment(request, apiuser, messa auth_user = apiuser comment = ChangesetComment.get(comment_id) if not comment: - raise JSONRPCError('comment `%s` does not exist' % (comment_id,)) + raise JSONRPCError('comment `{}` does not exist'.format(comment_id)) is_super_admin = has_superadmin_permission(apiuser) is_repo_admin = HasRepoPermissionAnyApi('repository.admin')\ @@ -1891,11 +1889,11 @@ def edit_comment(request, apiuser, messa Session().commit() except CommentVersionMismatch: raise JSONRPCError( - 'comment ({}) version ({}) mismatch'.format(comment_id, version) + f'comment ({comment_id}) version ({version}) mismatch' ) if not comment_history and not message: raise JSONRPCError( - "comment ({}) can't be changed with empty string".format(comment_id) + f"comment ({comment_id}) can't be changed with empty string" ) if comment.pull_request: @@ -1989,7 +1987,7 @@ def grant_user_permission(request, apius PermissionModel().flush_user_permission_caches(changes) return { - 'msg': 'Granted perm: `%s` for user: `%s` in repo: `%s`' % ( + 'msg': 'Granted perm: `{}` for user: `{}` in repo: `{}`'.format( perm.permission_name, user.username, repo.repo_name ), 'success': True @@ -1997,7 +1995,7 @@ def grant_user_permission(request, apius except Exception: log.exception("Exception occurred while trying edit permissions for repo") raise JSONRPCError( - 'failed to edit permission for user: `%s` in repo: `%s`' % ( + 'failed to edit permission for user: `{}` in repo: `{}`'.format( userid, repoid ) ) @@ -2052,7 +2050,7 @@ def revoke_user_permission(request, apiu PermissionModel().flush_user_permission_caches(changes) return { - 'msg': 'Revoked perm for user: `%s` in repo: `%s`' % ( + 'msg': 'Revoked perm for user: `{}` in repo: `{}`'.format( user.username, repo.repo_name ), 'success': True @@ -2060,7 +2058,7 @@ def revoke_user_permission(request, apiu except Exception: log.exception("Exception occurred while trying revoke permissions to repo") raise JSONRPCError( - 'failed to edit permission for user: `%s` in repo: `%s`' % ( + 'failed to edit permission for user: `{}` in repo: `{}`'.format( userid, repoid ) ) @@ -2122,7 +2120,7 @@ def grant_user_group_permission(request, if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) perm_additions = [[user_group.users_group_id, perm.permission_name, "user_group"]] try: @@ -2196,7 +2194,7 @@ def revoke_user_group_permission(request if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) perm_deletions = [[user_group.users_group_id, None, "user_group"]] try: @@ -2213,7 +2211,7 @@ def revoke_user_group_permission(request PermissionModel().flush_user_permission_caches(changes) return { - 'msg': 'Revoked perm for user group: `%s` in repo: `%s`' % ( + 'msg': 'Revoked perm for user group: `{}` in repo: `{}`'.format( user_group.users_group_name, repo.repo_name ), 'success': True @@ -2282,7 +2280,7 @@ def pull(request, apiuser, repoid, remot ScmModel().pull_changes( repo.repo_name, apiuser.username, remote_uri=remote_uri) return { - 'msg': 'Pulled from url `%s` on repo `%s`' % ( + 'msg': 'Pulled from url `{}` on repo `{}`'.format( remote_uri_display, repo.repo_name), 'repository': repo.repo_name } @@ -2351,14 +2349,14 @@ def strip(request, apiuser, repoid, revi user=apiuser, commit=True) return { - 'msg': 'Stripped commit %s from repo `%s`' % ( + 'msg': 'Stripped commit {} from repo `{}`'.format( revision, repo.repo_name), 'repository': repo.repo_name } except Exception: log.exception("Exception while trying to strip") raise JSONRPCError( - 'Unable to strip commit %s from repo `%s`' % ( + 'Unable to strip commit {} from repo `{}`'.format( revision, repo.repo_name) ) @@ -2413,7 +2411,7 @@ def get_repo_settings(request, apiuser, if key is not None: settings = settings.get(key, None) except Exception: - msg = 'Failed to fetch settings for repository `{}`'.format(repoid) + msg = f'Failed to fetch settings for repository `{repoid}`' log.exception(msg) raise JSONRPCError(msg) @@ -2466,7 +2464,7 @@ def set_repo_settings(request, apiuser, new_settings, inherit_global_settings=inherit_global_settings) Session().commit() except Exception: - msg = 'Failed to update settings for repository `{}`'.format(repoid) + msg = f'Failed to update settings for repository `{repoid}`' log.exception(msg) raise JSONRPCError(msg) diff --git a/rhodecode/api/views/repo_group_api.py b/rhodecode/api/views/repo_group_api.py --- a/rhodecode/api/views/repo_group_api.py +++ b/rhodecode/api/views/repo_group_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -98,7 +96,7 @@ def get_repo_group(request, apiuser, rep if not HasRepoGroupPermissionAnyApi(*_perms)( user=apiuser, group_name=repo_group.group_name): raise JSONRPCError( - 'repository group `%s` does not exist' % (repogroupid,)) + 'repository group `{}` does not exist'.format(repogroupid)) permissions = [] for _user in repo_group.permissions(): @@ -242,7 +240,7 @@ def create_repo_group( except Exception: log.exception("Exception occurred while trying create repo group") raise JSONRPCError( - 'failed to create repo group `%s`' % (validated_group_name,)) + 'failed to create repo group `{}`'.format(validated_group_name)) @jsonrpc_method() @@ -331,13 +329,13 @@ def update_repo_group( Session().commit() return { - 'msg': 'updated repository group ID:%s %s' % ( + 'msg': 'updated repository group ID:{} {}'.format( repo_group.group_id, repo_group.group_name), 'repo_group': repo_group.get_api_data() } except Exception: log.exception( - u"Exception occurred while trying update repo group %s", + "Exception occurred while trying update repo group %s", repogroupid) raise JSONRPCError('failed to update repository group `%s`' % (repogroupid,)) @@ -629,7 +627,7 @@ def grant_user_group_permission_to_repo_ if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) apply_to_children = Optional.extract(apply_to_children) @@ -722,7 +720,7 @@ def revoke_user_group_permission_from_re if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) apply_to_children = Optional.extract(apply_to_children) diff --git a/rhodecode/api/views/search_api.py b/rhodecode/api/views/search_api.py --- a/rhodecode/api/views/search_api.py +++ b/rhodecode/api/views/search_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -109,7 +107,7 @@ def search(request, apiuser, search_quer searcher.cleanup() if not search_result['error']: - data['execution_time'] = '%s results (%.4f seconds)' % ( + data['execution_time'] = '{} results ({:.4f} seconds)'.format( search_result['count'], search_result['runtime']) else: diff --git a/rhodecode/api/views/server_api.py b/rhodecode/api/views/server_api.py --- a/rhodecode/api/views/server_api.py +++ b/rhodecode/api/views/server_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify diff --git a/rhodecode/api/views/testing_api.py b/rhodecode/api/views/testing_api.py --- a/rhodecode/api/views/testing_api.py +++ b/rhodecode/api/views/testing_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify diff --git a/rhodecode/api/views/user_api.py b/rhodecode/api/views/user_api.py --- a/rhodecode/api/views/user_api.py +++ b/rhodecode/api/views/user_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -232,10 +230,10 @@ def create_user(request, apiuser, userna raise JSONRPCForbidden() if UserModel().get_by_username(username): - raise JSONRPCError("user `%s` already exist" % (username,)) + raise JSONRPCError("user `{}` already exist".format(username)) if UserModel().get_by_email(email, case_insensitive=True): - raise JSONRPCError("email `%s` already exist" % (email,)) + raise JSONRPCError("email `{}` already exist".format(email)) # generate random password if we actually given the # extern_name and it's not rhodecode @@ -305,7 +303,7 @@ def create_user(request, apiuser, userna } except Exception: log.exception('Error occurred during creation of user') - raise JSONRPCError('failed to create user `%s`' % (username,)) + raise JSONRPCError('failed to create user `{}`'.format(username)) @jsonrpc_method() @@ -398,7 +396,7 @@ def update_user(request, apiuser, userid user=apiuser) Session().commit() return { - 'msg': 'updated user ID:%s %s' % (user.user_id, user.username), + 'msg': 'updated user ID:{} {}'.format(user.user_id, user.username), 'user': user.get_api_data(include_secrets=True) } except DefaultUserException: @@ -406,7 +404,7 @@ def update_user(request, apiuser, userid raise JSONRPCError('editing default user is forbidden') except Exception: log.exception("Error occurred during update of user") - raise JSONRPCError('failed to update user `%s`' % (userid,)) + raise JSONRPCError('failed to update user `{}`'.format(userid)) @jsonrpc_method() @@ -467,13 +465,13 @@ def delete_user(request, apiuser, userid Session().commit() return { - 'msg': 'deleted user ID:%s %s' % (user.user_id, user.username), + 'msg': 'deleted user ID:{} {}'.format(user.user_id, user.username), 'user': None } except Exception: log.exception("Error occurred during deleting of user") raise JSONRPCError( - 'failed to delete user ID:%s %s' % (user.user_id, user.username)) + 'failed to delete user ID:{} {}'.format(user.user_id, user.username)) @jsonrpc_method() diff --git a/rhodecode/api/views/user_group_api.py b/rhodecode/api/views/user_group_api.py --- a/rhodecode/api/views/user_group_api.py +++ b/rhodecode/api/views/user_group_api.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2011-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify @@ -103,8 +101,8 @@ def get_user_group(request, apiuser, use _perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin',) if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): - raise JSONRPCError('user group `%s` does not exist' % ( - usergroupid,)) + raise JSONRPCError('user group `{}` does not exist'.format( + usergroupid)) permissions = [] for _user in user_group.permissions(): @@ -226,7 +224,7 @@ def create_user_group( raise JSONRPCForbidden() if UserGroupModel().get_by_name(group_name): - raise JSONRPCError("user group `%s` already exist" % (group_name,)) + raise JSONRPCError("user group `{}` already exist".format(group_name)) if isinstance(owner, Optional): owner = apiuser.user_id @@ -279,7 +277,7 @@ def create_user_group( } except Exception: log.exception("Error occurred during creation of user group") - raise JSONRPCError('failed to create group `%s`' % (group_name,)) + raise JSONRPCError('failed to create group `{}`'.format(group_name)) @jsonrpc_method() @@ -341,7 +339,7 @@ def update_user_group(request, apiuser, if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) else: include_secrets = True @@ -374,7 +372,7 @@ def update_user_group(request, apiuser, user=apiuser) Session().commit() return { - 'msg': 'updated user group ID:%s %s' % ( + 'msg': 'updated user group ID:{} {}'.format( user_group.users_group_id, user_group.users_group_name), 'user_group': user_group.get_api_data( include_secrets=include_secrets) @@ -382,7 +380,7 @@ def update_user_group(request, apiuser, except Exception: log.exception("Error occurred during update of user group") raise JSONRPCError( - 'failed to update user group `%s`' % (usergroupid,)) + 'failed to update user group `{}`'.format(usergroupid)) @jsonrpc_method() @@ -431,7 +429,7 @@ def delete_user_group(request, apiuser, if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) old_data = user_group.get_api_data() try: @@ -441,7 +439,7 @@ def delete_user_group(request, apiuser, user=apiuser) Session().commit() return { - 'msg': 'deleted user group ID:%s %s' % ( + 'msg': 'deleted user group ID:{} {}'.format( user_group.users_group_id, user_group.users_group_name), 'user_group': None } @@ -506,14 +504,14 @@ def add_user_to_user_group(request, apiu _perms = ('usergroup.admin',) if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): - raise JSONRPCError('user group `%s` does not exist' % ( - usergroupid,)) + raise JSONRPCError('user group `{}` does not exist'.format( + usergroupid)) old_values = user_group.get_api_data() try: ugm = UserGroupModel().add_user_to_group(user_group, user) success = True if ugm is not True else False - msg = 'added member `%s` to user group `%s`' % ( + msg = 'added member `{}` to user group `{}`'.format( user.username, user_group.users_group_name ) msg = msg if success else 'User is already in that group' @@ -533,7 +531,7 @@ def add_user_to_user_group(request, apiu except Exception: log.exception("Error occurred during adding a member to user group") raise JSONRPCError( - 'failed to add member to user group `%s`' % ( + 'failed to add member to user group `{}`'.format( user_group.users_group_name, ) ) @@ -579,12 +577,12 @@ def remove_user_from_user_group(request, if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) old_values = user_group.get_api_data() try: success = UserGroupModel().remove_user_from_group(user_group, user) - msg = 'removed member `%s` from user group `%s`' % ( + msg = 'removed member `{}` from user group `{}`'.format( user.username, user_group.users_group_name ) msg = msg if success else "User wasn't in group" @@ -600,7 +598,7 @@ def remove_user_from_user_group(request, except Exception: log.exception("Error occurred during removing an member from user group") raise JSONRPCError( - 'failed to remove member from user group `%s`' % ( + 'failed to remove member from user group `{}`'.format( user_group.users_group_name, ) ) @@ -641,7 +639,7 @@ def grant_user_permission_to_user_group( if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) user = get_user_or_error(userid) perm = get_perm_or_error(perm, prefix='usergroup.') @@ -663,7 +661,7 @@ def grant_user_permission_to_user_group( return { 'msg': - 'Granted perm: `%s` for user: `%s` in user group: `%s`' % ( + 'Granted perm: `{}` for user: `{}` in user group: `{}`'.format( perm.permission_name, user.username, user_group.users_group_name ), @@ -713,7 +711,7 @@ def revoke_user_permission_from_user_gro if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (usergroupid,)) + 'user group `{}` does not exist'.format(usergroupid)) user = get_user_or_error(userid) @@ -732,7 +730,7 @@ def revoke_user_permission_from_user_gro PermissionModel().flush_user_permission_caches(changes) return { - 'msg': 'Revoked perm for user: `%s` in user group: `%s`' % ( + 'msg': 'Revoked perm for user: `{}` in user group: `{}`'.format( user.username, user_group.users_group_name ), 'success': True @@ -784,14 +782,14 @@ def grant_user_group_permission_to_user_ user=apiuser, user_group_name=target_user_group.users_group_name): raise JSONRPCError( - 'to user group `%s` does not exist' % (usergroupid,)) + 'to user group `{}` does not exist'.format(usergroupid)) # check if we have at least read permission for source user group ! _perms = ('usergroup.read', 'usergroup.write', 'usergroup.admin',) if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (sourceusergroupid,)) + 'user group `{}` does not exist'.format(sourceusergroupid)) try: changes = UserGroupModel().grant_user_group_permission( @@ -864,7 +862,7 @@ def revoke_user_group_permission_from_us user=apiuser, user_group_name=target_user_group.users_group_name): raise JSONRPCError( - 'to user group `%s` does not exist' % (usergroupid,)) + 'to user group `{}` does not exist'.format(usergroupid)) # check if we have at least read permission # for the source user group ! @@ -872,7 +870,7 @@ def revoke_user_group_permission_from_us if not HasUserGroupPermissionAnyApi(*_perms)( user=apiuser, user_group_name=user_group.users_group_name): raise JSONRPCError( - 'user group `%s` does not exist' % (sourceusergroupid,)) + 'user group `{}` does not exist'.format(sourceusergroupid)) try: changes = UserGroupModel().revoke_user_group_permission( diff --git a/rhodecode/lib/vcs/geventcurl.py b/rhodecode/lib/vcs/geventcurl.py --- a/rhodecode/lib/vcs/geventcurl.py +++ b/rhodecode/lib/vcs/geventcurl.py @@ -187,7 +187,7 @@ class GeventCurlMulti(object): for curl in ok_list: curl.waiter.switch(None) for curl, errnum, errmsg in err_list: - curl.waiter.throw(Exception('%s %s' % (errnum, errmsg))) + curl.waiter.throw(Exception('{} {}'.format(errnum, errmsg))) if num_q == 0: break diff --git a/rhodecode/lib/vcs/nodes.py b/rhodecode/lib/vcs/nodes.py --- a/rhodecode/lib/vcs/nodes.py +++ b/rhodecode/lib/vcs/nodes.py @@ -1,5 +1,3 @@ - - # Copyright (C) 2014-2023 RhodeCode GmbH # # This program is free software: you can redistribute it and/or modify