Author: bugman Date: Thu Feb 7 11:09:56 2008 New Revision: 4917 URL: http://svn.gna.org/viewcvs/relax?rev=4917&view=rev Log: Converted the test_binary() method into a module function. Modified: 1.3/relax_io.py Modified: 1.3/relax_io.py URL: http://svn.gna.org/viewcvs/relax/1.3/relax_io.py?rev=4917&r1=4916&r2=4917&view=diff ============================================================================== --- 1.3/relax_io.py (original) +++ 1.3/relax_io.py Thu Feb 7 11:09:56 2008 @@ -384,6 +384,46 @@ return new +def test_binary(binary): + """Function for testing that the binary string corresponds to a valid executable file. + + @param binary: The name or path of the binary executable file. + @type binary: str + """ + + # 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 + + @@ -495,42 +535,6 @@ 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): """Class for splitting an IO stream to two outputs."""