Commit 3919a689 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

better handle of software path checking

parent a1bc00e9
......@@ -16,6 +16,7 @@
#
import os
import sys
import inspect
import tempfile
......@@ -130,12 +131,35 @@ class Component(object):
def get_resource(self, resource):
return self.config_reader.get_resource(resource)
def __which(self, program):
"""
Return if the asked program exist in the user path
@param options : the options asked by the user
"""
import os
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)
fpath, fname = os.path.split(program)
if fpath:
if is_exe(program):
return program
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, program)
if is_exe(exe_file):
return exe_file
return None
def get_exec_path(self, software):
exec_path = self.config_reader.get_exec(software)
if exec_path is None and os.path.isfile(os.path.join(os.path.dirname(inspect.getfile(self.__class__)), "../bin", software)):
exec_path = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), "../bin", software)
elif exec_path is None and os.path.isfile(os.path.join(os.path.dirname(inspect.getfile(self.__class__)), "bin", software)):
exec_path = os.path.join(os.path.dirname(inspect.getfile(self.__class__)), "bin", software)
if exec_path is None: exec_path = software
if self.__which(exec_path) == None:
sys.stderr.write("Error: '" + software + "' connot be retrieved either in the PATH and in the application.properties file!\n")
sys.exit(1)
return exec_path
def get_nameid(self):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment