diff --git a/lib/tool_shed/grids/admin_grids.py b/lib/tool_shed/grids/admin_grids.py index 52f68837b501..c3ea548c8fd9 100644 --- a/lib/tool_shed/grids/admin_grids.py +++ b/lib/tool_shed/grids/admin_grids.py @@ -401,7 +401,7 @@ def get_value(self, trans, grid, repository_metadata): # We used to display the following, but grid was too cluttered. # for tool_metadata_dict in metadata[ 'tools' ]: # tools_str += '%s %s
' % ( tool_metadata_dict[ 'id' ], tool_metadata_dict[ 'version' ] ) - return "%d" % len(metadata["tools"]) + return "{}".format(len(metadata["tools"])) return tools_str class DatatypesColumn(grids.TextColumn): @@ -414,7 +414,7 @@ def get_value(self, trans, grid, repository_metadata): # We used to display the following, but grid was too cluttered. # for datatype_metadata_dict in metadata[ 'datatypes' ]: # datatypes_str += '%s
' % datatype_metadata_dict[ 'extension' ] - return "%d" % len(metadata["datatypes"]) + return "{}".format(len(metadata["datatypes"])) return datatypes_str class WorkflowsColumn(grids.TextColumn): @@ -432,7 +432,7 @@ def get_value(self, trans, grid, repository_metadata): # workflow_metadata_dicts = [ workflow_tup[1] for workflow_tup in workflow_tups ] # for workflow_metadata_dict in workflow_metadata_dicts: # workflows_str += '%s
' % workflow_metadata_dict[ 'name' ] - return "%d" % len(metadata["workflows"]) + return "{}".format(len(metadata["workflows"])) return workflows_str class DeletedColumn(grids.BooleanColumn): diff --git a/lib/tool_shed/grids/util.py b/lib/tool_shed/grids/util.py index 06c500d4b306..afef473cc30d 100644 --- a/lib/tool_shed/grids/util.py +++ b/lib/tool_shed/grids/util.py @@ -41,7 +41,7 @@ def build_changeset_revision_select_field( # Display the latest revision first. options.insert(0, (changeset_tup[1], changeset_tup[2])) if add_id_to_name: - name = "changeset_revision_%d" % repository.id + name = f"changeset_revision_{repository.id}" else: name = "changeset_revision" select_field = SelectField(name=name, refresh_on_change=True) diff --git a/lib/tool_shed/managers/repositories.py b/lib/tool_shed/managers/repositories.py index e7af6ff641bf..2a9b0e36e270 100644 --- a/lib/tool_shed/managers/repositories.py +++ b/lib/tool_shed/managers/repositories.py @@ -223,7 +223,7 @@ def index_tool_ids(app: ToolShedApp, tool_ids: List[str]) -> Dict[str, Any]: continue for tool_metadata in tools: if tool_metadata["guid"] in tool_ids: - repository_found.append("%d:%s" % (int(changeset), changehash)) + repository_found.append(f"{int(changeset)}:{changehash}") metadata = get_current_repository_metadata_for_changeset_revision(app, repository, changehash) if metadata is None: continue diff --git a/lib/tool_shed/metadata/repository_metadata_manager.py b/lib/tool_shed/metadata/repository_metadata_manager.py index 1f9b817e0230..7562459bbbdc 100644 --- a/lib/tool_shed/metadata/repository_metadata_manager.py +++ b/lib/tool_shed/metadata/repository_metadata_manager.py @@ -943,12 +943,12 @@ def reset_metadata_on_selected_repositories(self, **kwd): except Exception: log.exception("Error attempting to reset metadata on repository %s", str(repository.name)) unsuccessful_count += 1 - message = "Successfully reset metadata on %d %s. " % ( + message = "Successfully reset metadata on {} {}. ".format( successful_count, inflector.cond_plural(successful_count, "repository"), ) if unsuccessful_count: - message += "Error setting metadata on %d %s - see the paster log for details. " % ( + message += "Error setting metadata on {} {} - see the paster log for details. ".format( unsuccessful_count, inflector.cond_plural(unsuccessful_count, "repository"), ) diff --git a/lib/tool_shed/test/base/twilltestcase.py b/lib/tool_shed/test/base/twilltestcase.py index a8414ff3dc69..4d019215991f 100644 --- a/lib/tool_shed/test/base/twilltestcase.py +++ b/lib/tool_shed/test/base/twilltestcase.py @@ -669,15 +669,6 @@ def check_for_strings(self, strings_displayed=None, strings_not_displayed=None): for check_str in strings_not_displayed: self.check_string_not_in_page(check_str) - def check_page(self, strings_displayed, strings_displayed_count, strings_not_displayed): - """Checks a page for strings displayed, not displayed and number of occurrences of a string""" - for check_str in strings_displayed: - self.check_page_for_string(check_str) - for check_str, count in strings_displayed_count: - self.check_string_count_in_page(check_str, count) - for check_str in strings_not_displayed: - self.check_string_not_in_page(check_str) - def check_page_for_string(self, patt): """Looks for 'patt' in the current browser page""" self._browser.check_page_for_string(patt) @@ -905,7 +896,7 @@ def browse_tools(self, strings_displayed=None, strings_not_displayed=None): self.visit_url(url) self.check_for_strings(strings_displayed, strings_not_displayed) - def check_count_of_metadata_revisions_associated_with_repository(self, repository: Repository, metadata_count): + def check_count_of_metadata_revisions_associated_with_repository(self, repository: Repository, metadata_count: int): self.check_repository_changelog(repository) self.check_string_count_in_page("Repository metadata is associated with this change set.", metadata_count) @@ -1011,7 +1002,7 @@ def check_repository_invalid_tools_for_changeset_revision( strings_not_displayed=strings_not_displayed, ) - def check_string_count_in_page(self, pattern, min_count, max_count=None): + def check_string_count_in_page(self, pattern, min_count: int, max_count: Optional[int] = None): """Checks the number of 'pattern' occurrences in the current browser page""" page = self.last_page() pattern_count = page.count(pattern) @@ -1022,14 +1013,9 @@ def check_string_count_in_page(self, pattern, min_count, max_count=None): # than max_count. if pattern_count < min_count or pattern_count > max_count: fname = self.write_temp_file(page) - errmsg = "%i occurrences of '%s' found (min. %i, max. %i).\npage content written to '%s' " % ( - pattern_count, - pattern, - min_count, - max_count, - fname, + raise AssertionError( + f"{pattern_count} occurrences of '{pattern}' found (min. {min_count}, max. {max_count}).\npage content written to '{fname}' " ) - raise AssertionError(errmsg) def check_galaxy_repository_tool_panel_section( self, repository: galaxy_model.ToolShedRepository, expected_tool_panel_section: str @@ -2098,8 +2084,7 @@ def _wait_for_installation(repository: galaxy_model.ToolShedRepository, refresh) # This timeout currently defaults to 10 minutes. if timeout_counter > repository_installation_timeout: raise AssertionError( - "Repository installation timed out, %d seconds elapsed, repository state is %s." - % (timeout_counter, repository.status) + f"Repository installation timed out, {timeout_counter} seconds elapsed, repository state is {repository.status}." ) time.sleep(1) diff --git a/lib/tool_shed/test/functional/test_0000_basic_repository_features.py b/lib/tool_shed/test/functional/test_0000_basic_repository_features.py index 5b723b3aa41d..aae51a69b6d4 100644 --- a/lib/tool_shed/test/functional/test_0000_basic_repository_features.py +++ b/lib/tool_shed/test/functional/test_0000_basic_repository_features.py @@ -362,7 +362,7 @@ def test_0130_verify_handling_of_invalid_characters(self): # unicode decoding error message. content = self._escape_page_content_if_needed("These characters should not") strings_displayed = [ - "%d:%s" % (revision_number, revision_hash), + f"{revision_number}:{revision_hash}", "filtering_0000", "user1", "repos", diff --git a/lib/tool_shed/test/functional/test_0440_deleting_dependency_definitions.py b/lib/tool_shed/test/functional/test_0440_deleting_dependency_definitions.py index 4b540f71584e..045b5ce9aff4 100644 --- a/lib/tool_shed/test/functional/test_0440_deleting_dependency_definitions.py +++ b/lib/tool_shed/test/functional/test_0440_deleting_dependency_definitions.py @@ -144,12 +144,10 @@ def test_0020_verify_dependency_metadata(self): metadata_record = self._get_repository_metadata_by_changeset_revision(repository, tip) # Make sure that the new tip is now downloadable, and that there are no other downloadable revisions. assert metadata_record.downloadable, "Tip is not downloadable." + n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions) assert ( - len(self._db_repository(repository).downloadable_revisions) == 1 - ), "Repository %s has %d downloadable revisions, expected 1." % ( - repository.name, - len(self._db_repository(repository).downloadable_revisions), - ) + n_downloadable_revisions == 1 + ), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1." def test_0025_delete_repository_dependency(self): """Delete the repository_dependencies.xml from convert_chars_0440. @@ -174,12 +172,10 @@ def test_0025_delete_repository_dependency(self): metadata_record.downloadable ), f"The revision of {repository.name} that does not contain repository_dependencies.xml is not downloadable." # Verify that there are only two downloadable revisions. + n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions) assert ( - len(self._db_repository(repository).downloadable_revisions) == 2 - ), "Repository %s has %d downloadable revisions, expected 2." % ( - repository.name, - len(self._db_repository(repository).downloadable_revisions), - ) + n_downloadable_revisions == 2 + ), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 2." def test_0030_create_bwa_package_repository(self): """Create and populate the bwa_package_0440 repository. @@ -257,12 +253,10 @@ def test_0045_verify_dependency_metadata(self): metadata_record = self._get_repository_metadata_by_changeset_revision(repository, tip) # Make sure that the new tip is now downloadable, and that there are no other downloadable revisions. assert metadata_record.downloadable, "Tip is not downloadable." + n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions) assert ( - len(self._db_repository(repository).downloadable_revisions) == 1 - ), "Repository %s has %d downloadable revisions, expected 1." % ( - repository.name, - len(self._db_repository(repository).downloadable_revisions), - ) + n_downloadable_revisions == 1 + ), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1." def test_0050_delete_complex_repository_dependency(self): """Delete the tool_dependencies.xml from bwa_base_0440. @@ -287,12 +281,10 @@ def test_0050_delete_complex_repository_dependency(self): metadata_record.downloadable ), f"The revision of {repository.name} that does not contain tool_dependencies.xml is not downloadable." # Verify that there are only two downloadable revisions. + n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions) assert ( - len(self._db_repository(repository).downloadable_revisions) == 2 - ), "Repository %s has %d downloadable revisions, expected 2." % ( - repository.name, - len(self._db_repository(repository).downloadable_revisions), - ) + n_downloadable_revisions == 2 + ), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 2." def test_0055_create_bwa_tool_dependency_repository(self): """Create and populate the bwa_tool_dependency_0440 repository. @@ -340,12 +332,10 @@ def test_0060_delete_bwa_tool_dependency_definition(self): metadata_record is None ), f"The tip revision of {repository.name} should not have metadata, but metadata was found." # Verify that the new changeset revision is not downloadable. + n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions) assert ( - len(self._db_repository(repository).downloadable_revisions) == 1 - ), "Repository %s has %d downloadable revisions, expected 1." % ( - repository.name, - len(self._db_repository(repository).downloadable_revisions), - ) + n_downloadable_revisions == 1 + ), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1." def test_0065_reupload_bwa_tool_dependency_definition(self): """Reupload the tool_dependencies.xml file to bwa_tool_dependency_0440. @@ -372,12 +362,10 @@ def test_0065_reupload_bwa_tool_dependency_definition(self): metadata_record.downloadable ), f"The revision of {repository.name} that contains tool_dependencies.xml is not downloadable." # Verify that there are only two downloadable revisions. + n_downloadable_revisions = len(self._db_repository(repository).downloadable_revisions) assert ( - len(self._db_repository(repository).downloadable_revisions) == 1 - ), "Repository %s has %d downloadable revisions, expected 1." % ( - repository.name, - len(self._db_repository(repository).downloadable_revisions), - ) + n_downloadable_revisions == 1 + ), f"Repository {repository.name} has {n_downloadable_revisions} downloadable revisions, expected 1." def _get_repository_metadata_by_changeset_revision(self, repository: Repository, changeset: str): return self.get_repository_metadata_by_changeset_revision(self._db_repository(repository).id, changeset) diff --git a/lib/tool_shed/test/functional/test_0470_tool_dependency_repository_type.py b/lib/tool_shed/test/functional/test_0470_tool_dependency_repository_type.py index 99c3fe760920..2b5f966a4755 100644 --- a/lib/tool_shed/test/functional/test_0470_tool_dependency_repository_type.py +++ b/lib/tool_shed/test/functional/test_0470_tool_dependency_repository_type.py @@ -144,10 +144,9 @@ def test_0020_upload_updated_tool_dependency_to_package_x11(self): # Upload the tool dependency definition to the package_x11_client_1_5_proto_7_0_0470 repository. self.user_populator().setup_test_data_repo("libx11_proto", package_x11_repository, start=1, end=2) count = self._get_metadata_revision_count(package_x11_repository) - assert count == 1, ( - "package_x11_client_1_5_proto_7_0_0470 has incorrect number of metadata revisions, expected 1 but found %d" - % count - ) + assert ( + count == 1 + ), f"package_x11_client_1_5_proto_7_0_0470 has incorrect number of metadata revisions, expected 1 but found {count}" def test_0025_upload_updated_tool_dependency_to_package_emboss(self): """Upload a new tool_dependencies.xml to package_emboss_5_0_0_0470. @@ -164,9 +163,9 @@ def test_0025_upload_updated_tool_dependency_to_package_emboss(self): "package_emboss_5_0_0_0470", package_emboss_repository, start=1, end=2 ) count = self._get_metadata_revision_count(package_emboss_repository) - assert count == 2, ( - "package_emboss_5_0_0_0470 has incorrect number of metadata revisions, expected 2 but found %d" % count - ) + assert ( + count == 2 + ), f"package_emboss_5_0_0_0470 has incorrect number of metadata revisions, expected 2 but found {count}" def test_0030_upload_updated_tool_dependency_to_emboss_5_repository(self): """Upload a new tool_dependencies.xml to emboss_5_0470. @@ -216,11 +215,9 @@ def test_0045_reset_repository_metadata(self): self.reset_repository_metadata(package_emboss_repository) self.reset_repository_metadata(package_x11_repository) count = self._get_metadata_revision_count(package_emboss_repository) - assert count == 1, "Repository package_emboss_5_0_0 has %d installable revisions, expected 1." % count + assert count == 1, f"Repository package_emboss_5_0_0 has {count} installable revisions, expected 1." count = self._get_metadata_revision_count(package_x11_repository) - assert count == 1, ( - "Repository package_x11_client_1_5_proto_7_0 has %d installable revisions, expected 1." % count - ) + assert count == 1, f"Repository package_x11_client_1_5_proto_7_0 has {count} installable revisions, expected 1." def test_0050_reset_emboss_5_metadata(self): """Reset metadata on emboss_5. @@ -230,4 +227,4 @@ def test_0050_reset_emboss_5_metadata(self): emboss_repository = self._get_repository_by_name_and_owner(emboss_repository_name, common.test_user_1_name) self.reset_repository_metadata(emboss_repository) count = self._get_metadata_revision_count(emboss_repository) - assert count == 1, "Repository emboss_5 has %d installable revisions, expected 1." % count + assert count == 1, f"Repository emboss_5 has {count} installable revisions, expected 1." diff --git a/lib/tool_shed/util/admin_util.py b/lib/tool_shed/util/admin_util.py index c85aba5fae69..4e01b03b3369 100644 --- a/lib/tool_shed/util/admin_util.py +++ b/lib/tool_shed/util/admin_util.py @@ -128,11 +128,7 @@ def create_role(self, trans, **kwd): num_in_groups = len(in_groups) with transaction(trans.sa_session): trans.sa_session.commit() - message = "Role '%s' has been created with %d associated users and %d associated groups. " % ( - role.name, - len(in_users), - num_in_groups, - ) + message = f"Role '{role.name}' has been created with {len(in_users)} associated users and {num_in_groups} associated groups. " if create_group_for_role_checked: message += ( "One of the groups associated with this role is the newly created group with the same name." @@ -232,11 +228,7 @@ def manage_users_and_groups_for_role(self, trans, **kwd): in_groups = [trans.sa_session.get(trans.app.model.Group, x) for x in util.listify(params.in_groups)] trans.app.security_agent.set_entity_role_associations(roles=[role], users=in_users, groups=in_groups) trans.sa_session.refresh(role) - message = "Role '%s' has been updated with %d associated users and %d associated groups" % ( - role.name, - len(in_users), - len(in_groups), - ) + message = f"Role '{role.name}' has been updated with {len(in_users)} associated users and {len(in_groups)} associated groups" trans.response.send_redirect( web.url_for(controller="admin", action="roles", message=util.sanitize_text(message), status=status) ) @@ -303,7 +295,7 @@ def mark_role_deleted(self, trans, **kwd): web.url_for(controller="admin", action="roles", message=message, status="error") ) ids = util.listify(id) - message = "Deleted %d roles: " % len(ids) + message = f"Deleted {len(ids)} roles: " for role_id in ids: role = get_role(trans, role_id) role.deleted = True @@ -325,8 +317,7 @@ def undelete_role(self, trans, **kwd): web.url_for(controller="admin", action="roles", message=message, status="error") ) ids = util.listify(id) - count = 0 - undeleted_roles = "" + undeleted_roles = [] for role_id in ids: role = get_role(trans, role_id) if not role.deleted: @@ -338,9 +329,8 @@ def undelete_role(self, trans, **kwd): trans.sa_session.add(role) with transaction(trans.sa_session): trans.sa_session.commit() - count += 1 - undeleted_roles += f" {role.name}" - message = "Undeleted %d roles: %s" % (count, undeleted_roles) + undeleted_roles.append(role.name) + message = "Undeleted {} roles: {}".format(len(undeleted_roles), " ".join(undeleted_roles)) trans.response.send_redirect( web.url_for(controller="admin", action="roles", message=util.sanitize_text(message), status="done") ) @@ -362,7 +352,7 @@ def purge_role(self, trans, **kwd): web.url_for(controller="admin", action="roles", message=util.sanitize_text(message), status="error") ) ids = util.listify(id) - message = "Purged %d roles: " % len(ids) + message = f"Purged {len(ids)} roles: " for role_id in ids: role = get_role(trans, role_id) if not role.deleted: @@ -472,11 +462,7 @@ def manage_users_and_roles_for_group(self, trans, **kwd): in_users = [trans.sa_session.get(trans.app.model.User, x) for x in util.listify(params.in_users)] trans.app.security_agent.set_entity_group_associations(groups=[group], roles=in_roles, users=in_users) trans.sa_session.refresh(group) - message += "Group '%s' has been updated with %d associated roles and %d associated users" % ( - group.name, - len(in_roles), - len(in_users), - ) + message += f"Group '{group.name}' has been updated with {len(in_roles)} associated roles and {len(in_users)} associated users" trans.response.send_redirect( web.url_for(controller="admin", action="groups", message=util.sanitize_text(message), status=status) ) @@ -494,11 +480,7 @@ def manage_users_and_roles_for_group(self, trans, **kwd): in_users.append((user.id, user.email)) else: out_users.append((user.id, user.email)) - message += "Group %s is currently associated with %d roles and %d users" % ( - group.name, - len(in_roles), - len(in_users), - ) + message += f"Group {group.name} is currently associated with {len(in_roles)} roles and {len(in_users)} users" return trans.fill_template( "/webapps/tool_shed/admin/dataset_security/group/group.mako", group=group, @@ -561,11 +543,7 @@ def create_group(self, trans, **kwd): num_in_roles = len(in_roles) with transaction(trans.sa_session): trans.sa_session.commit() - message = "Group '%s' has been created with %d associated users and %d associated roles. " % ( - group.name, - len(in_users), - num_in_roles, - ) + message = f"Group '{group.name}' has been created with {len(in_users)} associated users and {num_in_roles} associated roles. " if create_role_for_group_checked: message += ( "One of the roles associated with this group is the newly created role with the same name." @@ -601,7 +579,7 @@ def mark_group_deleted(self, trans, **kwd): web.url_for(controller="admin", action="groups", message=message, status="error") ) ids = util.listify(id) - message = "Deleted %d groups: " % len(ids) + message = f"Deleted {len(ids)} groups: " for group_id in ids: group = get_group(trans, group_id) group.deleted = True @@ -623,8 +601,7 @@ def undelete_group(self, trans, **kwd): web.url_for(controller="admin", action="groups", message=message, status="error") ) ids = util.listify(id) - count = 0 - undeleted_groups = "" + undeleted_groups = [] for group_id in ids: group = get_group(trans, group_id) if not group.deleted: @@ -638,9 +615,8 @@ def undelete_group(self, trans, **kwd): trans.sa_session.add(group) with transaction(trans.sa_session): trans.sa_session.commit() - count += 1 - undeleted_groups += f" {group.name}" - message = "Undeleted %d groups: %s" % (count, undeleted_groups) + undeleted_groups.append(group.name) + message = "Undeleted {} groups: {}".format(len(undeleted_groups), " ".join(undeleted_groups)) trans.response.send_redirect( web.url_for(controller="admin", action="groups", message=util.sanitize_text(message), status="done") ) @@ -657,7 +633,7 @@ def purge_group(self, trans, **kwd): web.url_for(controller="admin", action="groups", message=util.sanitize_text(message), status="error") ) ids = util.listify(id) - message = "Purged %d groups: " % len(ids) + message = f"Purged {len(ids)} groups: " for group_id in ids: group = get_group(trans, group_id) if not group.deleted: @@ -713,7 +689,9 @@ def reset_user_password(self, trans, **kwd): with transaction(trans.sa_session): trans.sa_session.commit() if not message and not status: - message = "Passwords reset for %d %s." % (len(user_ids), inflector.cond_plural(len(user_ids), "user")) + message = "Passwords reset for {} {}.".format( + len(user_ids), inflector.cond_plural(len(user_ids), "user") + ) status = "done" trans.response.send_redirect( web.url_for(controller="admin", action="users", message=util.sanitize_text(message), status=status) @@ -735,7 +713,7 @@ def mark_user_deleted(self, trans, **kwd): web.url_for(controller="admin", action="users", message=message, status="error") ) ids = util.listify(id) - message = "Deleted %d users: " % len(ids) + message = f"Deleted {len(ids)} users: " for user_id in ids: user = get_user(trans, user_id) user.deleted = True @@ -780,8 +758,7 @@ def undelete_user(self, trans, **kwd): web.url_for(controller="admin", action="users", message=message, status="error") ) ids = util.listify(id) - count = 0 - undeleted_users = "" + undeleted_users = [] for user_id in ids: user = get_user(trans, user_id) if not user.deleted: @@ -793,9 +770,8 @@ def undelete_user(self, trans, **kwd): trans.sa_session.add(user) with transaction(trans.sa_session): trans.sa_session.commit() - count += 1 - undeleted_users += f" {user.email}" - message = "Undeleted %d users: %s" % (count, undeleted_users) + undeleted_users.append(user.email) + message = "Undeleted {} users: {}".format(len(undeleted_users), " ".join(undeleted_users)) trans.response.send_redirect( web.url_for(controller="admin", action="users", message=util.sanitize_text(message), status="done") ) @@ -822,7 +798,7 @@ def purge_user(self, trans, **kwd): web.url_for(controller="admin", action="users", message=util.sanitize_text(message), status="error") ) ids = util.listify(id) - message = "Purged %d users: " % len(ids) + message = f"Purged {len(ids)} users: " for user_id in ids: user = get_user(trans, user_id) if not user.deleted: @@ -936,10 +912,7 @@ def manage_roles_and_groups_for_user(self, trans, **kwd): if in_roles: trans.app.security_agent.set_entity_user_associations(users=[user], roles=in_roles, groups=in_groups) trans.sa_session.refresh(user) - message += ( - "User '%s' has been updated with %d associated roles and %d associated groups (private roles are not displayed)" - % (user.email, len(in_roles), len(in_groups)) - ) + message += f"User '{user.email}' has been updated with {len(in_roles)} associated roles and {len(in_groups)} associated groups (private roles are not displayed)" trans.response.send_redirect( web.url_for(controller="admin", action="users", message=util.sanitize_text(message), status="done") ) @@ -961,11 +934,7 @@ def manage_roles_and_groups_for_user(self, trans, **kwd): in_groups.append((group.id, group.name)) else: out_groups.append((group.id, group.name)) - message += "User '%s' is currently associated with %d roles and is a member of %d groups" % ( - user.email, - len(in_roles), - len(in_groups), - ) + message += f"User '{user.email}' is currently associated with {len(in_roles)} roles and is a member of {len(in_groups)} groups" if not status: status = "done" return trans.fill_template( diff --git a/lib/tool_shed/util/hg_util.py b/lib/tool_shed/util/hg_util.py index 4f2a03155c2e..f08782b64eb2 100644 --- a/lib/tool_shed/util/hg_util.py +++ b/lib/tool_shed/util/hg_util.py @@ -167,7 +167,7 @@ def get_rev_label_changeset_revision_from_repository_metadata( repo = repository.hg_repo changeset_revision = repository_metadata.changeset_revision if ctx := get_changectx_for_changeset(repo, changeset_revision): - rev = "%04d" % ctx.rev() + rev = f"{ctx.rev():04d}" if include_date: changeset_revision_date = get_readable_ctx_date(ctx) if include_hash: @@ -207,7 +207,7 @@ def get_rev_label_from_changeset_revision(repo, changeset_revision, include_date which includes the revision date if the receive include_date is True. """ if ctx := get_changectx_for_changeset(repo, changeset_revision): - rev = "%04d" % ctx.rev() + rev = f"{ctx.rev():04d}" label = get_revision_label_from_ctx(ctx, include_date=include_date) else: rev = "-1" diff --git a/lib/tool_shed/util/repository_util.py b/lib/tool_shed/util/repository_util.py index 51c9ae6d1155..592c3e9b3b1f 100644 --- a/lib/tool_shed/util/repository_util.py +++ b/lib/tool_shed/util/repository_util.py @@ -390,12 +390,7 @@ def handle_role_associations(app: "ToolShedApp", role, repository, **kwd): roles=[role], users=in_users, groups=in_groups, repositories=in_repositories ) sa_session.refresh(role) - message += "Role %s has been associated with %d users, %d groups and %d repositories. " % ( - escape(str(role.name)), - len(in_users), - len(in_groups), - len(in_repositories), - ) + message += f"Role {escape(str(role.name))} has been associated with {len(in_users)} users, {len(in_groups)} groups and {len(in_repositories)} repositories. " in_users = [] out_users = [] in_groups = [] diff --git a/lib/tool_shed/util/shed_index.py b/lib/tool_shed/util/shed_index.py index 11faf5d9c8c2..c1f93c4f09c1 100644 --- a/lib/tool_shed/util/shed_index.py +++ b/lib/tool_shed/util/shed_index.py @@ -135,7 +135,7 @@ def get_repos(sa_session, file_path, hgweb_config_dir, hgweb_repo_prefix, **kwar # Parse all the tools within repo for a separate index. tools_list = [] path = os.path.join(file_path, *directory_hash_id(repo.id)) - path = os.path.join(path, "repo_%d" % repo.id) + path = os.path.join(path, f"repo_{repo.id}") if os.path.exists(path): tools_list.extend(load_one_dir(path)) for root, dirs, _files in os.walk(path): diff --git a/lib/tool_shed/webapp/api/repository_revisions.py b/lib/tool_shed/webapp/api/repository_revisions.py index be3b358adedf..a49921c0d73d 100644 --- a/lib/tool_shed/webapp/api/repository_revisions.py +++ b/lib/tool_shed/webapp/api/repository_revisions.py @@ -87,7 +87,7 @@ def repository_dependencies(self, trans, id, **kwd): tool_shed, name, owner, changeset_revision = rd_tup[0:4] repository_dependency = repository_util.get_repository_by_name_and_owner(trans.app, name, owner) if repository_dependency is None: - log.dbug(f"Cannot locate repository dependency {name} owned by {owner}.") + log.debug(f"Cannot locate repository dependency {name} owned by {owner}.") continue repository_dependency_id = trans.security.encode_id(repository_dependency.id) repository_dependency_repository_metadata = metadata_util.get_repository_metadata_by_changeset_revision( @@ -109,10 +109,9 @@ def repository_dependencies(self, trans, id, **kwd): else: decoded_repository_dependency_id = trans.security.decode_id(repository_dependency_id) debug_msg = ( - "Cannot locate repository_metadata with id %d for repository dependency %s owned by %s " - % (decoded_repository_dependency_id, str(name), str(owner)) + f"Cannot locate repository_metadata with id {decoded_repository_dependency_id} for repository dependency {name} owned by {owner} " + f"using either of these changeset_revisions: {changeset_revision}, {new_changeset_revision}." ) - debug_msg += f"using either of these changeset_revisions: {changeset_revision}, {new_changeset_revision}." log.debug(debug_msg) continue repository_dependency_metadata_dict = repository_dependency_repository_metadata.to_dict( diff --git a/lib/tool_shed/webapp/controllers/admin.py b/lib/tool_shed/webapp/controllers/admin.py index 9b1681bafe24..f07ce4297192 100644 --- a/lib/tool_shed/webapp/controllers/admin.py +++ b/lib/tool_shed/webapp/controllers/admin.py @@ -176,8 +176,7 @@ def delete_repository(self, trans, **kwd): if id := kwd.get("id", None): # Deleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify(id) - count = 0 - deleted_repositories = "" + deleted_repositories = [] for repository_id in ids: repository = repository_util.get_repository_in_tool_shed(trans.app, repository_id) if repository: @@ -197,13 +196,13 @@ def delete_repository(self, trans, **kwd): trans.sa_session.commit() # Update the repository registry. trans.app.repository_registry.remove_entry(repository) - count += 1 - deleted_repositories += f" {repository.name} " + deleted_repositories.append(repository.name) + count = len(deleted_repositories) if count: - message = "Deleted %d %s: %s" % ( + message = "Deleted {} {}: {}".format( count, - inflector.cond_plural(len(ids), "repository"), - escape(deleted_repositories), + inflector.cond_plural(count, "repository"), + escape(" ".join(deleted_repositories)), ) else: message = "All selected repositories were already marked deleted." @@ -223,15 +222,13 @@ def delete_repository_metadata(self, trans, **kwd): status = kwd.get("status", "done") if id := kwd.get("id", None): ids = util.listify(id) - count = 0 for repository_metadata_id in ids: repository_metadata = metadata_util.get_repository_metadata_by_id(trans.app, repository_metadata_id) trans.sa_session.delete(repository_metadata) with transaction(trans.sa_session): trans.sa_session.commit() - count += 1 - if count: - message = "Deleted %d repository metadata %s" % (count, inflector.cond_plural(len(ids), "record")) + count = len(ids) + message = "Deleted {} repository metadata {}".format(count, inflector.cond_plural(count, "record")) else: message = "No repository metadata ids received for deleting." status = "error" @@ -383,8 +380,7 @@ def undelete_repository(self, trans, **kwd): if id := kwd.get("id", None): # Undeleting multiple items is currently not allowed (allow_multiple=False), so there will only be 1 id. ids = util.listify(id) - count = 0 - undeleted_repositories = "" + undeleted_repositories = [] for repository_id in ids: repository = repository_util.get_repository_in_tool_shed(trans.app, repository_id) if repository: @@ -409,13 +405,13 @@ def undelete_repository(self, trans, **kwd): if not repository.deprecated: # Update the repository registry. trans.app.repository_registry.add_entry(repository) - count += 1 - undeleted_repositories += f" {repository.name}" + undeleted_repositories.append(repository.name) + count = len(undeleted_repositories) if count: - message = "Undeleted %d %s: %s" % ( + message = "Undeleted {} {}: {}".format( count, inflector.cond_plural(count, "repository"), - undeleted_repositories, + " ".join(undeleted_repositories), ) else: message = "No selected repositories were marked deleted, so they could not be undeleted." @@ -433,10 +429,9 @@ def mark_category_deleted(self, trans, **kwd): # TODO: We should probably eliminate the Category.deleted column since it really makes no # sense to mark a category as deleted (category names and descriptions can be changed instead). # If we do this, and the following 2 methods can be eliminated. - message = escape(kwd.get("message", "")) if id := kwd.get("id", None): ids = util.listify(id) - message = "Deleted %d categories: " % len(ids) + deleted_categories = [] for category_id in ids: category = suc.get_category(trans.app, category_id) category.deleted = True @@ -445,7 +440,8 @@ def mark_category_deleted(self, trans, **kwd): trans.sa_session.commit() # Update the Tool Shed's repository registry. trans.app.repository_registry.remove_category_entry(category) - message += f" {escape(category.name)} " + deleted_categories.append(category.name) + message = "Deleted {} categories: {}".format(len(deleted_categories), escape(" ".join(deleted_categories))) else: message = "No category ids received for deleting." trans.response.send_redirect( @@ -463,9 +459,7 @@ def purge_category(self, trans, **kwd): message = escape(kwd.get("message", "")) if id := kwd.get("id", None): ids = util.listify(id) - count = 0 - purged_categories = "" - message = "Purged %d categories: " % len(ids) + purged_categories = [] for category_id in ids: category = suc.get_category(trans.app, category_id) if category.deleted: @@ -474,8 +468,8 @@ def purge_category(self, trans, **kwd): trans.sa_session.delete(rca) with transaction(trans.sa_session): trans.sa_session.commit() - purged_categories += f" {category.name} " - message = "Purged %d categories: %s" % (count, escape(purged_categories)) + purged_categories.append(category.name) + message = "Purged {} categories: {}".format(len(purged_categories), escape(" ".join(purged_categories))) else: message = "No category ids received for purging." trans.response.send_redirect( @@ -490,8 +484,7 @@ def undelete_category(self, trans, **kwd): message = escape(kwd.get("message", "")) if id := kwd.get("id", None): ids = util.listify(id) - count = 0 - undeleted_categories = "" + undeleted_categories = [] for category_id in ids: category = suc.get_category(trans.app, category_id) if category.deleted: @@ -501,9 +494,10 @@ def undelete_category(self, trans, **kwd): trans.sa_session.commit() # Update the Tool Shed's repository registry. trans.app.repository_registry.add_category_entry(category) - count += 1 - undeleted_categories += f" {category.name}" - message = "Undeleted %d categories: %s" % (count, escape(undeleted_categories)) + undeleted_categories.append(category.name) + message = "Undeleted {} categories: {}".format( + len(undeleted_categories), escape(" ".join(undeleted_categories)) + ) else: message = "No category ids received for undeleting." trans.response.send_redirect( diff --git a/lib/tool_shed/webapp/controllers/repository.py b/lib/tool_shed/webapp/controllers/repository.py index 67fd5ed998cd..5e2ee39f0e7f 100644 --- a/lib/tool_shed/webapp/controllers/repository.py +++ b/lib/tool_shed/webapp/controllers/repository.py @@ -2161,7 +2161,7 @@ def set_email_alerts(self, trans, **kwd): if flush_needed: with transaction(trans.sa_session): trans.sa_session.commit() - message = "Total alerts added: %d, total alerts removed: %d" % (total_alerts_added, total_alerts_removed) + message = f"Total alerts added: {total_alerts_added}, total alerts removed: {total_alerts_removed}" kwd["message"] = message kwd["status"] = "done" del kwd["operation"] diff --git a/lib/tool_shed/webapp/model/__init__.py b/lib/tool_shed/webapp/model/__init__.py index 8cd5f31d8a04..b950938b869d 100644 --- a/lib/tool_shed/webapp/model/__init__.py +++ b/lib/tool_shed/webapp/model/__init__.py @@ -530,7 +530,7 @@ def hg_repository_path(self, repositories_directory: str) -> str: if self.id is None: raise Exception("Attempting to call hg_repository_path before id has been set on repository object") dir = os.path.join(repositories_directory, *util.directory_hash_id(self.id)) - final_repository_path = os.path.join(dir, "repo_%d" % self.id) + final_repository_path = os.path.join(dir, f"repo_{self.id}") return final_repository_path def ensure_hg_repository_path(self, repositories_directory: str) -> str: @@ -667,7 +667,7 @@ class Tag(Base): parent = relationship("Tag", back_populates="children", remote_side=[id]) def __str__(self): - return "Tag(id=%s, type=%i, parent_id=%s, name=%s)" % (self.id, self.type, self.parent_id, self.name) + return f"Tag(id={self.id}, type={self.type}, parent_id={self.parent_id}, name={self.name})" # The RepositoryMetadata model is mapped imperatively (for details see discussion in PR #12064).