python: Expose version of the module
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Feb 2018 13:33:38 +0000 (13:33 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Feb 2018 13:33:38 +0000 (13:33 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/location-query.in
src/python/locationmodule.c

index 260f4bd..e750ea4 100644 (file)
@@ -42,6 +42,10 @@ class CLI(object):
                parser.add_argument("--debug", action="store_true",
                        help=_("Enable debug output"))
 
+               # version
+               parser.add_argument("--version", action="version",
+                       version="%%(prog)s %s" % location.__version__)
+
                # lookup an IP address
                lookup = subparsers.add_parser("lookup",
                        help=_("Lookup one or multiple IP addresses"),
index 40b0c35..dcb5a47 100644 (file)
@@ -106,5 +106,11 @@ PyMODINIT_FUNC PyInit_location(void) {
        Py_INCREF(&WriterType);
        PyModule_AddObject(m, "Writer", (PyObject *)&WriterType);
 
+       // Add constants
+       PyObject* d = PyModule_GetDict(m);
+
+       // Version
+       PyDict_SetItemString(d, "__version__", PyUnicode_FromString(VERSION));
+
        return m;
 }