-
Notifications
You must be signed in to change notification settings - Fork 1
/
boxpyshell.py
223 lines (176 loc) · 8.15 KB
/
boxpyshell.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
from configparser import ConfigParser
from scriptparser import RemoteScriptBuilder
import re as regex
import sys
import time
import os
from boxEngine import *
from rich.console import Console
from userLogon import logins
console = Console()
printStuffPc, printStuff, run = True, True, True
OSNAME = os.getlogin()
config = ConfigParser(comment_prefixes="#", delimiters="=")
config.read("data/config/main.ini")
# check if debug mode is on:
try:
debug_check = str(config["DEBUG"]["isActive"])
if debug_check == "false":
debugMode = False
elif debug_check == "true":
console.print(f"["+"[bold][bright_yellow] WARN [/]"+"] Debug mode is on!")
debugMode = True
except Exception as Err:
boxEngine.error.ConfigFatal(Err)
# check if the config for the animation lib has changed.
try:
config_data1 = str(config["DEBUG"]["noloading"])
if config_data1 == "false":
animlib.loadingAnim("load",5)
elif config_data1 == "true":
console.print(f"["+"[bold][bright_green] OK [/]"+"]"+"[italic][bold][bright_red] DEBUG:[/]"+" loading animation skipped!")
except Exception as Err:
boxEngine.error.ConfigFatal(Err)
logins.doLogin() # Make a login. Is bypassed if skipLogin is true.
while run is True: # Main Loop
if printStuff is True:
warn("This version of boxpyshell is still in beta! There might be new releases on github!")
print("Hello There!, Type 'help' for a list of avaiable commands")
printStuff = False
print("Please type a command.")
command = console.input(f"[bold][bright_yellow]boxpyshell[/][bright_magenta]@[/][bright_green]{OSNAME}$~:[/] ") # OSNAME = Host name.
if command == "help": # Help is read in /data/ for easier code readability.
print("Select which type of help to display: basic, ext1, ext2")
typeHelp = input(" -> ")
if typeHelp == "basic":
with open('data/txt/help.txt') as file:
print(file.read())
elif typeHelp == "ext1":
with open('data/txt/hpc.txt') as file:
print(file.read())
elif typeHelp == "ext2":
with open('data/txt/hpg.txt') as file:
print(file.read())
continue
elif command == "readEX": # Just what the first print() says. sauce is in /data/
print('This is just a demonstration of the reading ability of boxpyshell')
print("Please wait...")
animlib.loadingAnim("load", 2)
boxEngine.clear()
with open('data/txt/helloworld.txt') as file:
print(file.read())
elif command == "source":
with open("data/txt/source.txt") as file:
print(file.read())
elif command == "cvar": # Common variable
boxEngine.cvar()
elif command == "vars": # Variables stored in /config/vars.ini
boxEngine.vars()
elif command == "rmdir": # gnu :4khdtroll:
path = input("Path to remove directory: ")
boxEngine.rmdir(path)
elif command == "mkdir":
name = input("Give a name for the new directory: ")
if name == None or name == "":
error("You cannot choose an empty name.")
else:
boxEngine.mkdir(name)
elif command == "pcinfo":
...
elif command == "config":
warn("You are changing the main.ini configuartion file. Please be warned that any typo can break boxpyshell!")
uInput = console.input("[bold]What would block you like to change?")
uIBlocks = ["main","debug","ext","external","m","d","e"] # List of commands, full (external), inital letters (e), shortened (ext)
if uInput != uIBlocks: # spell check
error(f"No such thing as {uInput}! Run the command again.")
elif uInput == "main" or uInput == "m": # edit main
boxEngine.error.NotImplement()
elif uInput == "ext" or uInput == "external" or uInput == "e": # edit ext
boxEngine.error.NotImplement()
elif uInput == "debug" or uInput == "d":
boxEngine.error.NotImplement()
elif command == "screenCreate":
print("Please input a command")
cmmd = input()
if cmmd == "createScreen1":
pythonBasic.screens.createScreen()
elif command == "addScript": # Only gusic knows wtf is going in there.
main = RemoteScriptBuilder()
main.run()
elif command == "echo":
find_echo_string = regex.search('"', command)
index_of_string = find_echo_string.span()
echo_string = command[index_of_string[1]:-1:1] # -> Slicing from the start of the string to the end of the string to get the contents
print(echo_string)
if command[:1] in ("?", "!"): #Command Flags for executing code
try:
exec(f"{command[1:]}") # Splitting the command flag from the string so we can run it
except Exception as Err:
print(f"Couldn't run code (Error Received) -> {Err}")
elif command in ("build", "run"): # command should be structured like (build {filename}.py >> .exe) or (run {filename}.py)
command = command.split(" ", 4)
try:
if os.path.exists(command[1]) and ".py" in command[1]:
if command[2] in (">>", "->") and command[3] == ".exe":
with open("file0.py", "w") as file:
file.write(f"""import subprocess
try:
import PyInstaller.__main__
except ModuleNotFoundError:
subprocess.call(['python', '-m', 'pip', 'install', 'pyinstaller'])
import PyInstaller.__main__
PyInstaller.__main__.run(['{command[1]}','--onefile'])""")
try:
os.system("python file0.py")
os.system("py file0.py")
print(f"Successfully built {command[1]} to .exe")
except PermissionError:
print("PermissionError: Couldn't run file0.py")
if command[2] == "" and command[3] == "":
os.system(f"python {command[1]}")
os.system(f"python {command[1]}") # WHAT THE FUCK IS GOING ON
except IndexError:
print("Invalid params for build command")
command = " ".join(command, 4)
elif command == "clearscreen" or command == "clear":
boxEngine.clear()
elif command == "shellVer":
boxEngine.extFunc.funct.shellVer()
elif command == "MathAdd":
boxEngine.extFunc.math.add()
elif command == "MathSubt":
boxEngine.extFunc.math.subtract()
elif command == "helloMe":
boxEngine.extFunc.fun.helloUser()
elif command == "8Ball":
boxEngine.extFunc.fun.eightBall()
elif command == "YesOrNo":
boxEngine.extFunc.fun.ynGame()
elif command == "me":
sys.exit("M E G A E X I T")
elif command == "testcolor":
warn("test")
error("test")
success('test')
elif command == "logout":
logins.logout()
elif command == "license":
with open('LICENSE.txt') as file:
print(file.read())
elif command == "createFile":
try:
command = command.split(" ", 2)
file = command[1]
file_extension = ".txt" if file[-5:] not in (".txt", ".py", ".c", ".rc", ".java") else "" # Basically if the final 5 characters in the user string are not in the tuple, then file_extension = "" as command[1] will already have a file_extension
with open(f"{file}{file_extension}", "w") as file:
file.write("") # Writing nothing to the file so we can just create an empty file
command = " ".join(command, 2)
except Exception as Err: # If we get an index error, we know that the user most likely hasn't specified a filename
print(f"Please specify a filename!") if type(Err) == IndexError else print(f"CreateFileError: {Err}") # Printing first statement if Err is an index error, else we print the other statement
elif command in ("quit", "exit"):
animlib.loadingAnim("exit", 5)
print("terminated main task. exit")
sys.exit()
elif command not in cmdList:
print(f"{command} is not a valid command!")
continue