def find_file_type_from_file_name(file_name, action): """ Extract file type from file name """ print(file_name) if action == "read": list_of_file_types = PARSER.get_all_file_types() else: list_of_file_types = RENDERER.get_all_file_types() print(list_of_file_types) file_types = [] lowercase_file_name = file_name.lower() for a_supported_type in list_of_file_types: if lowercase_file_name.endswith(a_supported_type): file_types.append(a_supported_type) if len(file_types) > 1: file_types = sorted(file_types, key=len) file_type = file_types[-1] elif len(file_types) == 1: file_type = file_types[0] else: file_type = lowercase_file_name.split(".")[-1] raise FileTypeNotSupported(constants.FILE_TYPE_NOT_SUPPORTED_FMT % (file_type, action)) return file_type
def can_i_handle(self, action, file_type): if action == constants.WRITE_ACTION: status = file_type.lower() in tuple( RENDERER.get_all_file_types()) else: status = False return status
def find_file_type_from_file_name(file_name, action): """ Extract file type from file name """ if action == 'read': list_of_file_types = PARSER.get_all_file_types() else: list_of_file_types = RENDERER.get_all_file_types() file_types = [] lowercase_file_name = file_name.lower() for a_supported_type in list_of_file_types: if lowercase_file_name.endswith(a_supported_type): file_types.append(a_supported_type) if len(file_types) > 1: file_types = sorted(file_types, key=len) file_type = file_types[-1] elif len(file_types) == 1: file_type = file_types[0] else: file_type = lowercase_file_name.split('.')[-1] raise FileTypeNotSupported( constants.FILE_TYPE_NOT_SUPPORTED_FMT % (file_type, action)) return file_type
def can_i_handle(self, action, file_type): if action == constants.WRITE_ACTION: status = file_type.lower() in tuple(RENDERER.get_all_file_types()) else: status = False return status