-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathcheck_update.py
More file actions
91 lines (76 loc) · 3.2 KB
/
check_update.py
File metadata and controls
91 lines (76 loc) · 3.2 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import requests, os, zipfile, shutil, subprocess
from tqdm import tqdm
import re
from tkinter import messagebox
main_path = os.path.dirname(__file__)
gui_github = requests.get("https://raw.githubusercontent.com/agentasteriski/DiffTrainer/main/difftrainer.py")
github_version = re.search(r'version\s*=\s*[\'"]([^\'"]+)[\'"]', gui_github.text)
github_version = github_version.group(1)
with open("difftrainer.py", "r", encoding = "utf-8") as gui_local:
gui_local = gui_local.read()
local_version = re.search(r'version\s*=\s*[\'"]([^\'"]+)[\'"]', gui_local)
local_version = local_version.group(1)
reqs_url = "https://raw.githubusercontent.com/agentasteriski/DiffTrainer/refs/heads/main/requirements.txt"
reqresponse = requests.get(reqs_url)
with open('requirements_compare.txt', 'wb') as f:
f.write(reqresponse.content)
reqs_new = "requirements_compare.txt"
reqs = "requirements.txt"
with open(reqs, 'r') as f1:
with open(reqs_new, 'r') as f2:
if f1.read() != f2.read():
update_reqs = True
else:
update_reqs = False
try:
os.remove(reqs_new)
except:
print("Error removing temporary comparison file")
if local_version >= github_version:
pass
else:
update_prompt = messagebox.askyesno("Notice", f"Latest DiffTrainer version is {github_version}.\n\nYou currently have {local_version}.\n\nWould you like to update DiffTrainer?")
if update_prompt:
url = "https://github.com/agentasteriski/DiffTrainer/archive/refs/heads/main.zip"
zip = os.path.join(os.getcwd(), url.split("/")[-1])
folder = "DiffTrainer-main"
response = requests.get(url, stream = True)
total_size = int(response.headers.get("content-length", 0))
with tqdm(total = total_size, unit = "B", unit_scale = True, desc = "downloading DiffTrainer...") as progress_bar:
with open("main.zip", "wb") as f:
for chunk in response.iter_content(chunk_size = 1024):
if chunk:
f.write(chunk)
progress_bar.update(len(chunk))
with zipfile.ZipFile(zip, "r") as zip_ref:
zip_ref.extractall()
os.remove(zip)
if os.path.exists(folder):
shutil.rmtree("strings")
shutil.move(f"{folder}/strings", main_path)
shutil.rmtree("assets")
shutil.move(f"{folder}/assets", main_path)
[os.remove(filename)
for filename in os.listdir(main_path) if filename.endswith(".bat")]
[shutil.move(os.path.join(folder, filename), main_path)
for filename in os.listdir(folder) if filename.endswith(".bat")]
[os.remove(filename)
for filename in os.listdir(main_path) if filename.endswith(".txt")]
[shutil.move(os.path.join(folder, filename), main_path)
for filename in os.listdir(folder) if filename.endswith(".txt")]
[os.remove(filename)
for filename in os.listdir(main_path) if filename.endswith(".py")]
[shutil.move(os.path.join(folder, filename), main_path)
for filename in os.listdir(folder) if filename.endswith(".py")]
shutil.rmtree(folder)
if update_reqs == True:
try:
subprocess.check_call(['pip', 'install', '-r', 'requirements.txt'])
except subprocess.CalledProcessError as e:
print(f"Error updating dependencies: {e}")
else:
pass
from difftrainer import App #import later to prevent the app from using the older ver <3
if __name__ == "__main__":
app = App()
app.mainloop()