-
Notifications
You must be signed in to change notification settings - Fork 1
/
updater.py
89 lines (69 loc) · 3.53 KB
/
updater.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
85
86
87
88
89
from boxEngine import warn,error,success
import git
import shutil
from configparser import ConfigParser
from rich.console import Console
console = Console()
config = ConfigParser(comment_prefixes="#", delimiters="=")
config.read("data/config/main.ini")
current_version = str(config["MAIN"]["version"]) # Gets version from config main.ini
current_channel = str(config["MAIN"]["channel"]) # Gets branch selection from config main.ini
class updater:
# Automatically pulls from
def update():
branch = current_channel
if branch == "main":
# Replace these with your own values
repo_url = "https://github.com/ValkTheBoxman/boxpyShell"
local_path = "/path/to/local/folder"
# Clone the latest code from the GitHub repository
repo = git.Repo.clone_from(repo_url, local_path, branch='main')
# Replace the old code with the new code
shutil.rmtree("/path/to/old/folder")
shutil.move(local_path, "/path/to/old/folder")
elif branch == "dev":
# Replace these with your own values
repo_url = "https://github.com/ValkTheBoxman/boxpyShell/tree/dev"
local_path = "/path/to/local/folder"
# Clone the latest code from the GitHub repository
repo = git.Repo.clone_from(repo_url, local_path, branch='dev')
# Replace the old code with the new code
shutil.rmtree("/path/to/old/folder")
shutil.move(local_path, "/path/to/old/folder")
def check():
branch = current_channel
if branch == "main":
repo_url = "https://github.com/ValkTheBoxman/boxpyShell/"
local_path = "/path/to/local/folder"
# Clone the latest code from the GitHub repository
repo = git.Repo.clone_from(repo_url, local_path, branch='main')
# Check the latest version of the code on GitHub
latest_version = repo.git.describe('--tags', '--abbrev=0')
# Replace the old code with the new code if the latest version is different
if latest_version != current_version:
warn(f"A new update ({latest_version}) is available! Use the updater to update to the latest version.")
else:
success("You have the latest version of the code!")
elif branch == "dev":
repo_url = "https://github.com/ValkTheBoxman/boxpyShell/tree/dev"
local_path = "/path/to/local/folder"
# Clone the latest code from the GitHub repository
repo = git.Repo.clone_from(repo_url, local_path, branch='main')
# Check the latest version of the code on GitHub
latest_version = repo.git.describe('--tags', '--abbrev=0')
# Replace the old code with the new code if the latest version is different
if latest_version != current_version:
warn(f"A new update ({latest_version}) is available! Use the updater to update to the latest version.")
else:
success("You have the latest version of the code!")
while True:
console.print("[bold]Welcome to the boxpyshell updater!")
updater.check()
uInput = input("user: ")
if uInput == ["exit","e","Exit"]:
exit(0)
elif uInput == ["update","u"]:
warn("Are you sure you want to update? Please make sure that boxpyshell is closed before continuing.")
confirm = console.input("Confirm? ([bright_green]Y[/]/[bright_red]N[/]) :")
elif uInput == "download" or uInput == "d":
warn()