This repository has been archived on 2024-08-25. You can view files and clone it, but cannot push or open issues or pull requests.
gitea-branding/upload.py

45 lines
1.2 KiB
Python
Raw Normal View History

2023-03-26 19:57:10 +01:00
#!/usr/bin/env python3
import requests
from pathlib import Path
2023-03-26 20:38:35 +01:00
from generate import OUTPUT_DIR
import os
import zipfile
from io import BytesIO
ARTIFACT_NAME = "branding.zip"
OWNER = "sys"
PACKAGE_NAME = "gitea-branding"
def main():
2023-11-27 19:48:57 +00:00
gitea_url = os.environ["GITEA_URL"]
gitea_token = os.environ["GITEA_TOKEN"]
session = requests.Session()
session.headers["Authorization"] = f"token {gitea_token}"
print("Building archive...")
archive = BytesIO()
with zipfile.ZipFile(archive, "w") as zip_file:
for output_file in OUTPUT_DIR.rglob("*.*"):
zip_file.writestr(output_file.name, output_file.read_bytes())
archive.seek(0)
print("Deleting existing...")
delete_response = session.delete(f"{gitea_url}/api/packages/{OWNER}/generic/{PACKAGE_NAME}/latest/{ARTIFACT_NAME}")
# 404 means we've not uploaded it yet.
if delete_response.status_code != 404:
delete_response.raise_for_status()
print("Uploading...")
response = session.put(f"{gitea_url}/api/packages/{OWNER}/generic/{PACKAGE_NAME}/latest/{ARTIFACT_NAME}", files={ARTIFACT_NAME: archive})
response.raise_for_status()
if __name__ == "__main__":
main()