Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 436f8fda authored by Freezed's avatar Freezed
Browse files

:sparkles: Improve standalone vs import usage #2

Move args management & print() only if __name__ == __main__

TODO: remove print() by a logger
parent fa88079c
No related branches found
No related tags found
No related merge requests found
Pipeline #4305 passed
cli/gpx.py 100644 → 100755
......@@ -7,7 +7,6 @@ Process a GPX file to get informations.
import sys as mod_sys
import logging as mod_logging
import argparse as mod_argparse
from typing import Union, List
import gpxpy as mod_gpxpy
......@@ -87,7 +86,7 @@ def get_gpx_info(gpx: mod_gpx.GPX, gpx_file: str) -> None:
# gpx_summary.update({"segments": len(track.segments)})
gpx_summary.update(get_gpx_part_info(gpx))
print(gpx_summary)
return gpx_summary
def run(gpx_files: List[str]) -> None:
......@@ -101,7 +100,7 @@ def run(gpx_files: List[str]) -> None:
gpx = mod_gpxpy.parse(open_file)
try:
get_gpx_info(gpx, gpx_file)
return get_gpx_info(gpx, gpx_file)
except mod_gpx.GPXXMLSyntaxException as except_detail:
mod_logging.exception(except_detail)
mod_sys.exit(1)
......@@ -114,20 +113,12 @@ def run(gpx_files: List[str]) -> None:
if __name__ == "__main__":
import argparse as mod_argparse
parser = mod_argparse.ArgumentParser(
usage="%(prog)s [-d] [file ...]",
usage="%(prog)s [-h] path_to_gpx_file(s)",
description="Command line utility to extract basic statistics from gpx file(s)",
)
parser.add_argument(
"-d", "--debug", action="store_true", help="show detailed logging"
)
args, local_files = parser.parse_known_args()
debug = args.debug
if debug:
mod_logging.basicConfig(
level=mod_logging.DEBUG,
format="%(asctime)s %(name)-12s %(levelname)-8s %(message)s",
)
run(gpx_files=local_files)
print(run(gpx_files=local_files))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment