1
0
forked from 0ad/0ad

Simplify code by making use of early returns

This commit is contained in:
Dunedan 2024-09-07 06:38:52 +02:00
parent f4c40b740c
commit eeb502c115
Signed by untrusted user: Dunedan
GPG Key ID: 885B16854284E0B2
2 changed files with 58 additions and 57 deletions

View File

@ -98,15 +98,13 @@ class Extractor:
break
else:
for filemask in self.include_masks:
if pathmatch(filemask, filename):
if not pathmatch(filemask, filename):
continue
filepath = os.path.join(directory_absolute_path, filename)
for (
message,
plural,
context,
position,
comments,
) in self.extract_from_file(filepath):
for message, plural, context, position, comments in self.extract_from_file(
filepath
):
if empty_string_pattern.match(message):
continue
@ -457,14 +455,14 @@ class XmlExtractor(Extractor):
for keyword in self.keywords:
for element in xml_document.iter(keyword):
lineno = element.sourceline
if element.text is not None:
if element.text is None:
continue
comments = []
if "extractJson" in self.keywords[keyword]:
json_extractor = self.get_json_extractor()
json_extractor.set_options(self.keywords[keyword]["extractJson"])
for message, context in json_extractor.extract_from_string(
element.text
):
for message, context in json_extractor.extract_from_string(element.text):
yield message, None, context, lineno, comments
else:
context = None

View File

@ -35,7 +35,9 @@ def warn_about_untouched_mods():
mods_root_folder = os.path.join(PROJECT_ROOT_DIRECTORY, "binaries", "data", "mods")
untouched_mods = {}
for mod_folder in os.listdir(mods_root_folder):
if mod_folder[0] != "_" and mod_folder[0] != ".":
if mod_folder.startswith(("_", ".")):
continue
if not os.path.exists(os.path.join(mods_root_folder, mod_folder, L10N_FOLDER_NAME)):
untouched_mods[mod_folder] = (
f"There is no '{L10N_FOLDER_NAME}' folder in the root folder of this mod."
@ -47,6 +49,7 @@ def warn_about_untouched_mods():
f"There is no '{messages_filename}' file within the '{L10N_FOLDER_NAME}' "
f"folder in the root folder of this mod."
)
if untouched_mods:
print("Warning: No messages were extracted from the following mods:")
for mod in untouched_mods: