-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate.py
More file actions
62 lines (49 loc) · 1.95 KB
/
update.py
File metadata and controls
62 lines (49 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# ~~~~~~
# NOTE: Do NOT execute this script if you have forked this repo, it will REVERT YOUR CHANGES to the latest release!
# ~~~~~~
import multiprocessing
import requests
import zipfile
import io
import os
import shutil
import sys
# --- CONFIGURATION ---
REPO_OWNER = "Redfourk"
REPO_NAME = "FileLauncher"
TAG_NAME = "0.1.0-test.3"
ZIP_URL = f"https://api.github.com/repos/{REPO_OWNER}/{REPO_NAME}/zipball/"
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
def update_project():
try:
print(f"Connecting to GitHub to download {TAG_NAME}...")
response = requests.get(ZIP_URL, stream=True, timeout=20)
response.raise_for_status()
zip_data = zipfile.ZipFile(io.BytesIO(response.content))
temp_dir = os.path.join(ROOT_DIR, "_update_temp")
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir)
zip_data.extractall(temp_dir)
extracted_folder = os.path.join(temp_dir, f"{REPO_NAME}-{TAG_NAME}")
if not os.path.exists(extracted_folder):
extracted_folder = os.path.join(temp_dir, os.listdir(temp_dir)[0])
print("Updating local project files...")
for item in os.listdir(extracted_folder):
source = os.path.join(extracted_folder, item)
destination = os.path.join(ROOT_DIR, item)
if os.path.isdir(source):
if os.path.exists(destination):
shutil.rmtree(destination)
shutil.copytree(source, destination)
else:
shutil.copy2(source, destination)
shutil.rmtree(temp_dir)
print("\nSUCCESS: Project updated to latest version. Please restart.")
sys.exit()
except requests.exceptions.ConnectionError:
print("ERROR: Could not connect to GitHub. Check your internet or proxy.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
multiprocessing.freeze_support()
update_project()