def is_valid_cmd_args(self, cmd_arg_string): """ Given a yap command argument string, if enable is set to yes, validates the command arguments Returns true if it is valid,a warning message if a basename is found in one of the arguments, false otherwise. If enable is set to no, returns true A command argument is valid if all paths or basenames contained in it exist in system """ if self.enable != "yes": return True # True is default when disabled # strip starting and trailing spaces cmd_arg_string = cmd_arg_string.strip() if len(cmd_arg_string) <= 0: return True # return True if empty string # find all file names and paths in argument string path_ops = yap_path_checks() cmd_arg_items = path_ops.extract_files_and_paths(cmd_arg_string) # return True if no files/paths in command arguments if len(cmd_arg_items) <= 0: return True # check if all files and paths exist in command argument return self.is_valid_cmd_paths( cmd_arg_items, path_ops.valid_path_or_link, path_ops.basename_exists)
def is_valid_cmd_args(self, cmd_arg_string): """ Given a yap command argument string, if enable is set to yes, validates the command arguments Returns true if it is valid,a warning message if a basename is found in one of the arguments, false otherwise. If enable is set to no, returns true A command argument is valid if all paths or basenames contained in it exist in system """ if self.enable != "yes": return True # True is default when disabled # strip starting and trailing spaces cmd_arg_string = cmd_arg_string.strip() if len(cmd_arg_string) <= 0: return True # return True if empty string # find all file names and paths in argument string path_ops = yap_path_checks() cmd_arg_items = path_ops.extract_files_and_paths(cmd_arg_string) # return True if no files/paths in command arguments if len(cmd_arg_items) <= 0: return True # check if all files and paths exist in command argument return self.is_valid_cmd_paths(cmd_arg_items, path_ops.valid_path_or_link, path_ops.basename_exists)
def check_files_when_postproc_only( self, postprocess_cmd_arr, input_files_path): """ When run postprocess alone, check if needed file of given input_file_type exists in given input_directory. """ path_check = yap_path_checks() # new object of yap_path_checks for post_cmd in postprocess_cmd_arr: # each command in postprocess file_info = post_cmd[1] command_name = post_cmd[2][0][0] found = 'not check' # file_info e.g.: # ['input_file_type *queryname*.sam', # 'input_directory aligner_output'] for info in file_info: # get input_file_type and input_directory if info.startswith("input_file_type"): l = len('input_file_type') input_file_type = info[l:].strip() if info.startswith("input_directory"): l = len("input_directory") input_directory = info[l:].strip() if input_directory == 'aligner_output': # when the input_directory is 'aligner_output', # check if the required input_file_type # exists in the input_directory input_directory = input_files_path.split(';') found = \ path_check.file_or_basename_exist_in_any( input_directory, input_file_type) if found == 'files_found' or found == 'not check': pass elif found == 'basename found': warning_string = "Warning: basename found " + \ "instead of filename in " + \ " input file type. Please" + \ " make sure that command '" + \ command_name + "' can work with" + \ "basenames." self.warning_list.append(warning_string) elif found == 'not found': self.error_list.append("Error: required file " + input_file_type + " not exists" + " in aligner_output directory.")
def check_files_when_postproc_only(self, postprocess_cmd_arr, input_files_path): """ When run postprocess alone, check if needed file of given input_file_type exists in given input_directory. """ path_check = yap_path_checks() # new object of yap_path_checks for post_cmd in postprocess_cmd_arr: # each command in postprocess file_info = post_cmd[1] command_name = post_cmd[2][0][0] found = 'not check' # file_info e.g.: # ['input_file_type *queryname*.sam', # 'input_directory aligner_output'] for info in file_info: # get input_file_type and input_directory if info.startswith("input_file_type"): l = len('input_file_type') input_file_type = info[l:].strip() if info.startswith("input_directory"): l = len("input_directory") input_directory = info[l:].strip() if input_directory == 'aligner_output': # when the input_directory is 'aligner_output', # check if the required input_file_type # exists in the input_directory input_directory = input_files_path.split(';') found = \ path_check.file_or_basename_exist_in_any( input_directory, input_file_type) if found == 'files_found' or found == 'not check': pass elif found == 'basename found': warning_string = "Warning: basename found " + \ "instead of filename in " + \ " input file type. Please" + \ " make sure that command '" + \ command_name + "' can work with" + \ "basenames." self.warning_list.append(warning_string) elif found == 'not found': self.error_list.append("Error: required file " + input_file_type + " not exists" + " in aligner_output directory.")
def check_exe(self, command): """ Given a command string, Retuns true if command is executable, false otherwise """ # expand environment variables in command command = os.path.expandvars(command) if command in self.exceptions_list: return True # true for all exceptions # find path of the given command exectuable find_exe_result = distutils.spawn.find_executable(command) if find_exe_result is None: return False # not an executable # check if executable path exists (applies only when full path is # given) path_checker = yap_path_checks() if path_checker.valid_path_or_link(find_exe_result): # return true if execute is set on executable file return os.access(find_exe_result, os.X_OK) else: return False # return false if executable does not exist