Exemple #1
0
def update_files_file(temp_dir, verbose):
    """Update the source package's 'files' file.

    The file path to each file that will be in the target archive is
    written to the 'files' file.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    verbose (bool) -- show output of items that are updated
    """
    files_file = os.path.join(temp_dir, 'info/files')

    with open(files_file, 'w') as files:
        file_paths = []
        for dirpath, dirnames, filenames in walk(temp_dir):
            relative_dir = os.path.relpath(dirpath, temp_dir)
            filenames = [os.path.join(relative_dir, f) for f in filenames]
            for filename in filter_info_files(filenames, ''):
                file_paths.append(
                    filename.replace('\\', '/').replace('\\\\', '/'))
                if verbose:
                    print('Updating {}'.format(filename))

        for file_path in sorted(file_paths):
            files.write(file_path + '\n')
Exemple #2
0
def update_files_file(temp_dir, verbose):
    """Update the source package's 'files' file.

    The file path to each file that will be in the target archive is
    written to the 'files' file.

    Positional arguments:
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    verbose (bool) -- show output of items that are updated
    """
    files_file = os.path.join(temp_dir, 'info/files')

    with open(files_file, 'w') as files:
        file_paths = []
        for dirpath, dirnames, filenames in walk(temp_dir):
            relative_dir = os.path.relpath(dirpath, temp_dir)
            filenames = [os.path.join(relative_dir, f) for f in filenames]
            for filename in filter_info_files(filenames, ''):
                file_paths.append(filename.replace('\\', '/').replace('\\\\', '/'))
                if verbose:
                    print('Updating {}' .format(filename))

        for file_path in sorted(file_paths):
            files.write(file_path + '\n')
Exemple #3
0
def _load_all_json(path):
    """
    Load all json files in a directory.  Return dictionary with filenames mapped to json
    dictionaries.
    """
    root, _, files = next(utils.walk(path))
    result = {}
    for f in files:
        if f.endswith('.json'):
            result[f] = _load_json(join(root, f))
    return result
Exemple #4
0
def _load_all_json(path):
    """
    Load all json files in a directory.  Return dictionary with filenames mapped to json
    dictionaries.
    """
    root, _, files = next(utils.walk(path))
    result = {}
    for f in files:
        if f.endswith('.json'):
            result[f] = _load_json(join(root, f))
    return result
Exemple #5
0
def create_target_archive(file_path, temp_dir, platform, output_dir):
    """Create the converted package's tar file.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    platform (str) -- the platform to convert to: 'win-64', 'win-32', 'linux-64',
        'linux-32', or 'osx-64'
    """
    output_directory = os.path.join(output_dir, platform)

    if not os.path.isdir(output_directory):
        os.makedirs(output_directory)

    destination = os.path.join(output_directory, os.path.basename(file_path))

    with tarfile.open(destination, 'w:bz2') as target:
        for dirpath, dirnames, filenames in walk(temp_dir):
            relative_dir = os.path.relpath(dirpath, temp_dir)
            filenames = [os.path.join(relative_dir, f) for f in filenames]
            for filename in filenames:
                target.add(os.path.join(temp_dir, filename), arcname=filename)
Exemple #6
0
def create_target_archive(file_path, temp_dir, platform, output_dir):
    """Create the converted package's tar file.

    Positional arguments:
    file_path (str) -- the file path to the source package's tar file
    temp_dir (str) -- the file path to the temporary directory containing the source
        package's extracted contents
    platform (str) -- the platform to convert to: 'win-64', 'win-32', 'linux-64',
        'linux-32', or 'osx-64'
    """
    output_directory = os.path.join(output_dir, platform)

    if not os.path.isdir(output_directory):
        os.makedirs(output_directory)

    destination = os.path.join(output_directory, os.path.basename(file_path))

    with tarfile.open(destination, 'w:bz2') as target:
        for dirpath, dirnames, filenames in walk(temp_dir):
            relative_dir = os.path.relpath(dirpath, temp_dir)
            filenames = [os.path.join(relative_dir, f) for f in filenames]
            for filename in filenames:
                target.add(os.path.join(temp_dir, filename), arcname=filename)