changeset 2:9e5c3f162eca draft

Needed to dereference links when searching for TRINITY_BASE_DIR.
author trinity_ctat
date Tue, 26 Sep 2017 11:34:17 -0400
parents b33e9252e6b4
children 32b6a47c9312
files trinityToolWrapper.py
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/trinityToolWrapper.py	Mon Sep 25 15:51:40 2017 -0400
+++ b/trinityToolWrapper.py	Tue Sep 26 11:34:17 2017 -0400
@@ -17,18 +17,25 @@
 if os.environ.has_key('TRINITY_HOME'):
     TRINITY_BASE_DIR = os.environ['TRINITY_HOME'];
 else:
-    # Cicada Dennis added looking for the location of the Trinity program using the unix "which" utility.
+    # 2017-09-26
+    # Cicada Dennis added looking for the location of the Trinity program using the Unix "which" utility.
     # I tried using "command -v Trinity" but for some reason, I was getting a OS permission error with that.
+    # I just found distutils.spawn.find_executable() which might work, but already implemented the below.
     try:
         pipe1 = subprocess.Popen(["which", "Trinity"], stdout=subprocess.PIPE)
     except:
         t, v, tb = sys.exc_info()
-        sys.stderr.write("You must set the environmental variable TRINITY_HOME to the base installation directory of Trinity before running this");
+        sys.stderr.write("You must set the environmental variable TRINITY_HOME to the base installation directory of Trinity before running {:s}.".format(sys.argv[0]);
         raise t, v, tb
     else:
-        output1, err1 = pipe1.communicate()
+        TrinityPath, err_info = pipe1.communicate()
+        # FIX - probably should be checking err_info for errors...
+        # Determine the TRINITY_BASE_DIR from output1.
+        # If TrinityPath is a link, we need to dereference the link.
+        while os.path.islink(TrinityPath)
+            TrinityPath = os.path.join(os.path.dirname(TrinityPath),os.readlink(TrinityPath))
         # Take off the last part of the path (which is the Trinity command)
-        TRINITY_BASE_DIR = "/".join(output1.split("/")[0:-1])
+        TRINITY_BASE_DIR = "/".join(TrinityPath.split("/")[0:-1])
 
 # get bindir
 bindir = sys.argv[0]