-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnepterm.py
More file actions
52 lines (44 loc) · 943 Bytes
/
Copy pathnepterm.py
File metadata and controls
52 lines (44 loc) · 943 Bytes
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
import os
ERROR = "ERROR"
CD = "CD"
COMMAND_ID = {
"ls": 0,
"touch": 1,
"cat": 2,
"mkdir": 3,
"cd": 4,
"pwd": 5,
"exit": 6,
"help": 7,
"rm": 8,
"echo": 9,
"clear": 10,
"$": 11,
ERROR: 12,
}
def handle_ls(cwd: str, stream: str):
try:
file_path = stream.split()[1]
except:
file_path = cwd
files = [file for file in os.listdir(file_path)]
return ".\n..\n"+"\n".join(files)
def check_for_command_id(stream: str):
try:
type = stream.split()[0]
if type in COMMAND_ID:
return COMMAND_ID[type]
return COMMAND_ID[ERROR]
except:
return COMMAND_ID[ERROR]
def handle_command_by_id(cwd: str, stream: str, id: int):
if (id == COMMAND_ID["ls"]):
return handle_ls(cwd, stream)
pass
def exec(cwd: str, stream: str):
id = check_for_command_id(stream)
if id == COMMAND_ID[ERROR]:
return ERROR
return handle_command_by_id(cwd, stream, id)
if __name__ == "main":
print(exec(r"C:\Lakshay\Projects\Neptune", "ls"))