Esempio n. 1
0
def _introspect_licenses(destination_folder,
                         root_introspection,
                         extra_licenses_check=None):
    """Generate archive with 3rd party licenses"""
    print("- Introspecting for dependencies..." + str(root_introspection))

    try:
        locale.getdefaultlocale()
    except Exception:
        os.environ['LANG'] = 'en_US.UTF-8'
        os.environ['LC_ALL'] = 'en_US.UTF-8'

    zip_name = generate_artefact(root_introspection,
                                 extra_licenses_check=extra_licenses_check)
    ZipFile(zip_name).extractall(destination_folder)
    os.remove(zip_name)
    print("- Dependencies archive with licenses done.")
def prepare_anaconda_dist(config):
    """
    Main method for building from Anaconda (This requires TVB_Distribution - step1 ZIP to have been generated before
    """
    _log(0,
         "Generating ANACONDA-based TVB_Distribution! " + config.platform_name)

    _log(1, "Removing old artifacts")
    for ar in glob.glob(config.artifact_glob):
        os.remove(ar)
    shutil.rmtree(config.target_root, True)

    _log(
        1, "Decompressing " + config.step1_result + " into '" +
        config.target_root + "' ...")
    zipfile.ZipFile(config.step1_result).extractall(config.target_root)

    # make needed directory structure that is not in the step1 zip
    # bin dir is initially empty, step1 does not support empty dirs in the zip
    os.mkdir(join(config.target_root, 'bin'))

    _log(
        1, "Copying anaconda ENV folder" + config.anaconda_env_path +
        " into '" + config.target_library_root + "'...")
    shutil.copytree(config.anaconda_env_path, config.target_library_root)

    _log(1, "Copying TVB sources into site-packages ...")
    _copy_collapsed(config)

    demo_data_src = join(config.target_root, "_tvb_data")
    demo_data_dst = join(config.target_site_packages, "tvb_data")
    _log(2, "Moving " + demo_data_src + " to " + demo_data_dst)
    os.rename(demo_data_src, demo_data_dst)

    online_help_src = join(config.target_root, "_help")
    online_help_dst = join(config.target_site_packages, "tvb", "interfaces",
                           "web", "static", "help")
    _log(2, "Moving " + online_help_src + " to " + online_help_dst)
    os.rename(online_help_src, online_help_dst)

    _log(1, "Modifying PTH " + config.easy_install_pth)
    _modify_pth(config.easy_install_pth)

    _log(1, "Creating command files:")
    for target_file, content in config.commands_map.items():
        config.command_factory(join(config.target_root, target_file), content)

    _log(1, "Introspecting 3rd party licenses...")
    zip_name = generate_artefact(
        config.target_site_packages,
        extra_licenses_check=config.to_read_licenses_from)
    zipfile.ZipFile(zip_name).extractall(config.target_3rd_licences_folder)
    os.remove(zip_name)

    _log(1, "Packing final ZIP...")
    if os.path.exists(config.target_before_zip):
        shutil.rmtree(config.target_before_zip, True)
    os.mkdir(config.target_before_zip)
    shutil.move(config.target_root, config.target_before_zip)
    _compress(config.target_before_zip, config.artifact_pth)
    shutil.rmtree(config.target_before_zip, True)
    _log(1, "Done TVB package " + config.artifact_pth)