Exemplo n.º 1
0
def create_asset_archive(name, version):
    """Used to make archives of file or dir. Zip on windows and tar.gz
    on all other platforms

    Args:
        name - Name to rename binary.

        version - Version of app. Used to create archive filename

    Returns:
         (str) - name of archive
    """
    file_dir = os.path.dirname(os.path.abspath(name))
    filename = '{}-{}-{}'.format(
        os.path.splitext(name)[0], system.get_system(), version)

    # Only use zip on windows.
    # Zip does not preserve file permissions on nix & mac
    with paths.ChDir(file_dir):
        if system.get_system() == 'win':
            ext = '.zip'
            with zipfile.ZipFile(filename + ext, 'w') as zf:
                zf.write(name, name)
        else:
            ext = '.tar.gz'
            with paths.ChDir(file_dir):
                with tarfile.open(filename + ext, 'w:gz',
                                  compresslevel=0) as tar:
                    tar.add(name, name)

    output_filename = filename + ext
    log.debug('Archive output filename: %s', output_filename)
    return output_filename
Exemplo n.º 2
0
def make_archive(name, target, version):
    """Used to make archives of file or dir. Zip on windows and tar.gz
    on all other platforms

    Args:
        name - Name to rename binary.

        version - Version of app. Used to create archive filename

        target - Name of file to archive.

    Returns:
         (str) - name of archive
    """
    log.debug('starting archive')
    ext = os.path.splitext(target)[1]
    temp_file = name + ext
    log.debug('Temp file: %s', temp_file)
    # Remove file if it exists. Found during testing...
    if os.path.exists(temp_file):
        paths.remove_any(temp_file)

    if os.path.isfile(target):
        shutil.copy(target, temp_file)
    else:
        shutil.copytree(target, temp_file)
        # renames the entry-point executable
        file_ext = '.exe' if system.get_system() == 'win' else ''
        src_executable = temp_file + os.sep + target + file_ext
        dst_executable = temp_file + os.sep + name + file_ext
        # is an osx bundle app so does not need to fix the executable name
        if ext != '.app':
            shutil.move(src_executable, dst_executable)

        # is a win folder so the manifest need to be renamed too
        if system.get_system() == 'win':
            src_manifest = src_executable + '.manifest'
            dst_manifest = dst_executable + '.manifest'
            shutil.move(src_manifest, dst_manifest)

    file_dir = os.path.dirname(os.path.abspath(target))
    filename = '{}-{}-{}'.format(
        os.path.splitext(name)[0], system.get_system(), version)
    # Only use zip on windows.
    # Zip does not preserve file permissions on nix & mac
    # tar.gz creates full file path
    with paths.ChDir(file_dir):
        ext = 'gztar'
        if system.get_system() == 'win':
            ext = 'zip'
        output_filename = shutil.make_archive(filename, ext, file_dir,
                                              temp_file)

    if os.path.exists(temp_file):
        paths.remove_any(temp_file)

    log.debug('Archive output filename: %s', output_filename)
    return output_filename
Exemplo n.º 3
0
def make_archive(name, target, version):
    """Used to make archives of file or dir. Zip on windows and tar.gz
    on all other platforms

    Args:
        name - Name to rename binary.

        version - Version of app. Used to create archive filename

        target - Name of file to archive.

    Returns:
         (str) - name of archive
    """
    log.debug('starting archive')
    ext = os.path.splitext(target)[1]
    temp_file = name + ext
    log.debug('Temp file: %s', temp_file)
    # Remove file if it exists. Found during testing...
    if os.path.exists(temp_file):
        paths.remove_any(temp_file)

    if os.path.isfile(target):
        shutil.copy(target, temp_file)
    else:
        shutil.copytree(target, temp_file)

    file_dir = os.path.dirname(os.path.abspath(target))
    filename = '{}-{}-{}'.format(os.path.splitext(name)[0],
                                 system.get_system(), version)

    # Only use zip on windows.
    # Zip doens't preserve file permissions on nix & mac
    # tar.gz creates full file path
    with paths.ChDir(file_dir):
        if system.get_system() == 'win':
            ext = '.zip'
            with zipfile.ZipFile(filename + ext, 'w') as zf:
                zf.write(target, temp_file)
        else:
            ext = '.tar.gz'
            with tarfile.open(filename + ext, 'w:gz',
                              compresslevel=0) as tar:
                tar.add(target, temp_file)

    if os.path.exists(temp_file):
        paths.remove_any(temp_file)

    output_filename = filename + ext
    log.debug('Archive output filename: %s', output_filename)
    return output_filename