Esempio n. 1
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
Esempio n. 2
0
def pralinefile_from_path(file_system : FileSystem, path: str, skip_validation=False) -> Dict[str, Any]:
    with file_system.open_file(path, 'r') as reader:
        return pralinefile_from_reader(reader)
Esempio n. 3
0
def hash_file(file_system: FileSystem, file_path: str) -> str:
    hasher = hashlib.sha3_256()
    with file_system.open_file(file_path, 'rb') as f:
        for chunk in iter(lambda: f.read(4096), b''):
            hasher.update(chunk)
    return hasher.hexdigest()