[prev in list] [next in list] [prev in thread] [next in thread] 

List:       relax-commits
Subject:    r2589 - in /1.2: errors.py generic_fns/palmer.py io.py
From:       edward () domain ! hid
Date:       2006-09-30 13:35:17
Message-ID: E1GTezt-0006Fn-V8 () domain ! hid
[Download RAW message or body]

Author: bugman
Date: Sat Sep 30 15:35:17 2006
New Revision: 2589

URL: http://svn.gna.org/viewcvs/relax?rev=2589&view=rev
Log:
Fix to bug #7225.

This bug was reported by Alex Hansen at https://gna.org/bugs/index.php?7225.

To enable comprehensible error messages when attempting to execute Modelfree4, the \
function 'self.test_binary()' was added to the file 'io.py'.  This was described in \
the post located at https://mail.gna.org/public/relax-devel/2006-09/msg00034.html \
(Message-id: <7f080ed10609280917s139d2c2cm9f0edcbd5a9fc04c@domain.hid>).  The \
implementation is slightly different to the post though.  Firstly the supplied string \
corresponding to the binary is tested to see if the full path has been supplied.  If \
so then the string is tested to see if the file exists and if the file is executable. \
Otherwise the file is searched for in the PATH environmental variable.  Point 5 of \
the post at https://mail.gna.org/public/relax-devel/2006-09/msg00034.html, testing \
that the binary is in the current directory was not implemented.  The reason is \
because I was unable to successfully modify the PATH variable.

Three new RelaxErrors have been created to print out comprehensible messages:
RelaxMissingBinaryError, RelaxNonExecError, and RelaxNoInPathError.


Modified:
    1.2/errors.py
    1.2/generic_fns/palmer.py
    1.2/io.py

Modified: 1.2/errors.py
URL: http://svn.gna.org/viewcvs/relax/1.2/errors.py?rev=2589&r1=2588&r2=2589&view=diff
 ==============================================================================
--- 1.2/errors.py (original)
+++ 1.2/errors.py Sat Sep 30 15:35:17 2006
@@ -103,6 +103,31 @@
             if Debug:
                 self.save_state()
 
+
+    # The binary executable file does not exist (full path has been given!).
+    class RelaxMissingBinaryError(BaseError):
+        def __init__(self, name):
+            self.text = "The binary executable file " + `name` + " does not exist."
+            if Debug:
+                self.save_state()
+
+
+    # The binary executable file is not executable.
+    class RelaxNonExecError(BaseError):
+        def __init__(self, name):
+            self.text = "The binary executable file " + `name` + " is not \
executable." +            if Debug:
+                self.save_state()
+
+
+    # The binary executable file is not located within the system path.
+    class RelaxNoInPathError(BaseError):
+        def __init__(self, name):
+            self.text = "The binary executable file " + `name` + " is not located \
within the system path." +            if Debug:
+                self.save_state()
+
+
     # Program execution failure.
     class RelaxProgFailError(BaseError):
         def __init__(self, name):

Modified: 1.2/generic_fns/palmer.py
URL: http://svn.gna.org/viewcvs/relax/1.2/generic_fns/palmer.py?rev=2589&r1=2588&r2=2589&view=diff
 ==============================================================================
--- 1.2/generic_fns/palmer.py (original)
+++ 1.2/generic_fns/palmer.py Sat Sep 30 15:35:17 2006
@@ -456,6 +456,9 @@
                     if search('out$', file) or search('rotate$', file):
                         remove(file)
 
+            # Test the binary file string corresponds to a valid executable.
+            self.relax.IO.test_binary(self.binary)
+
             # Execute Modelfree4 (inputting a PDB file).
             if pdb:
                 status = spawnlp(P_WAIT, self.binary, self.binary, '-i', 'mfin', \
'-d', 'mfdata', '-p', 'mfpar', '-m', 'mfmodel', '-o', 'mfout', '-e', 'out', '-s', \
pdb)

Modified: 1.2/io.py
URL: http://svn.gna.org/viewcvs/relax/1.2/io.py?rev=2589&r1=2588&r2=2589&view=diff
==============================================================================
--- 1.2/io.py (original)
+++ 1.2/io.py Sat Sep 30 15:35:17 2006
@@ -1,6 +1,6 @@
 ###############################################################################
 #                                                                             #
-# Copyright (C) 2003-2005 Edward d'Auvergne                                   #
+# Copyright (C) 2003-2006 Edward d'Auvergne                                   #
 #                                                                             #
 # This file is part of the program relax.                                     #
 #                                                                             #
@@ -41,7 +41,7 @@
     __builtin__.devnull_import = 0
     __builtin__.devnull_import_message = message.args[0]
 
-from os import F_OK, access, makedirs, remove, stat
+from os import F_OK, X_OK, access, altsep, getenv, makedirs, pathsep, remove, sep, \
stat  from os.path import expanduser
 from re import match, search
 from string import split
@@ -363,6 +363,41 @@
         sys.stderr = self.tee_stderr
 
 
+    def test_binary(self, binary):
+        """Function for testing that the binary string corresponds to a valid \
executable file.""" +
+        # Path separator RE string.
+        if altsep:
+            path_sep = '[' + sep + altsep + ']'
+        else:
+            path_sep = sep
+
+        # The full path of the program has been given (if a directory separatory has \
been supplied). +        if search(path_sep, binary):
+            # Test that the binary exists.
+            if not access(binary, F_OK):
+                raise RelaxMissingBinaryError, binary
+
+            # Test that if the binary is executable.
+            if not access(binary, X_OK):
+                raise RelaxNonExecError, binary
+
+        # The path to the binary has not been given.
+        else:
+            # Get the PATH environmental variable.
+            path = getenv('PATH')
+
+            # Split PATH by the path separator.
+            path_list = split(path, pathsep)
+
+            # Test that the binary exists within the system path (and exit this \
function instantly once it has been found). +            for path in path_list:
+                if access(path + sep + binary, F_OK):
+                    return
+
+            # The binary is not located in the system path!
+            raise RelaxNoInPathError, binary
+
 
 class SplitIO:
     def __init__(self):


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic