-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.py
99 lines (73 loc) · 2.35 KB
/
util.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
import platform
import ast
import copy
def point(thing: any) -> any:
"""Makes a reference to an object"""
ref = thing
return ref
def interface(thing: any) -> any:
"""Create a a copy of the object but reference nested objects"""
replica = copy.copy(thing)
return replica
def clone(thing: any) -> any:
"""Create a copy of an object not as a reference"""
newthing = copy.deepcopy(thing)
return newthing
def parsetree(source: str) -> ast.AST:
try:
tree = ast.parse(source, type_comments=True)
except:
tree = ast.parse(source)
finally:
return tree
def get_operating_system() -> str:
"""
Determine the operating system being used.
Returns:
str: A string indicating the operating system. Possible values are "Windows", "Linux", "macOS", or "Unknown".
"""
system: str = platform.system()
if system == "Windows":
return "Windows"
elif system == "Linux":
return "Linux"
elif system == "Darwin":
return "macOS"
else:
return "Unknown"
pip_str = "pip" if get_operating_system() == "Windows" else "pip3"
python_str = "python" if get_operating_system() == "Windows" else "python3"
def classes_begin_index(lines: list[str]) -> int:
# first try to put the CTkListBox as the first Class in the class area
count = 0
for line in lines:
if line.startswith("class "):
return count
count += 1
# if there is no classes defined in the script. Find the first non import line
count = 0
for line in lines:
if line.startswith("import ") or line.startswith("from "):
count += 1
continue
else:
return count
return count
def get_listbox_source():
with open("listbox.py", "r") as file:
lines = file.readlines()[1:]
return lines
def has_listbox(filepath: str) -> bool:
with open(filepath, "r") as file:
content = file.read()
try:
lbi = content.find("tk.Listbox(")
return True
except IndexError:
return False
def print_warning(string: str) -> None:
print("\033[35m[WARNING]\033[0m:\033[31m" + string + "\033[0m")
def print_update(string: str) -> None:
if isinstance(string, list):
string = "[" + ", ".join(string) + "]"
print("\033[32m[UPDATE]\033[0m:\033[33m" + string + "\033[0m")