python/: Add --version switch to all scripts.
authorMarko Kreen <markokr@gmail.com>
Wed, 14 Oct 2009 15:03:54 +0000 (18:03 +0300)
committerMarko Kreen <markokr@gmail.com>
Wed, 14 Oct 2009 15:03:54 +0000 (18:03 +0300)
Based on patch by Hannu Krosing

Makefile
config.mak.in
python/skytools/__init__.py
python/skytools/installer_config.py.in
python/skytools/scripting.py

index 976597d3d5ad7a2fa5c6192704c66b5da9d4d277..8a5df5c89e0ad25893b2896b3c60e75d8f98456e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -59,7 +59,7 @@ python-install: config.mak sub-all
 
 python-install python-all: python/skytools/installer_config.py
 python/skytools/installer_config.py: python/skytools/installer_config.py.in config.mak
-       sed -e 's!@SQLDIR@!$(SQLDIR)!g' $< > $@
+       sed -e 's!@SQLDIR@!$(SQLDIR)!g' -e 's!@PACKAGE_VERSION@!$(PACKAGE_VERSION)!g' $< > $@
 
 realclean: distclean
        $(MAKE) -C doc $@
index 894c8c9830d3f7ccea05297a26ec24ace1602727..d105f635500ae5ef2cdd1ec5c346cef6d1cfbdb1 100644 (file)
@@ -36,3 +36,8 @@ INSTALL = @INSTALL@
 BININSTALL = @BININSTALL@
 
 
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PACKAGE_STRING = @PACKAGE_STRING@
+
index b958b483d3aa081223eeb7d9ae9f694a977d8065..03b18a04c2f2a03d7571a3e19364adfb2f4f5087 100644 (file)
@@ -35,3 +35,6 @@ __all__ = (skytools.psycopgwrapper.__all__
         + skytools.adminscript.__all__
         + skytools.parsing.__all__)
 
+import skytools.installer_config
+__version__ = skytools.installer_config.package_version
+
index a01621f7b71b333cf8ce136280c05eb499998294..2c684c1713a62defca4e2ab56ef07b2a9278ea30 100644 (file)
@@ -6,3 +6,6 @@ __all__ = ['sql_locations']
 sql_locations = [
     "@SQLDIR@",
 ]
+
+package_version = "@PACKAGE_VERSION@"
+
index 0d4b0fab17a34c60d3b3feb8dfe5bd43bbf21ed6..5740177351dea1324b5f7f28fd19dd182649ea0f 100644 (file)
@@ -325,6 +325,9 @@ class DBScript(object):
         self.options, self.args = parser.parse_args(args)
 
         # check args
+        if self.options.version:
+            self.print_version()
+            sys.exit(0)
         if self.options.daemon:
             self.go_daemon = 1
         if self.options.quiet:
@@ -353,6 +356,9 @@ class DBScript(object):
         elif self.options.cmd == "reload":
             self.send_signal(signal.SIGHUP)
 
+    def print_version(self):
+        print '%s, Skytools version %s' % (self.service_name, skytools.__version__)
+
     def print_ini(self):
         """Prints out ini file from doc string of the script of default for dbscript
         
@@ -431,6 +437,8 @@ class DBScript(object):
                      help = "log verbosely")
         p.add_option("-d", "--daemon", action="store_true",
                      help = "go background")
+        p.add_option("-V", "--version", action="store_true",
+                     help = "print version info and exit")
         p.add_option("", "--ini", action="store_true",
                     help = "display sample ini file")