From 6193cf445da39b8e3947ee1e1c5dcd61b6f0da1f Mon Sep 17 00:00:00 2001 From: Thomas Kolb Date: Mon, 13 Nov 2023 20:02:29 +0100 Subject: [PATCH] Move CLI code out of qsomap.py qsomap.py is now a library with no own functionality. --- cli.py | 24 ++++++++++++++++++++++++ qsomap.py | 21 --------------------- 2 files changed, 24 insertions(+), 21 deletions(-) create mode 100755 cli.py mode change 100755 => 100644 qsomap.py diff --git a/cli.py b/cli.py new file mode 100755 index 0000000..733c2cc --- /dev/null +++ b/cli.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import sys +import qsomap +import argparse + +parser = argparse.ArgumentParser( + description="Render an azimuthal equidistant map of the world " + + "centered on the given point") + +parser.add_argument(metavar='ref-lat', type=float, dest='ref_lat', + help='Reference Latitude') +parser.add_argument(metavar='ref-lon', type=float, dest='ref_lon', + help='Reference Longitude') +parser.add_argument('-o', '--output-file', type=argparse.FileType('w'), + help='The output SVG file (default: print to stdout)', + default=sys.stdout) +parser.add_argument('-a', '--adif', type=argparse.FileType('r'), + required=False, + help='ADIF log to load and display on the map') + +args = parser.parse_args() + +qsomap.render(args.ref_lat, args.ref_lon, args.output_file, args.adif) diff --git a/qsomap.py b/qsomap.py old mode 100755 new mode 100644 index 5226fb9..a989af6 --- a/qsomap.py +++ b/qsomap.py @@ -9,7 +9,6 @@ import matplotlib.pyplot as pp from matplotlib.colors import hsv_to_rgb import json import random -import argparse LABEL_MIN_FONT_SIZE = 2 LABEL_MAX_FONT_SIZE = 40 @@ -615,23 +614,3 @@ def render(ref_lat, ref_lon, output_stream, adif_stream): pp.show() - -if __name__ == "__main__": - parser = argparse.ArgumentParser( - description="Render an azimuthal equidistant map of the world " + - "centered on the given point") - - parser.add_argument(metavar='ref-lat', type=float, dest='ref_lat', - help='Reference Latitude') - parser.add_argument(metavar='ref-lon', type=float, dest='ref_lon', - help='Reference Longitude') - parser.add_argument('-o', '--output-file', type=argparse.FileType('w'), - help='The output SVG file (default: print to stdout)', - default=sys.stdout) - parser.add_argument('-a', '--adif', type=argparse.FileType('r'), - required=False, - help='ADIF log to load and display on the map') - - args = parser.parse_args() - - render(args.ref_lat, args.ref_lon, args.output_file, args.adif)