-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.py
127 lines (112 loc) · 3.65 KB
/
Utils.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import json
import struct
import time
import sys
import os
import shutil
import gzip
from colorama import init as colorama_init
from colorama import Fore, Style
colorama_init()
SystemCriticalFolders = ["users", "logs"]
def get_base_path():
return os.path.abspath(".")
def get_log_path():
return os.path.join(get_base_path(), "A", "logs")
def ensure_log_directory():
log_path = get_log_path()
if not os.path.exists(log_path):
os.makedirs(log_path)
with open(log_path + ".meta", "wb") as file:
binary_data = struct.pack('i', 2)
file.write(binary_data)
file.close()
def OSPrint(value):
Msg = f">> {value}"
print(Msg)
OSLatestLog(Msg)
def OSPrintError(value):
Error = f"{Fore.RED}/!\ {value} /!\{Style.RESET_ALL}"
LogError = f"/!\ {value} /!\ "
print(Error)
OSLatestLog(LogError)
def OSPrintWarning(value):
Warn = f"{Fore.YELLOW}! {value} !{Style.RESET_ALL}"
LogWarn = f"! {value} !"
print(Warn)
OSLatestLog(LogWarn)
def OSLatestLog(value):
ensure_log_directory()
latest_log = open(os.path.join(get_log_path(), "latest.log"), "a")
if "\n" in value:
latest_log.write(value)
else:
latest_log.write(value + "\n")
def OSClearLatestLog():
log_path = get_log_path()
ensure_log_directory()
if not os.path.isfile(os.path.join(log_path, "latest.log")):
open(os.path.join(log_path, "latest.log"), "w").close()
return
FileCount = 0
for item in os.listdir(log_path):
if os.path.isfile(os.path.join(log_path, item)):
if ".meta" not in item and ".gitignore" not in item:
FileCount += 1
if FileCount >= 6:
shutil.rmtree(log_path)
os.makedirs(log_path)
open(os.path.join(log_path, "latest.log"), "w").close()
return
CurrentTime = time.ctime()
CurrentTime = CurrentTime.replace(" ", "-")
CurrentTime = CurrentTime.replace(":", "-")
latest_log_path = os.path.join(log_path, "latest.log")
backup_log_path = os.path.join(log_path, f"{CurrentTime}.log")
gzip_log_path = f"{backup_log_path}.gz"
shutil.copy(latest_log_path, backup_log_path)
with open(backup_log_path, 'rb') as f_in:
with gzip.open(gzip_log_path, 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
os.remove(backup_log_path)
open(latest_log_path, "w").close()
def OSLoad(value, endmessage, speed):
Completion = 0
while Completion != 100:
sys.stdout.write(f"\r>> {value} ({Completion}%)")
if speed == "Slow":
time.sleep(0.1)
elif speed == "Normal":
time.sleep(0.01)
elif speed == "Fast":
time.sleep(0.001)
else:
time.sleep(0.1)
Completion += 1
EndMessage = f"\r>> {endmessage} ({Completion}%)"
sys.stdout.write(f"{EndMessage} ")
sys.stdout.write("\n")
OSLatestLog(EndMessage)
def OS_Shutdown(value):
Completion = 0
while Completion != 3:
sys.stdout.write(f"\r>> {value}. ")
time.sleep(0.1)
sys.stdout.write(f"\r>> {value}.. ")
time.sleep(0.1)
sys.stdout.write(f"\r>> {value}...")
time.sleep(0.1)
Completion += 1
sys.stdout.write("\n")
os.system("cls")
def OSInput(CaseSensitive):
value = input("// ")
if not CaseSensitive:
value = value.lower()
OSLatestLog(f"// {value}")
return value
def GetAccountAccredidation(login):
with open(os.path.join(get_base_path(), "accounts", f"{login}.json")) as f:
data = json.loads(f.read())
accreditationlvl = data["accreditation"]
return int(accreditationlvl)