summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2013-06-05 19:27:03 +0200
committerAlexander Sulfrian <alexander@sulfrian.net>2013-06-05 20:04:29 +0200
commit149dcbae2d12587fb687b81e3a1a4631f04db4d7 (patch)
tree95633022329108c836363148ef95df4cadeab109 /bin
parentf77799678c6132f6a8db16faa2f9c72771c017f3 (diff)
downloadtools-149dcbae2d12587fb687b81e3a1a4631f04db4d7.tar.gz
tools-149dcbae2d12587fb687b81e3a1a4631f04db4d7.tar.bz2
tools-149dcbae2d12587fb687b81e3a1a4631f04db4d7.zip
hostinfo: add -V and --version to get the version0.2.0
The version is generated from the git-tags during build (setup.py) or during run time, if executed from the git repository.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/hostinfo20
1 files changed, 20 insertions, 0 deletions
diff --git a/bin/hostinfo b/bin/hostinfo
index f1453e9..8700be7 100755
--- a/bin/hostinfo
+++ b/bin/hostinfo
@@ -5,6 +5,7 @@ import sys
import argparse
import yaml
import os
+import pkg_resources
from dns import resolver, reversename
OWN_DIRECTORY = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
@@ -190,6 +191,20 @@ def find_host(basepath, host):
return None
+def print_version_and_exit():
+ ver = None
+ try:
+ import version
+ ver = version.get_git_version()
+ except:
+ ver = pkg_resources.require("hostinfo-tools")[0].version
+
+ if ver is None:
+ sys.stderr.write('Unable to identify the version information.')
+ sys.exit(1)
+ print("hostinfo-tools %s" % ver)
+ sys.exit(0)
+
def main():
basepath = '/usr/local/share/hostinfo'
if 'HOSTINFO_PATH' in os.environ and os.environ['HOSTINFO_PATH'] != '':
@@ -220,8 +235,13 @@ def main():
help="only print the hostname of the matching entries")
parser.add_argument("-d", "--details", action="store_true",
help="print details about matching hosts")
+ parser.add_argument("-V", "--version", action="store_true",
+ help="only print the version number and exit")
args = parser.parse_args()
+ if args.version:
+ print_version_and_exit()
+
if args.path:
basepath = args.path