def _is_file_path(script_command_with_whitespaces, working_directory): if script_command_with_whitespaces.startswith('"') \ or script_command_with_whitespaces.startswith("'"): return False file_exists = file_utils.exists(script_command_with_whitespaces, working_directory) if file_exists: LOGGER.warning('"%s" is a file with whitespaces' ', please wrap it with quotes to avoid ambiguity', script_command_with_whitespaces) return True return False
def _load_script_code_by_config(self, plain_config): script_path = plain_config.get(SCRIPT_PATH_FIELD) if is_blank(script_path): raise InvalidFileException('', 'Script path is not specified') command = process_utils.split_command( script_path, plain_config.get(WORKING_DIR_FIELD)) binary_files = [] for argument in command: if file_utils.exists(argument): if file_utils.is_binary(argument): binary_files.append(argument) continue return { 'code': file_utils.read_file(argument), 'file_path': argument } if binary_files: if len(binary_files) == 1: return { 'code': None, 'file_path': binary_files[0], 'code_edit_error': 'Cannot edit binary file' } raise InvalidFileException( 'command', 'Cannot choose which binary file to edit: ' + str(binary_files)) if len(command) == 1: return { 'code': None, 'file_path': command[0], 'code_edit_error': 'Script path does not exist' } raise InvalidFileException( 'command', 'Failed to find script path in command "' + script_path + '"')