-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater_others.py
84 lines (75 loc) · 2.91 KB
/
updater_others.py
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
"""
This file implements auto-updates for the ACPL.
This file will update the other update file and the startup file.
"""
import os
import shutil
from recurrent_classes import *
from time import sleep
# Updating the main updater
print(bcolors.OKBLUE + texts.updates["RewritingElement"].format(element="updater_main.py") + bcolors.ENDC)
old_file = open("updater_main.py", "r", encoding="utf-8")
old_lines = old_file.readlines()
try:
old_file = open("updater_main.py", "w", encoding="utf-8")
new_file = open("update/updater_main.py", "r", encoding="utf-8")
old_file.writelines(new_file.readlines())
old_file.close()
new_file.close()
print(bcolors.OKBLUE + texts.updates["ElementRewritten"].format(element="updater_main.py") + bcolors.ENDC)
except:
old_file.writelines(old_lines)
old_file.close()
print(bcolors.FAIL + texts.updates["CouldNotRewritElement"].format(element="updater_main") + bcolors.ENDC)
del old_lines
startup_file = open("startup.acpl-ini", "r")
new_startup_file = open("update/startup.acpl-ini", "r")
# Getting the old settings
old_settings = {}
for line in startup_file:
line = remove_suffix(line, line.endswith("\n"))
line = line.split(": ")
old_settings[line[0]] = line[1]
# Getting the new settings
new_settings = {}
for line in new_startup_file:
line = remove_suffix(line, line.endswith("\n"))
line = line.split(": ")
new_settings[line[0]] = line[1]
# Setting up final settings
final_settings = {}
for element in new_settings:
if element != "version" and element in old_settings.keys():
final_settings[element] = old_settings[element]
else:
final_settings[element] = new_settings[element]
# Putting final settings in startup.acpl-ini
# Closing the old files first
startup_file.close()
new_startup_file.close()
# Opening it in write mode
startup_file = open("startup.acpl-ini", "w", encoding="utf-8")
# Creating a list of its lines
new_startup_lines = []
for element in final_settings:
new_startup_lines.append(f"{element}: {final_settings[element]}\n")
# Writing them inside and closing it
startup_file.writelines(new_startup_lines)
startup_file.close()
# Removing the temp files and folders
os.remove("update.zip")
shutil.rmtree(os.getcwd()+"/update", ignore_errors=True)
# Updating dependencies
print(f"{bcolors.OKBLUE}Updating dependencies...{bcolors.ENDC}")
os.system("pip install -r --upgrade requirements.txt")
print(f"{bcolors.OKGREEN}Dependencies updated successfully !{bcolors.ENDC}")
# Changelog
print(f"\n\n{bcolors.BOLD}{bcolors.OKGREEN}{texts.updates['UpdateApplied']}{bcolors.ENDC}")
sleep(2)
user_input = input(f"{texts.updates['SeeChangelog']} (yes/no)\n")
if user_input[0].lower() == "y":
changelog_file = open("changelog.md", "r")
changelog = changelog_file.readlines()
changelog_file.close()
changelog = md_format(changelog)
print(changelog)