[py] incref exception type before restoring it
[aubio.git] / this_version.py
index 69d2f56..4e85914 100644 (file)
@@ -1,5 +1,6 @@
 #! python
 import os
+import sys
 
 __version_info = {} # keep a reference to parse VERSION once
 
@@ -81,17 +82,26 @@ def get_git_revision_hash(short=True):
     try:
         gitsha = subprocess.check_output(gitcmd).strip().decode('utf8')
     except Exception as e:
-        print('git command error :%s' % e)
+        sys.stderr.write('git command error :%s\n' % e)
         return None
     # check if we have a clean tree
-    gitcmd = ['git', '-C', aubio_dir, 'diff-index', '--quiet']
-    gitcmd.append('HEAD')
+    gitcmd = ['git', '-C', aubio_dir, 'status', '--porcelain']
     try:
-        subprocess.check_output(gitcmd).strip().decode('utf8')
-    except Exception as e:
-        gitsha += '+mods'
+        output = subprocess.check_output(gitcmd).decode('utf8')
+        if len(output):
+            sys.stderr.write('Info: current tree is not clean\n\n')
+            sys.stderr.write(output + '\n')
+            gitsha += '+mods'
+    except subprocess.CalledProcessError as e:
+        sys.stderr.write('git command error :%s\n' % e)
+        pass
     return gitsha
 
 if __name__ == '__main__':
-    print ('%30s'% 'aubio version:', get_aubio_version())
-    print ('%30s'% 'python-aubio version:', get_aubio_pyversion())
+    if len(sys.argv) > 1 and sys.argv[1] == '-v':
+        print (get_aubio_version())
+    elif len(sys.argv) > 1 and sys.argv[1] == '-p':
+        print (get_aubio_version())
+    else:
+        print ('%30s'% 'aubio version:', get_aubio_version())
+        print ('%30s'% 'python-aubio version:', get_aubio_pyversion())