summaryrefslogtreecommitdiffstats
path: root/version.py
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 /version.py
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 'version.py')
-rw-r--r--version.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/version.py b/version.py
new file mode 100644
index 0000000..a4c7ed6
--- /dev/null
+++ b/version.py
@@ -0,0 +1,41 @@
+# -*- coding: utf-8 -*-
+# To use this script, simply import it your setup.py file, and use the
+# results of get_git_version() as your package version:
+#
+# from version import *
+#
+# setup(
+# version=get_git_version(),
+# .
+# .
+# .
+# )
+
+__all__ = ["get_git_version"]
+
+import os
+import re
+from subprocess import Popen, PIPE
+
+OWN_DIR = os.path.dirname(os.path.abspath(os.path.realpath(__file__)))
+
+def call_git_describe(abbrev=4):
+ try:
+ p = Popen(['git', 'describe', '--abbrev=%d' % abbrev, '--tags'],
+ cwd=OWN_DIR, stdout=PIPE, stderr=PIPE)
+ p.stderr.close()
+ line = p.stdout.readlines()[0]
+ return line.strip()
+
+ except:
+ return None
+
+def get_git_version(abbrev=4):
+ version = call_git_describe(abbrev)
+ if version is None:
+ raise ValueError("Cannot find the version number!")
+
+ return re.sub('^debian/', '', version)
+
+if __name__ == "__main__":
+ print get_git_version()