Пример #1
0
def get_package_extracted_contents(
        file_system: FileSystem, package_path: str,
        extraction_path: str) -> Dict[str, List[str]]:
    contents = {
        'resources': [],
        'headers': [],
        'libraries': [],
        'libraries_interfaces': [],
        'symbols_tables': [],
        'executables': []
    }
    with file_system.open_tarfile(package_path, 'r:gz') as archive:
        for member in archive.getmembers():
            if member.isfile():
                extracted = False
                for root, files in contents.items():
                    if common_path(
                        [normalized_path(member.name),
                         normalized_path(root)]) == root:
                        files.append(join(extraction_path, member.name))
                        extracted = True
                if not extracted and member.name != 'Pralinefile':
                    raise InvalidPackageContentsError(
                        f"unrecognized file '{member.name}' in package")
    return contents
Пример #2
0
def unpack(file_system: FileSystem, package_path: str,
           extraction_path: str) -> Dict[str, List[str]]:
    contents = {
        'resources': [],
        'headers': [],
        'libraries': [],
        'libraries_interfaces': [],
        'symbols_tables': [],
        'executables': []
    }
    with file_system.open_tarfile(package_path, 'r:gz') as archive:
        for member in archive.getmembers():
            if member.isfile():
                extracted = False
                for root, files in contents.items():
                    if common_path(
                        [normalized_path(member.name),
                         normalized_path(root)]) == root:
                        archive.extract(member, extraction_path)
                        files.append(join(extraction_path, member.name))
                        extracted = True
                if not extracted and member.name != 'Pralinefile':
                    raise InvalidPackageContentsError(
                        f"unrecognized file '{member.name}' in package")
    for header in contents['headers']:
        with file_system.open_file(header, 'rb') as f:
            text = f.read().decode()
        with file_system.open_file(header, 'wb') as f:
            f.write(text.replace('PRALINE_EXPORT', 'PRALINE_IMPORT').encode())
    return contents
Пример #3
0
def hash_archive(file_system: FileSystem, archive_path: str):
    hasher = hashlib.sha3_256()
    with file_system.open_tarfile(archive_path, 'r:gz') as archive:
        for member in archive.getmembers():
            if member.isfile():
                hasher.update(member.name.encode('utf-8'))
                with archive.extractfile(member.name) as f:
                    for chunk in iter(lambda: f.read(4096), b''):
                        hasher.update(chunk)
    return hasher.hexdigest()
Пример #4
0
def pack(file_system: FileSystem, package_path: str,
         package_files: List[Tuple[str, str]], cache: Dict[str, Any]):
    hasher = lambda p: hash_file(file_system, p)
    updated, removed, new_cache = key_delta([p for p, _ in package_files],
                                            hasher, cache)
    if updated or removed or not file_system.exists(package_path):
        with file_system.open_tarfile(package_path, 'w:gz') as archive:
            for file_path, package_file_path in package_files:
                archive.add(file_path, package_file_path)
    cache.clear()
    cache.update(new_cache)
Пример #5
0
def get_package_dependencies_from_archive(file_system: FileSystem,
                                          package_path: str,
                                          scope: str) -> List[str]:
    with file_system.open_tarfile(package_path, 'r:gz') as archive:
        with archive.extractfile('Pralinefile') as reader:
            pralinefile = pralinefile_from_reader(reader, skip_validation=True)
    package = get_package_metadata(package_path)
    package_dependencies = []
    for dependency in pralinefile['dependencies']:
        if dependency['scope'] == scope:
            package_dependency = get_package(
                dependency['organization'], dependency['artifact'],
                package['architecture'], package['platform'],
                package['compiler'], package['mode'], dependency['version'])
            package_dependencies.append(package_dependency)
    return package_dependencies