Commit d3a2fe14 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

better handle of software path checking

parent 3919a689
......@@ -16,7 +16,6 @@
#
import os
import sys
import inspect
import tempfile
......@@ -131,36 +130,8 @@ 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
return self.config_reader.get_exec(software)
def get_nameid(self):
return self.__class__.__name__ + "." + self.prefix
......
......@@ -16,6 +16,7 @@
#
import os
import sys
import inspect
from ConfigParser import ConfigParser, NoOptionError
......@@ -33,6 +34,25 @@ class JFlowConfigReader(object):
self.reader = ConfigParser()
self.reader.read(os.path.join(os.path.dirname(inspect.getfile(self.__class__)), self.CONFIG_FILE_PATH))
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_tmp_directory(self):
return self.reader.get("storage", "tmp_directory")
......@@ -41,9 +61,18 @@ class JFlowConfigReader(object):
def get_exec(self, software):
try:
return self.reader.get("softwares", software)
exec_path = self.reader.get("softwares", software)
except NoOptionError, e:
return None
exec_path = None
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_resource(self, resource):
return self.reader.get("resources", resource)
......
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