-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
78 lines (67 loc) · 2.56 KB
/
main.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
import sys
import os
sys.path.append(os.path.abspath(os.path.dirname(__file__)))
from programs import *
from tools import splitCommand, readInfoFile, writeInfoFile, validateText, sanitizeFilename, ensureUnixPath
def main():
filesystemPath = "filesystem"
infoPath = os.path.join(filesystemPath, ".info")
currentPath = ensureUnixPath(os.path.abspath(filesystemPath))
if not os.path.exists(filesystemPath):
os.makedirs(filesystemPath)
if os.path.exists(infoPath):
info = readInfoFile(infoPath)
username = info.get("username", "user")
hostname = info.get("hostname", "host")
else:
print("Welcome to Punix! Please enter the following information.\n")
while True:
username = input("Username: ")
if validateText(username):
break
else:
print("Please make your username between 3 and 15 characters, with only alphanumeric characters, dashes, or underscores.")
while True:
hostname = input("Hostname: ")
if validateText(hostname):
break
else:
print("Please make your hostname between 3 and 15 characters, with only alphanumeric characters, dashes, or underscores.")
writeInfoFile(infoPath, username, hostname)
while True:
command = input(f"{username}@{hostname} $ ")
args = splitCommand(command)
if not args:
continue
if args[0] in ["help", "?"]:
executeHelp()
elif args[0] == "echo":
executeEcho(args)
elif args[0] == "clear":
clearScreen()
elif args[0] == "touch":
executeTouch(args[1:], currentPath)
elif args[0] == "cd":
currentPath = executeCd(args, currentPath)
elif args[0] == "mkdir":
executeMkdir(args[1:], currentPath)
elif args[0] == "pwd":
executePwd(currentPath)
elif args[0] == "ls":
executeLs(currentPath)
elif args[0] == "rm":
executeRm(args[1:], currentPath)
elif args[0] == "cat":
executeCat(args, currentPath)
elif args[0] == "eval":
executeEval(args)
elif args[0] == "edit":
executeEdit(args)
elif args[0] == "neofetch":
executeNeofetch(username, hostname)
elif args[0] == "exit":
break
else:
print("err: command invalid")
if __name__ == "__main__":
main()