stream_layered_image: Add main method

This commit is contained in:
Utku Demir 2020-06-21 11:46:15 +12:00
parent 307804d97d
commit 26402290bf
No known key found for this signature in database
GPG Key ID: F3F8629C3E0BF60B

View File

@ -181,19 +181,18 @@ def add_bytes(tar, path, content, mtime):
tar.addfile(ti, io.BytesIO(content)) tar.addfile(ti, io.BytesIO(content))
# Main def main():
with open(sys.argv[1], "r") as f:
with open(sys.argv[1], "r") as f:
conf = json.load(f) conf = json.load(f)
created = ( created = (
datetime.now(tz=datetime.timezone.utc) datetime.now(tz=datetime.timezone.utc)
if conf["created"] == "now" if conf["created"] == "now"
else datetime.fromisoformat(conf["created"]) else datetime.fromisoformat(conf["created"])
) )
mtime = int(created.timestamp()) mtime = int(created.timestamp())
with tarfile.open(mode="w|", fileobj=sys.stdout.buffer) as tar: with tarfile.open(mode="w|", fileobj=sys.stdout.buffer) as tar:
layers = [] layers = []
for num, store_layer in enumerate(conf["store_layers"]): for num, store_layer in enumerate(conf["store_layers"]):
print( print(
@ -248,3 +247,7 @@ with tarfile.open(mode="w|", fileobj=sys.stdout.buffer) as tar:
add_bytes(tar, "manifest.json", manifest_json, mtime=mtime) add_bytes(tar, "manifest.json", manifest_json, mtime=mtime)
print("Done.", file=sys.stderr) print("Done.", file=sys.stderr)
if __name__ == "__main__":
main()