-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
147 lines (123 loc) · 3.68 KB
/
main.py
File metadata and controls
147 lines (123 loc) · 3.68 KB
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
import sys
import os
import arguments
commandname = []
commandarguements = []
commandwriting = []
debug = False
def delete(item, mode):
try:
value = commandname.index(item)
temp = commandname
temp.pop(value)
temp2 = commandarguements
temp2.pop(value)
value1 = ','.join(commandname) + "," + "NULL"
value2 = ','.join(commandarguements)
f = open("contents.csv", "w")
f.write(value1)
f.write("\n")
f.write(value2)
f.close()
if mode == True:
os.remove(item + ".py")
except Exception as e:
print("Error: Command does not exist")
def updatevalues():
global commandname
global commandarguements
for i in commandname:
commandname.pop(commandname.index(i))
for i in commandarguements:
commandarguements.pop(commandarguements.index(i))
f = open("contents.csv", "r")
contents = f.readlines()
temp = contents[0].split(',')
temp.pop()
value1 = temp
value2 = contents[1].split(',')
commandname = value1
commandarguements = value2
if len(commandname) != len(commandarguements):
commandarguements.pop()
def newvalue(name, arg):
f = open("contents.csv", "r")
contents = f.readlines()
temp = contents[0].split(',')
temp.pop()
value1 = ','.join(temp)
value2 = contents[1]
value1 = value1 + "," + name + "," + "NULL"
value2 = value2 + "," + arg
f.close()
f = open("contents.csv", "w")
f.write(value1)
f.write("\n")
f.write(value2)
f.close()
def decode(currentinput):
global debug
if lineinput == "/e":
sys.exit()
if currentinput.split()[0] == "fd":
try:
commandname.index(currentinput.split()[1])
if commandarguements[commandname.index(currentinput.split()[1])] == str(len(currentinput.split()) - 2):
if commandarguements[commandname.index(currentinput.split()[1])] != "0":
for i in range(len(arguments.args)):
arguments.args.pop()
for i in range(int(commandarguements[commandname.index(currentinput.split()[1])])):
arguments.args.append(currentinput.split()[i + 2])
exec(open(currentinput.split()[1] + ".py").read())
else :
print("Error: This needs %s arguments not %s" % (commandarguements[commandname.index(currentinput.split()[1])], len(currentinput.split()) - 2))
except Exception as e:
print("Error: That is not a current command")
if debug == False:
print(e)
else:
raise e
if currentinput.split()[0] == "new":
if len(currentinput.split()) == 3:
i = 0
while (True):
i += 1
writeinput = input("Line %d>> " % (i))
if writeinput == "/e":
break
else:
commandwriting.append(writeinput)
f = open(currentinput.split()[1] + ".py","w+")
for i in range(len(commandwriting)):
f.write(commandwriting[i])
f.write("\r")
f.close()
newvalue(currentinput.split()[1], currentinput.split()[2])
updatevalues()
else:
print("Error: You need 2 arguments")
if currentinput.split()[0] == "add":
if len(currentinput.split()) == 3:
newvalue(currentinput.split()[1], currentinput.split()[2])
print("Added " + currentinput.split()[1] + "to command list")
else:
print("Error: This must have 2 arguments")
if currentinput.split()[0] == "edit":
if len(currentinput.split()) == 3:
delete(currentinput.split()[1], False)
newvalue(currentinput.split()[1], currentinput.split()[2])
print("Changed the file %s to have %s arguments" % (currentinput.split()[1], currentinput.split()[2]))
if currentinput.split()[0] == "del":
delete(currentinput.split()[1], True)
print("Deleted %s from command list" % (currentinput.split()[1]))
if currentinput == "debug":
if debug == True:
debug = False
print("Debug Set to False")
else:
debug = True
print("Debug set to True")
while (True):
updatevalues()
lineinput = input("cmd>> ")
decode(lineinput)