Exemple #1
0
def _download_and_process(meta_info: dict, process_func: Callable,
                          single_file_path, verbose):
    """

    :param meta_info:
    :param process_func:
    :param single_file_path:
    :param verbose:
    """
    if process_func is not None:

        _check_process_func(process_func)

        tmp_file_path = "/tmp/{}.tmp".format(random_string())

        _download_file(meta_info, tmp_file_path, verbose=verbose)

        process_func(tmp_file_path,
                     meta_info,
                     verbose=verbose,
                     clean_up_raw_data=True)

    else:
        # The model file will be downloaded directly to the single_file_path
        _download_file(meta_info, single_file_path, verbose=verbose)
Exemple #2
0
def _download_and_process(meta_info: dict, process_func: Callable,
                          single_file_path, verbose):
    """

    :param meta_info:
    :param process_func:
    :param single_file_path:
    :param verbose:
    """
    if process_func is not None:

        _check_process_func(process_func)

        tmp_file_path = "/tmp/{}.tmp".format(random_string())

        _download_file(meta_info, tmp_file_path, verbose=verbose)

        process_func(tmp_file_path,
                     meta_info,
                     verbose=verbose,
                     clean_up_raw_data=True)

    else:
        single_file = meta_info['name'] + meta_info['file_extension']
        _download_file(meta_info,
                       os.path.join(single_file_path, single_file),
                       verbose=verbose)
Exemple #3
0
def _extract_single_file_from_zip(cache_dir: str, file_in_zip: str, full_path, zip_file):
    # To not have name conflicts

    tmp_path = os.path.join(cache_dir, ''.join(random_string()))

    outpath = zip_file.extract(file_in_zip, path=tmp_path)
    os.rename(outpath, full_path)

    shutil.rmtree(tmp_path)