From: Michael Tremer Date: Tue, 12 May 2020 10:11:34 +0000 (+0000) Subject: python: Add scaffolding for an importer tool X-Git-Tag: 0.9.1~74 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=78ff0cf2833ad5ac53219dcc138aac0f4525ed40;p=location%2Flibloc.git python: Add scaffolding for an importer tool Signed-off-by: Michael Tremer --- diff --git a/.gitignore b/.gitignore index ee45a59..b8b236a 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ Makefile.in /stamp-h1 /src/python/location-downloader /src/python/location-exporter +/src/python/location-importer /src/python/location-query /src/systemd/location-downloader.service /src/systemd/location-downloader.timer diff --git a/Makefile.am b/Makefile.am index c92ee8f..e3a55d4 100644 --- a/Makefile.am +++ b/Makefile.am @@ -243,16 +243,19 @@ uninstall-perl: bin_SCRIPTS = \ src/python/location-downloader \ src/python/location-exporter \ + src/python/location-importer \ src/python/location-query EXTRA_DIST += \ src/python/location-downloader.in \ src/python/location-exporter.in \ + src/python/location-importer.in \ src/python/location-query.in CLEANFILES += \ src/python/location-downloader \ src/python/location-exporter \ + src/python/location-importer \ src/python/location-query # ------------------------------------------------------------------------------ diff --git a/src/python/location-importer.in b/src/python/location-importer.in new file mode 100644 index 0000000..a5bbf4b --- /dev/null +++ b/src/python/location-importer.in @@ -0,0 +1,77 @@ +#!/usr/bin/python3 +############################################################################### +# # +# libloc - A library to determine the location of someone on the Internet # +# # +# Copyright (C) 2020 IPFire Development Team # +# # +# This library is free software; you can redistribute it and/or # +# modify it under the terms of the GNU Lesser General Public # +# License as published by the Free Software Foundation; either # +# version 2.1 of the License, or (at your option) any later version. # +# # +# This library is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # +# Lesser General Public License for more details. # +# # +############################################################################### + +import argparse +import logging +import sys + +# Load our location module +import location +from location.i18n import _ + +# Initialise logging +log = logging.getLogger("location.importer") +log.propagate = 1 + +class CLI(object): + def parse_cli(self): + parser = argparse.ArgumentParser( + description=_("Location Importer Command Line Interface"), + ) + + # Global configuration flags + parser.add_argument("--debug", action="store_true", + help=_("Enable debug output")) + + # version + parser.add_argument("--version", action="version", + version="%(prog)s @VERSION@") + + args = parser.parse_args() + + # Enable debug logging + if args.debug: + log.setLevel(logging.DEBUG) + + return args + + def run(self): + # Parse command line arguments + args = self.parse_cli() + + # Call function + ret = self.handle_import(args) + + # Return with exit code + if ret: + sys.exit(ret) + + # Otherwise just exit + sys.exit(0) + + def handle_import(self, ns): + pass + + +def main(): + # Run the command line interface + c = CLI() + c.run() + +main()