Exemplo n.º 1
0
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
Exemplo n.º 2
0
 def can_i_handle(self, action, file_type):
     __file_type = None
     if file_type:
         __file_type = file_type.lower()
     if action == constants.READ_ACTION:
         status = __file_type in PARSER.get_all_file_types()
     else:
         status = False
     return status
Exemplo n.º 3
0
 def can_i_handle(self, action, file_type):
     __file_type = None
     if file_type:
         __file_type = file_type.lower()
     if action == constants.READ_ACTION:
         status = __file_type in PARSER.get_all_file_types()
     else:
         status = False
     return status
Exemplo n.º 4
0
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