]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
python: Add scaffolding for an importer tool
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 May 2020 10:11:34 +0000 (10:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 12 May 2020 10:11:34 +0000 (10:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
.gitignore
Makefile.am
src/python/location-importer.in [new file with mode: 0644]

index ee45a591e605cbf717f11a2b458101143adeed00..b8b236aa22bf0f63109ec66af2049ca43eb74282 100644 (file)
@@ -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
index c92ee8f8d906de0c5e95bf9a294eb2b500aa2fae..e3a55d4f53e922196e3d85fc6a81f508766990c1 100644 (file)
@@ -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 (file)
index 0000000..a5bbf4b
--- /dev/null
@@ -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 <info@ipfire.org>                #
+#                                                                             #
+# 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()