Skip to content

Commit

Permalink
Changed formatting strings
Browse files Browse the repository at this point in the history
  • Loading branch information
P-T-I committed Jul 5, 2022
1 parent 9755c24 commit c07a1c8
Show file tree
Hide file tree
Showing 22 changed files with 101 additions and 161 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.dev32
2.0.dev33
24 changes: 9 additions & 15 deletions spectacles/docker_reg_api/Docker_reg_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,10 @@ def fetch_token(self, scope, service):
def set_token_header(self, name, action="pull"):

token = self.fetch_token(
"repository:{}:{}".format(name, action), service=self.docker_service_name
f"repository:{name}:{action}", service=self.docker_service_name
)

self.set_header_field(
"Authorization", "Bearer {}".format(token.build_token()["token"])
)
self.set_header_field("Authorization", f"Bearer {token.build_token()['token']}")

def ping(self):

Expand All @@ -65,8 +63,7 @@ def ping(self):

with self.get_session() as session:
r = session.get(
"{0}/{1}/{2}".format(self.baseurl, self.api_path, resource),
**request_api_resource
f"{self.baseurl}/{self.api_path}/{resource}", **request_api_resource
)

if "Www-Authenticate" in r.headers:
Expand All @@ -84,14 +81,13 @@ def ping(self):
token = self.fetch_token("registry:catalog:*", ret_dict["service"])

self.set_header_field(
"Authorization", "Bearer {}".format(token.build_token()["token"])
"Authorization", f"Bearer {token.build_token()['token']}"
)

resource = "_catalog"

r = session.get(
"{0}/{1}/{2}".format(self.baseurl, self.api_path, resource),
**request_api_resource
f"{self.baseurl}/{self.api_path}/{resource}", **request_api_resource
)

if r.status_code == 200:
Expand All @@ -105,9 +101,7 @@ def catalog_registry(self):

token = self.fetch_token("registry:catalog:*", service=self.docker_service_name)

self.set_header_field(
"Authorization", "Bearer {}".format(token.build_token()["token"])
)
self.set_header_field("Authorization", f"Bearer {token.build_token()['token']}")

resource = "_catalog"

Expand All @@ -117,7 +111,7 @@ def get_repository_list(self, name):

self.set_token_header(name=name)

resource = "{}/tags/list".format(name)
resource = f"{name}/tags/list"

return self.call("GET", resource=resource)

Expand All @@ -129,7 +123,7 @@ def get_repository_digest(self, name, tag):

self.set_token_header(name=name)

resource = "{}/manifests/{}".format(name, tag)
resource = f"{name}/manifests/{tag}"

result = self.call("GET", resource=resource, ret_headers=True)

Expand All @@ -139,6 +133,6 @@ def delete_repository(self, name, digest):

self.set_token_header(name=name, action="delete")

resource = "{}/manifests/{}".format(name, digest)
resource = f"{name}/manifests/{digest}"

return self.call("DELETE", resource=resource)
2 changes: 1 addition & 1 deletion spectacles/helpers/activity_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ def __insert(self, level, msg):
db.session.commit()
return True
except Exception as err:
self.logger.error("Error saving activity to database: {}".format(err))
self.logger.error(f"Error saving activity to database: {err}")
28 changes: 9 additions & 19 deletions spectacles/helpers/background_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ def CleanUpActivities(self):
)
db.session.commit()
if res != 0:
self.activity.info(
"Deleted from past activities: {} entries".format(res)
)
self.activity.info(f"Deleted from past activities: {res} entries")

def UpdateRegistryRepos(self):
self.logger.info("Running UpdateRegistryRepos")
Expand Down Expand Up @@ -126,19 +124,15 @@ def UpdateRegistryRepos(self):
):
if NEW:
self.activity.success(
"New repository discovered: {}".format(
my_repo.name
)
f"New repository discovered: {my_repo.name}"
)
db.session.add(my_repo)
db.session.commit()

for tag in repo_list["tags"]:

self.logger.info(
"Processing tag: {} of repo: {}".format(
tag, repo
)
f"Processing tag: {tag} of repo: {repo}"
)

digest = dr.get_repository_digest(
Expand Down Expand Up @@ -166,9 +160,7 @@ def UpdateRegistryRepos(self):
updated=update_time,
)
self.activity.success(
"New tag {} discovered for repository: {}".format(
my_tag.version, my_repo.name
)
f"New tag {my_tag.version} discovered for repository: {my_repo.name}"
)

db.session.add(my_tag)
Expand All @@ -182,17 +174,15 @@ def UpdateRegistryRepos(self):
db.session.commit()
if del_repo != 0:
self.activity.danger(
"Deleted repository: {}".format(
my_repo.name
)
f"Deleted repository: {my_repo.name}"
)

# non-existing namespace
else:
log_string = (
"Encountered a namespace on the registry that is not a part of spectacles "
"namespace database: {}. If you would like to access this namespace you "
"will have to add it!".format(namespace)
f"namespace database: {namespace}. If you would like to access this namespace you "
"will have to add it!"
)
self.logger.warning(log_string)
self.activity.warning(log_string)
Expand All @@ -201,7 +191,7 @@ def UpdateRegistryRepos(self):
del_tags = tags.query.filter(tags.updated != update_time).delete()
db.session.commit()
if del_tags != 0:
self.activity.info("Deleted {} old tags".format(del_tags))
self.activity.info(f"Deleted {del_tags} old tags")

# deleting repositories that are not updated; assuming that they do not longer exist on the
# registry
Expand All @@ -210,4 +200,4 @@ def UpdateRegistryRepos(self):
).delete()
db.session.commit()
if del_rep != 0:
self.activity.info("Deleted {} old tags".format(del_tags))
self.activity.info(f"Deleted {del_tags} old tags")
12 changes: 6 additions & 6 deletions spectacles/helpers/generic_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
self.server = address[0]
self.port = address[1]
self.protocol = protocol
self.baseurl = "{}://{}:{}".format(self.protocol, self.server, self.port)
self.baseurl = f"{self.protocol}://{self.server}:{self.port}"
self.api_path = api_path
self.proxies = proxies
self.user_agent = user_agent
Expand All @@ -55,7 +55,7 @@ def __init__(

def __repr__(self):
"""return a string representation of the obj GenericApi"""
return "<<GenericApi:({}, {})>>".format(self.server, self.port)
return f"<<GenericApi:({self.server}, {self.port})>>"

def __build_url(self, resource):
"""
Expand All @@ -67,9 +67,9 @@ def __build_url(self, resource):
:rtype: str
"""
if self.api_path is None:
return "{0}/{1}".format(self.baseurl, resource)
return f"{self.baseurl}/{resource}"
else:
return "{0}/{1}/{2}".format(self.baseurl, self.api_path, resource)
return f"{self.baseurl}/{self.api_path}/{resource}"

def __connect(
self, method, resource, session, data=None, timeout=60, ret_headers=False
Expand Down Expand Up @@ -179,7 +179,7 @@ def call(self, method=None, resource=None, data=None, **kwargs):
resource=resource,
session=session,
data=data,
**kwargs
**kwargs,
)
return result
except requests.ConnectionError:
Expand All @@ -197,7 +197,7 @@ def __default_headers(self):
return {
"Accept": "application/json",
"Content-Type": "application/json",
"User-Agent": "{}".format(self.user_agent),
"User-Agent": f"{self.user_agent}",
}

@property
Expand Down
10 changes: 5 additions & 5 deletions spectacles/helpers/logger_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def debug(self, msg, *args, **kwargs):
:type msg: str
"""

msg = colors.color("{}".format(msg), fg=HelperLogger.level_map["debug"])
msg = colors.color(f"{msg}", fg=HelperLogger.level_map["debug"])

return super(HelperLogger, self).debug(msg, *args, **kwargs)

Expand All @@ -89,7 +89,7 @@ def info(self, msg, *args, **kwargs):
:type msg: str
"""

msg = colors.color("{}".format(msg), fg=HelperLogger.level_map["info"])
msg = colors.color(f"{msg}", fg=HelperLogger.level_map["info"])

return super(HelperLogger, self).info(msg, *args, **kwargs)

Expand All @@ -105,7 +105,7 @@ def warning(self, msg, *args, **kwargs):
:type msg: str
"""

msg = colors.color("{}".format(msg), fg=HelperLogger.level_map["warning"])
msg = colors.color(f"{msg}", fg=HelperLogger.level_map["warning"])

return super(HelperLogger, self).warning(msg, *args, **kwargs)

Expand All @@ -123,7 +123,7 @@ def error(self, msg, *args, **kwargs):
:type msg: str
"""

msg = colors.color("{}".format(msg), fg=HelperLogger.level_map["error"])
msg = colors.color(f"{msg}", fg=HelperLogger.level_map["error"])

return super(HelperLogger, self).error(msg, *args, **kwargs)

Expand All @@ -141,6 +141,6 @@ def critical(self, msg, *args, **kwargs):
:type msg: str
"""

msg = colors.color("{}".format(msg), fg=HelperLogger.level_map["critical"])
msg = colors.color(f"{msg}", fg=HelperLogger.level_map["critical"])

return super(HelperLogger, self).critical(msg, *args, **kwargs)
2 changes: 1 addition & 1 deletion spectacles/webapp/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.dev32
2.0.dev33
23 changes: 10 additions & 13 deletions spectacles/webapp/admin/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from . import admin
from .forms import GroupForm
from ..auth.permissions import admin_required
from ..config import Config
from ..helpers.constants.common import msg_status, action_types
from ...helpers.activity_tracker import ActivityTracker
from ...helpers.app_logger import AppLogger
Expand All @@ -21,6 +22,8 @@

activity_track = ActivityTracker(action_type=action_types.GROUP)

config = Config()


@admin.route("/groups")
@login_required
Expand Down Expand Up @@ -51,7 +54,7 @@ def add_groups():
db.session.add(newgroup)
db.session.commit()
activity_track.success(
"User {} added group: {}".format(current_user.username, newgroup.name)
f"User {current_user.username} added group: {newgroup.name}"
)

return redirect(url_for("admin.get_groups"))
Expand All @@ -77,7 +80,7 @@ def del_groups():
groups.query.filter_by(id=post_data["id"]).delete()
db.session.commit()
activity_track.danger(
"User {} deleted group: {}".format(current_user.username, found_name)
f"User {current_user.username} deleted group: {found_name}"
)

total_groups = groups.query.filter().all()
Expand All @@ -87,12 +90,10 @@ def del_groups():
"partials/group_list.html", header="Groups", groups=total_groups
),
"status": msg_status.OK,
"msg": "Group {} deleted!".format(found_name),
"msg": f"Group {found_name} deleted!",
}
except Exception as err:
return jsonify(
{"status": msg_status.NOK, "msg": "Error encountered: {}".format(err)}
)
return jsonify({"status": msg_status.NOK, "msg": f"Error encountered: {err}"})


@admin.route("/groups/get_user_list", methods=["POST"])
Expand All @@ -115,7 +116,7 @@ def get_user_list():
{
"value": x.id,
"name": x.username,
"avatar": "/avatars/{}".format(x.avatar_l),
"avatar": f"{config.WEB_ROOT}/avatars/{x.avatar_l}",
"email": x.email,
}
for x in all_users
Expand Down Expand Up @@ -154,9 +155,7 @@ def set_user_list():
return jsonify(
{
"status": msg_status.NOK,
"msg": "The provided data is not the correct type, expected list got {}".format(
type(post_data["data"])
),
"msg": f"The provided data is not the correct type, expected list got {type(post_data['data'])}",
}
)

Expand All @@ -183,6 +182,4 @@ def del_groupmember():
"msg": "Group member deleted!",
}
except Exception as err:
return jsonify(
{"status": msg_status.NOK, "msg": "Error encountered: {}".format(err)}
)
return jsonify({"status": msg_status.NOK, "msg": f"Error encountered: {err}"})
22 changes: 7 additions & 15 deletions spectacles/webapp/admin/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ def get_count_dict():

ns_count = namespaces.query.filter(namespaces.registryid == each.id).count()

count_dict[each.uri] = "{} namespaces containing {} repositories".format(
ns_count, repo_count
)
count_dict[
each.uri
] = f"{ns_count} namespaces containing {repo_count} repositories"

return total_registry, count_dict

Expand Down Expand Up @@ -108,9 +108,7 @@ def add_registries():
db.session.add(reg)
db.session.commit()
activity_track.success(
"User {} added registry on uri: {}".format(
current_user.username, post_data["uri"]
)
f"User {current_user.username} added registry on uri: {post_data['uri']}"
)

total_registry, count_dict = get_count_dict()
Expand All @@ -125,9 +123,7 @@ def add_registries():
"msg": "Registry added!",
}
except Exception as err:
return jsonify(
{"status": msg_status.NOK, "msg": "Error encountered: {}".format(err)}
)
return jsonify({"status": msg_status.NOK, "msg": f"Error encountered: {err}"})


@admin.route("/registries/delete", methods=["POST"])
Expand All @@ -140,9 +136,7 @@ def del_registries():
registry.query.filter(registry.id == post_data["id"]).delete()
db.session.commit()
activity_track.danger(
"User {} deleted registry with ID: {}".format(
current_user.username, post_data["id"]
)
f"User {current_user.username} deleted registry with ID: {post_data['id']}"
)

total_registry = registry.query.filter().all()
Expand All @@ -155,6 +149,4 @@ def del_registries():
"msg": "Registry deleted!",
}
except Exception as err:
return jsonify(
{"status": msg_status.NOK, "msg": "Error encountered: {}".format(err)}
)
return jsonify({"status": msg_status.NOK, "msg": f"Error encountered: {err}"})
Loading

0 comments on commit c07a1c8

Please sign in to comment.