-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTerminalRuntimeEnv.py
More file actions
67 lines (46 loc) · 1.42 KB
/
TerminalRuntimeEnv.py
File metadata and controls
67 lines (46 loc) · 1.42 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
import Commands
"""V1"""
def transform_to_string(tuple_entry):
output = ""
for x in tuple_entry:
output += x
return output
def transform_to_tuple(string):
output = []
for x in string:
output.append(x)
return tuple(output)
def check_for_command(entry):
first_space = transform_to_string(entry).find(" ")
entry_s = transform_to_string(entry)
print(first_space)
# if entry == ("l", "s"):
if entry == transform_to_tuple("ls"):
Commands.ls()
# elif entry[:2] == ("c", "d"):
elif entry[:2] == transform_to_tuple("cd"):
path = transform_to_string(entry[3:])
Commands.cd(path)
# elif entry == ("w", "h", "o", "a", "m", "i"):
elif entry == transform_to_tuple("whoami"):
print(Commands.whoami())
# elif entry == ("p", "w", "d"):
elif entry == transform_to_tuple("pwd"):
print(Commands.pwd())
elif entry_s[:first_space] == "mkdir":
path = entry_s[first_space+1:]
Commands.mkdir(path)
elif entry_s[:first_space] == "rm":
path = entry_s[first_space+1:]
try:
a = open(path, "r")
mode = "file"
a.close()
except:
mode = "dir"
Commands.rm(path, mode)
# Main Loop NOT TO RUN ON IMPORT
if __name__ == "__main__":
while True:
entry = input(Commands.pwd() + " >>>")
check_for_command(transform_to_tuple(entry))