Skip to content

Commit

Permalink
chore(Python): Check if missing strings path exists and is not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
anddea committed Nov 6, 2024
1 parent a58c3df commit 2d5d325
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions xml_tools/handlers/missing_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ def compare_and_update(source_path: Path, dest_path: Path, missing_path: Path) -
# Parse source and destination files
_, _, source_strings = XMLProcessor.parse_file(source_path)
_, _, dest_strings = XMLProcessor.parse_file(dest_path)
_, _, missing_path_strings = (
XMLProcessor.parse_file(missing_path) if missing_path.exists() else (None, None, {})
)
_, _, missing_path_strings = XMLProcessor.parse_file(missing_path)

# Find missing strings
missing_strings = {}
Expand Down
3 changes: 3 additions & 0 deletions xml_tools/utils/xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ def parse_file(path: Path) -> Tuple[ET.ElementTree, ET.Element, Dict[str, Dict[s
Note:
Only elements with 'name' attributes are included in the returned dictionary.
"""
if not path.exists() or path.stat().st_size < 2:
return None, None, {}

try:
tree = ET.parse(path)
root = tree.getroot()
Expand Down

0 comments on commit 2d5d325

Please sign in to comment.