-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathShell.py
111 lines (111 loc) · 3.69 KB
/
Shell.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
import Swamipp as Swami
import os,datetime
import _thread, sys
import argparse
#sys.setrecursionlimit(10000)
parser = argparse.ArgumentParser(description="Swami++")
parser.add_argument("file",nargs="?",type=str,help="file to be executed",default="")
args=parser.parse_args()
if args.file:
try:
code=open(args.file,"r").read()
y=datetime.datetime.now()
result,error=Swami.run(args.file,code)
x=datetime.datetime.now()
if error:
print(error.toString(),sep="\n")
else:
print(f"\nExecuted with zero errors in {(x-y).total_seconds()} seconds")
except KeyboardInterrupt:
sys.exit()
except Exception as e:
print("Could not find file, or fatal error...",e)
sys.exit()
def begin(s,r):
return s[:len(r)]==r
print("Swami++ 2.9.3, type credits for more info")
directory="C:/Swamipp/Programs/"
def notepad(f):
os.system("notepad.exe "+directory+f)
return
while 1:
command=input(">>> ")
if command=="exit":
break
elif command=="credits":
print("Developed By ClackHack, inspired by CodePulse")
elif begin(command,"file "):
f=command.replace("file ","")
if not f.endswith(".spp"):
print("Expected .spp file")
continue
try:
open(directory+f,"r").read()
except:
open(directory+f,"w").write("")
_thread.start_new_thread(notepad,(f,))
#os.system("notepad.exe Programs/"+f)
elif begin(command,"run "):
f = command.replace("run ","")
try:
code=open(directory+f,"r").read()
y=datetime.datetime.now()
result,error=Swami.run(f,code)
x=datetime.datetime.now()
if error:
print(error.toString(),sep="\n")
else:
print(f"\nExecuted with zero errors in {(x-y).total_seconds()} seconds")
except KeyboardInterrupt:
continue
except Exception as e:
print("Could not find file, or fatal error...",e)
elif begin(command,"build "):
f = command.replace("build ","")
try:
code=open(directory+f,"r").read()
y=datetime.datetime.now()
result,error=Swami.build(f,code)
x=datetime.datetime.now()
if error:
print(error.toString(),sep="\n")
else:
print(result.node)
print(f"\nBuilt with zero errors in {(x-y).total_seconds()} seconds")
except KeyboardInterrupt:
continue
except Exception as e:
print("Could not find file, or fatal error...",e)
elif command=="repl":
while 1:
text=input("Swami++ > ")
if text.strip()=="":
continue
if text=="exit":
break
try:
result,error=Swami.run("<Shell>",text)
except KeyboardInterrupt:
continue
if error:
print(error.toString())
elif result:
if len(result.elements)==1:
print(repr(result.elements[0]))
else:
for i in result.elements:
print(repr(i))
elif command=="programs":
f=os.listdir(directory.strip("/"))
for p in f:
print(p)
elif begin(command,"delete"):
f = command.replace("delete ","").strip()
try:
os.remove(directory+f)
except:
print("The file you specified was not found...")
elif command=="help":
print("Commands are file, run, programs, delete, repl, and exit\nCheck the github page for syntax support")
else:
print("Unkown command...\ntype help for help... ")