2021-10-09 23:18:03 +00:00
|
|
|
import os
|
|
|
|
|
2021-10-10 19:37:22 +00:00
|
|
|
CHARSET = 'u8'
|
2021-10-09 23:18:03 +00:00
|
|
|
KEY = '%'
|
|
|
|
SEPARATOR = f'{os.linesep}{os.linesep}'
|
|
|
|
|
|
|
|
|
2021-10-09 18:04:49 +00:00
|
|
|
class Package:
|
2021-10-09 23:18:03 +00:00
|
|
|
def __init__(self, package, files):
|
2021-10-09 23:27:34 +00:00
|
|
|
for binary in [package, files]:
|
2021-10-10 19:37:22 +00:00
|
|
|
text = binary.decode(CHARSET).strip()
|
2021-10-09 23:27:34 +00:00
|
|
|
for item in text.split(SEPARATOR):
|
|
|
|
line, *lines = item.split(os.linesep)
|
|
|
|
key = line.split(KEY)[1].lower()
|
|
|
|
if len(lines) == 1:
|
|
|
|
value = lines[0]
|
|
|
|
else:
|
|
|
|
value = lines
|
|
|
|
setattr(self, key, value)
|
2021-10-10 11:45:02 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
lines = [
|
2021-10-10 20:35:13 +00:00
|
|
|
f' Name: {self.name}',
|
|
|
|
f'FileName: {self.filename}',
|
|
|
|
f' Size: {self.csize}',
|
|
|
|
f' Hash: {self.sha256sum}',
|
2021-10-10 11:45:02 +00:00
|
|
|
]
|
|
|
|
return os.linesep.join(lines)
|