ComputerKeeper/publish_package.py

46 lines
1.2 KiB
Python
Raw Normal View History

2022-11-07 04:06:29 +00:00
################################################################################
"""
Publish the EXE as a package to Gitea.
"""
################################################################################
import os
import requests
2022-11-07 04:21:12 +00:00
OWNER = "Potlatch-Loggers"
2022-11-07 04:06:29 +00:00
PKG_NAME = "ComputerKeeper-BUILD"
PKG_VERSION = "latest"
FILE_NAME = "main.exe"
AUTH_USER = os.getenv("GITEA_USER")
AUTH_PASS = os.getenv("GITEA_PASS")
HOST = "https://gitea.stanleysolutionsnw.com"
def main():
"""Attempt Deleting the Package, then Add the New Package with File."""
s = requests.Session()
s.auth = (AUTH_USER, AUTH_PASS)
# Delete Package
try:
2022-11-07 04:10:42 +00:00
print("Deleting...")
result = s.delete(
2022-11-07 04:06:29 +00:00
f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}"
)
2022-11-07 04:10:42 +00:00
result.raise_for_status()
2022-11-07 04:06:29 +00:00
except Exception:
# Intentionally Overlook Issues Here
2022-11-07 04:10:42 +00:00
print("No package to delete.")
2022-11-07 04:06:29 +00:00
# Add New Package
2022-11-07 04:10:42 +00:00
print("Adding new package...")
result = s.put(
2022-11-07 04:06:29 +00:00
(
f"{HOST}/api/packages/{OWNER}/generic/{PKG_NAME}/{PKG_VERSION}/" +
FILE_NAME
),
data=open(f"dist/{FILE_NAME}", 'rb').read(),
)
2022-11-07 04:10:42 +00:00
result.raise_for_status()
2022-11-07 04:16:42 +00:00
if __name__ == "__main__":
main()