Skip to content

Commit

Permalink
Python - Improve some debug messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Sep 27, 2022
1 parent 79f8f5f commit cc60b52
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 2 additions & 2 deletions qgis_plugin_repo/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def main():
if plugin.experimental:
print(f"{plugin.name} {plugin.version} experimental")
else:
print(f"{plugin.name} {plugin.version}")
print(f"{plugin.name} {plugin.version} stable")

elif args.command == "merge":
if len(args.output_xml) >= 2:
Expand All @@ -70,7 +70,7 @@ def main():
merger.merge()
else:
print(
"A single XML file detected for the output."
"A single XML file detected for the output. "
"This file is going to be edited whatever it's has a QGIS version."
)
merger = Merger(args.input_xml, args.output_xml[0])
Expand Down
15 changes: 12 additions & 3 deletions qgis_plugin_repo/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ def __init__(self, input_uri: str, destination_uri: Optional[str] = None):
# Usually a path as a string (filepath or remote URL)
if is_url(input_uri):
self.input_uri = input_uri
self.input_parser = ET.fromstring(requests.get(self.input_uri).content)
try:
remote = requests.get(self.input_uri)
except requests.exceptions.MissingSchema:
print(f"The input {self.input_uri} is neither a valid file nor a valid URL.")
exit(2)
self.input_parser = ET.fromstring(remote.content)
else:
self.input_uri = Path(input_uri)
self.input_parser = ET.parse(self.input_uri.absolute()).getroot()
Expand All @@ -49,12 +54,16 @@ def __init__(self, input_uri: str, destination_uri: Optional[str] = None):
if not self.destination_uri.exists():
self.init()

self.output_tree = ET.parse(self.destination_uri.absolute())
try:
self.output_tree = ET.parse(self.destination_uri.absolute())
except ET.ParseError:
print(f"Invalid XML file content {self.destination_uri.absolute()}")
exit(1)
self.output_parser = self.output_tree.getroot()

def init(self) -> None:
""" Init the XML files with an empty catalog. """
print(f"Creating source {self.destination_uri.absolute()}")
print(f"Creating source {self.destination_uri.absolute()} because the file did not exist.")
with open(self.destination_uri, 'w', encoding='utf8') as f:
f.write(self.xml_template())

Expand Down

0 comments on commit cc60b52

Please sign in to comment.