Пример #1
0
def load_name_list(file_obj, source='local'):
    """ Just the file names, and we'll look up the rest"""

    ret = []
    warnings = []

    rl = file_obj.readlines()

    # clean up the filenames
    for i, filename in enumerate(rl):
        filename = filename.strip()
        if filename.startswith('File:'):
            filename = filename[5:]
        rl[i] = filename

    edicts = []

    if source == 'remote':
        edicts, warnings = get_by_filename_remote(rl)
    else:
        for filename in rl:
            file_info = get_file_info(filename)
            if file_info is not None:
                edict, warnings = file_info
                edicts.append(edict)

    for edict in edicts:
        try:
            entry = make_entry(edict)
        except TypeError as e:
            warnings.append((edict, e))
        else:
            ret.append(entry)

    return ret, warnings
Пример #2
0
def get_files_info_by_name(request_dict):
    try:
        file_names = request_dict['names']
    except Exception:
        raise InvalidAction('must provide a list of names')
    files = []
    for file_name in file_names:
        file_info = get_file_info(file_name)
        files.append(file_info)
    return {'file_infos': files}
Пример #3
0
def load_by_filename(filenames, source='local'):
    ret = []
    if source == 'remote':
        files, warnings = get_by_filename_remote(filenames)
    else:
        files = []
        for filename in filenames:
            file_info = get_file_info(filename)
            files.append(file_info)
    for edict in files:
        entry = make_entry(edict)
        ret.append(entry)
    return ret
Пример #4
0
def load_by_filename(filenames, source='local'):
    entries = []
    warnings = []
    if source == 'remote':
        files, warnings = get_by_filename_remote(filenames)
    else:
        files = []
        for filename in filenames:
            file_info = get_file_info(filename)
            if file_info is not None:
                files.append(file_info)
            else:
                warnings.append(
                    'file "%s" does not exist, please check that its name is spelled correctly, '
                    'that it has not been renamed or removed' % (filename, ))
    for edict in files:
        entry = make_entry(edict)
        entries.append(entry)
    return entries, warnings