mrmp/catalog.py
Marc Beninca 6afb15d260 package
2023-01-28 21:19:16 +01:00

32 lines
782 B
Python

import io
import os
import tarfile
import package
FILES = 'files'
PACKAGE = 'desc'
class Catalog:
def __init__(self, binary):
self.binary = binary
self.load()
def load(self):
f = io.BytesIO(self.binary)
archive = tarfile.open(fileobj=f)
m = {}
packages = {}
for member in archive.getmembers():
directory, *file = member.name.split(os.sep)
if file:
d = m[directory]
d[file[0]] = archive.extractfile(member).read()
if len(d) == 2:
p = package.Package(d[PACKAGE], d[FILES])
packages[p.name] = p
else:
m[directory] = {}
archive.close()
self.packages = packages