Skip to content

Commit

Permalink
Remove gettext calls within log messages
Browse files Browse the repository at this point in the history
closes pulp#690
  • Loading branch information
lubosmj committed Apr 21, 2022
1 parent 5d26f6a commit 91708f7
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 56 deletions.
1 change: 1 addition & 0 deletions CHANGES/690.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Log messages are now not being translated.
4 changes: 1 addition & 3 deletions pulp_container/app/downloaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gettext import gettext as _

import aiohttp
import asyncio
import json
Expand Down Expand Up @@ -118,7 +116,7 @@ async def update_token(self, response_auth_header, used_token, repo_name):
try:
token_base_url = auth_query_dict.pop("realm")
except KeyError:
raise IOError(_("No realm specified for token auth challenge."))
raise IOError("No realm specified for token auth challenge.")

# self defense strategy in cases when registry does not provide the scope
if "scope" not in auth_query_dict:
Expand Down
12 changes: 4 additions & 8 deletions pulp_container/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,17 +506,13 @@ def validate(self):
verified = gpg.verify_file(fp)
if verified.trust_level is None or verified.trust_level < verified.TRUST_FULLY:
raise RuntimeError(
_(
"The signature could not be verified or the trust level is too "
"low. The signing script may generate invalid signatures."
)
"The signature could not be verified or the trust level is too "
"low. The signing script may generate invalid signatures."
)
elif verified.pubkey_fingerprint != self.pubkey_fingerprint:
raise RuntimeError(
_(
"Fingerprints of the provided public key and the verified public "
"key are not equal. The signing script is probably not valid."
)
"Fingerprints of the provided public key and the verified public "
"key are not equal. The signing script is probably not valid."
)


Expand Down
5 changes: 2 additions & 3 deletions pulp_container/app/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
import os
from gettext import gettext as _

from asgiref.sync import sync_to_async

Expand Down Expand Up @@ -67,7 +66,7 @@ async def _dispatch(file, headers):
"""
path = os.path.join(settings.MEDIA_ROOT, file.name)
if not os.path.exists(path):
raise Exception(_("Expected path '{}' is not found").format(path))
raise Exception("Expected path '{}' is not found".format(path))

full_headers = MultiDict()

Expand Down Expand Up @@ -121,7 +120,7 @@ async def get_tag(self, request):
and tag.tagged_manifest.media_type not in accepted_media_types
):
log.warn(
_("OCI format found, but the client only accepts {accepted_media_types}.").format(
"OCI format found, but the client only accepts {accepted_media_types}.".format(
accepted_media_types=accepted_media_types
)
)
Expand Down
8 changes: 3 additions & 5 deletions pulp_container/app/schema_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import json
import logging

from gettext import gettext as _

from collections import namedtuple
from jwkest import jws, jwk, ecc

Expand Down Expand Up @@ -332,7 +330,7 @@ def _get_dict(artifact):
return data
except FileNotFoundError:
raise Exception(
_(
"Expected manifest file 'sha256:{}' needed for schema conversion is not found"
).format(artifact.sha256)
"Expected manifest file 'sha256:{}' needed for schema conversion is not found".format(
artifact.sha256
)
)
35 changes: 14 additions & 21 deletions pulp_container/app/tasks/sync_stages.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import json
import logging

from gettext import gettext as _
from urllib.parse import urljoin, urlparse, urlunparse

from asgiref.sync import sync_to_async
Expand Down Expand Up @@ -89,11 +88,9 @@ async def run(self):

if signature_source is None and self.signed_only:
raise ValueError(
_(
"It is requested to sync only signed content but no sigstore URL is "
"provided. Please configure a `sigstore` on your Remote or set "
"`signed_only` to `False` for your sync request."
)
"It is requested to sync only signed content but no sigstore URL is "
"provided. Please configure a `sigstore` on your Remote or set "
"`signed_only` to `False` for your sync request."
)

async with ProgressReport(
Expand Down Expand Up @@ -149,15 +146,13 @@ async def run(self):
man_sig_dcs = await self.create_signatures(man_dc, signature_source)
if self.signed_only and not man_sig_dcs:
log.info(
_(
"The unsigned image {img_digest} which is a part of the "
"manifest list {ml_digest} (tagged as `{tag}`) can't be "
"synced due to a requirement to sync signed content only. "
"The whole manifest list is skipped.".format(
img_digest=man_dc.content.digest,
ml_digest=list_dc.content.digest,
tag=tag_name,
)
"The unsigned image {img_digest} which is a part of the "
"manifest list {ml_digest} (tagged as `{tag}`) can't be "
"synced due to a requirement to sync signed content only. "
"The whole manifest list is skipped.".format(
img_digest=man_dc.content.digest,
ml_digest=list_dc.content.digest,
tag=tag_name,
)
)
# do not pass down the pipeline a manifest list with unsigned
Expand Down Expand Up @@ -533,10 +528,8 @@ async def create_signatures(self, man_dc, signature_source):
except aiohttp.client_exceptions.ClientResponseError as exc:
if exc.status != 404:
log.info(
_(
"{} is not accessible, can't sync an image signature. "
"Error: {} {}".format(signature_url, exc.status, exc.message)
)
"{} is not accessible, can't sync an image signature. "
"Error: {} {}".format(signature_url, exc.status, exc.message)
)
# 404 is fine, it means there are no or no more signatures available
break
Expand Down Expand Up @@ -593,7 +586,7 @@ def _include_layer(self, layer):
layer_type = layer.get("mediaType", MEDIA_TYPE.REGULAR_BLOB)
is_foreign = layer_type in (MEDIA_TYPE.FOREIGN_BLOB, MEDIA_TYPE.FOREIGN_BLOB_OCI)
if is_foreign and foreign_excluded:
log.debug(_("Foreign Layer: %(d)s EXCLUDED"), dict(d=layer))
log.debug("Foreign Layer: %(d)s EXCLUDED", dict(d=layer))
return False
return True

Expand Down Expand Up @@ -663,7 +656,7 @@ def _pad_unpadded_b64(self, unpadded_b64):
# It is illegal base64 for the remainder to be 1 when the length of the block is
# divided by 4.
if len(unpadded_b64) % 4 == 1:
raise ValueError(_("Invalid base64: {t}").format(t=unpadded_b64))
raise ValueError("Invalid base64: {t}".format(t=unpadded_b64))
# Add back the missing padding characters, based on the length of the encoded string
paddings = {0: "", 2: "==", 3: "="}
return unpadded_b64 + paddings[len(unpadded_b64) % 4]
Expand Down
5 changes: 1 addition & 4 deletions pulp_container/app/tasks/synchronize.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from gettext import gettext as _
import logging

from pulpcore.plugin.stages import (
Expand Down Expand Up @@ -36,9 +35,7 @@ def synchronize(remote_pk, repository_pk, mirror, signed_only):
"""
remote = ContainerRemote.objects.get(pk=remote_pk)
repository = ContainerRepository.objects.get(pk=repository_pk)
if not remote.url:
raise ValueError(_("A remote must have a url specified to synchronize."))
log.info(_("Synchronizing: repository={r} remote={p}").format(r=repository.name, p=remote.name))
log.info("Synchronizing: repository={r} remote={p}".format(r=repository.name, p=remote.name))
first_stage = ContainerFirstStage(remote, signed_only)
dv = ContainerDeclarativeVersion(first_stage, repository, mirror)
return dv.create()
Expand Down
16 changes: 4 additions & 12 deletions pulp_container/app/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from gettext import gettext as _

import gnupg
import json
import logging
Expand Down Expand Up @@ -73,22 +71,16 @@ def extract_data_from_signature(signature_raw, man_digest):
crypt_obj = gpg.decrypt(signature_raw)
if not crypt_obj.data:
log.info(
_(
"It is not possible to read the signed document, GPG error: {}".format(
crypt_obj.stderr
)
)
"It is not possible to read the signed document, GPG error: {}".format(crypt_obj.stderr)
)
return

try:
sig_json = json.loads(crypt_obj.data)
except Exception as exc:
log.info(
_(
"Signed document cannot be parsed to create a signature for {}."
" Error: {}".format(man_digest, str(exc))
)
"Signed document cannot be parsed to create a signature for {}."
" Error: {}".format(man_digest, str(exc))
)
return

Expand All @@ -97,7 +89,7 @@ def extract_data_from_signature(signature_raw, man_digest):
errors.append(error.message)

if errors:
log.info(_("The signature for {} is not synced due to: {}".format(man_digest, errors)))
log.info("The signature for {} is not synced due to: {}".format(man_digest, errors))
return

sig_json["signing_key_id"] = crypt_obj.key_id
Expand Down

0 comments on commit 91708f7

Please sign in to comment.