packager/bodge-pkg.py

31 lines
1.3 KiB
Python
Raw Normal View History

import os
import tarfile
2023-07-13 16:50:49 +02:00
with open("./package.toml", mode='r') as mani:
data = mani.read()
2023-07-13 22:47:19 +02:00
with open("./sample.pkg", mode='wb') as pkg:
2023-07-13 16:50:49 +02:00
print("building header...")
pkg.write(bytes([0x01, (len(data) >> 8) & 0xFF, len(data) & 0xFF]))
print("writing manifest into pkg...")
pkg.write(data.encode("utf-8"))
with tarfile.TarFile("/tmp/pkgtar", 'w') as pkgtar:
2023-07-13 22:47:19 +02:00
print("tarring ./pkg...")
os.chdir("pkg")
2023-07-13 16:50:49 +02:00
for root, dirs, files in os.walk("."):
for file in files:
2023-07-13 22:47:19 +02:00
print(f"\33[2Kadd: {os.path.join(root, file)}", end="\r", flush=True)
2023-07-13 16:50:49 +02:00
pkgtar.add(os.path.join(root, file))
2023-07-13 22:47:19 +02:00
os.chdir("..")
for root, dirs, files in os.walk("pkgr"):
for file in files:
print(f"\33[2Kadd: {os.path.join(root, file)}", end="\r", flush=True)
pkgtar.add(os.path.join(root, file))
print("\33[2K", end="\r", flush=True)
2023-07-13 16:50:49 +02:00
with open("/tmp/pkgtar", 'rb') as pkgtar:
print("appending pkgtar to pkg...")
pkg.write(pkgtar.read())
print("deleting /tmp/pkgtar...")
os.unlink("/tmp/pkgtar")
print("closing write stream")
pkg.close()