validate: Determine development mode using git hash value
authorYoung Han Lee <joybro201@gmail.com>
Thu, 19 Feb 2015 11:53:16 +0000 (20:53 +0900)
committerThibault Saunier <tsaunier@gnome.org>
Thu, 19 Feb 2015 12:57:30 +0000 (13:57 +0100)
Development mode has been determined by whether the launcher is in git
repo
or not. This could be wrong when the launcher is installed to
subdirectory of other project's git repo, such as jhbuild. It is normal
to install compiled output to subdirectory of your jhbuild.

Changed logic gets the first commit hash of current git repo and
compares it with gst-devtools' the first commit hash.

https://bugzilla.gnome.org/show_bug.cgi?id=744781

validate/tools/gst-validate-launcher.in

index 4e487cc..6d9e062 100644 (file)
 # Boston, MA 02110-1301, USA.
 
 import os
+import subprocess
 import sys
 
 LIBDIR = '@LIBDIR@'
+GIT_FIRST_HASH = 'da962d096af9460502843e41b7d25fdece7ff1c2'
+
+
+def _get_git_first_hash(path):
+    try:
+      return subprocess.check_output(['git', '-C', path, 'rev-list', '--max-parents=0', 'HEAD']).rstrip('\n')
+    except subprocess.CalledProcessError:
+      return ''
 
 
 def _in_devel():
     root_dir = os.path.abspath(os.path.dirname(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                                             "..", "..", "..")))
-    return os.path.exists(os.path.join(root_dir, '.git'))
+    return _get_git_first_hash(root_dir) == GIT_FIRST_HASH
 
 
 def _add_gst_launcher_path():
     if not _in_devel():
         root = os.path.join(LIBDIR, 'gst-validate-launcher', 'python')
     else:
+        print "Running with development path"
         dir_ = os.path.dirname(os.path.abspath(__file__))
         root = os.path.split(dir_)[0]