ArunCode-Term 0.1.0__py3-none-any.whl → 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ArunCode_Term/main.py +169 -0
- {aruncode_term-0.1.0.dist-info → aruncode_term-0.1.1.dist-info}/METADATA +1 -1
- aruncode_term-0.1.1.dist-info/RECORD +7 -0
- aruncode_term-0.1.0.dist-info/RECORD +0 -7
- {aruncode_term-0.1.0.dist-info → aruncode_term-0.1.1.dist-info}/WHEEL +0 -0
- {aruncode_term-0.1.0.dist-info → aruncode_term-0.1.1.dist-info}/top_level.txt +0 -0
ArunCode_Term/main.py
CHANGED
|
@@ -9,6 +9,175 @@ import os
|
|
|
9
9
|
import subprocess
|
|
10
10
|
import readline
|
|
11
11
|
from importlib import resources
|
|
12
|
+
# =========================
|
|
13
|
+
# ArunCode main.py
|
|
14
|
+
# =========================
|
|
15
|
+
|
|
16
|
+
import random
|
|
17
|
+
import sys
|
|
18
|
+
import json
|
|
19
|
+
import os
|
|
20
|
+
import subprocess
|
|
21
|
+
import readline
|
|
22
|
+
from importlib import resources
|
|
23
|
+
|
|
24
|
+
# ---------- JSON HELPERS ----------
|
|
25
|
+
def load_accounts():
|
|
26
|
+
with resources.files("ArunCode_Term.Data").joinpath("user_data.json").open("r") as f:
|
|
27
|
+
return json.load(f)
|
|
28
|
+
|
|
29
|
+
def save_accounts(accounts):
|
|
30
|
+
with resources.files("ArunCode_Term.Data").joinpath("user_data.json").open("w") as f:
|
|
31
|
+
json.dump(accounts, f, indent=4)
|
|
32
|
+
|
|
33
|
+
# ---------- TERMINAL ----------
|
|
34
|
+
def terminal(user):
|
|
35
|
+
hostname = "ArunCode.com"
|
|
36
|
+
cwd = user["fs"]
|
|
37
|
+
path_stack = ["~"]
|
|
38
|
+
|
|
39
|
+
if "file_contents" not in user:
|
|
40
|
+
user["file_contents"] = {}
|
|
41
|
+
|
|
42
|
+
def completer(text, state):
|
|
43
|
+
options = [i for i in list(cwd["folders"].keys()) + cwd["files"] if i.startswith(text)]
|
|
44
|
+
return options[state] if state < len(options) else None
|
|
45
|
+
|
|
46
|
+
readline.set_completer(completer)
|
|
47
|
+
readline.parse_and_bind("tab: complete")
|
|
48
|
+
|
|
49
|
+
def prompt():
|
|
50
|
+
path = "/".join(path_stack)
|
|
51
|
+
symbol = "#" if user["sudo"] == "True" else "$"
|
|
52
|
+
return f"{user['username']}@{hostname}/{user['usertype']}:{path} {symbol} "
|
|
53
|
+
|
|
54
|
+
def print_tree(directory, prefix=""):
|
|
55
|
+
for folder in directory["folders"]:
|
|
56
|
+
print(prefix + folder + "/")
|
|
57
|
+
print_tree(directory["folders"][folder], prefix + " ")
|
|
58
|
+
for file in directory["files"]:
|
|
59
|
+
print(prefix + file)
|
|
60
|
+
|
|
61
|
+
try:
|
|
62
|
+
while True:
|
|
63
|
+
command = input(prompt()).strip()
|
|
64
|
+
|
|
65
|
+
if command == "whoami":
|
|
66
|
+
print(user["username"])
|
|
67
|
+
|
|
68
|
+
elif command == "exit":
|
|
69
|
+
break
|
|
70
|
+
|
|
71
|
+
elif command == "clear":
|
|
72
|
+
os.system("clear")
|
|
73
|
+
|
|
74
|
+
elif command == "ls":
|
|
75
|
+
items = list(cwd["folders"].keys()) + cwd["files"]
|
|
76
|
+
print(" ".join(items) if items else "(empty)")
|
|
77
|
+
|
|
78
|
+
elif command == "pwd":
|
|
79
|
+
print("/".join(path_stack))
|
|
80
|
+
|
|
81
|
+
elif command == "tree":
|
|
82
|
+
print_tree(cwd)
|
|
83
|
+
|
|
84
|
+
elif command.startswith("cd"):
|
|
85
|
+
parts = command.split()
|
|
86
|
+
if len(parts) == 1 or parts[1] == "~":
|
|
87
|
+
cwd = user["fs"]
|
|
88
|
+
path_stack[:] = ["~"]
|
|
89
|
+
elif parts[1] == "..":
|
|
90
|
+
if len(path_stack) > 1:
|
|
91
|
+
path_stack.pop()
|
|
92
|
+
cwd = user["fs"]
|
|
93
|
+
for p in path_stack[1:]:
|
|
94
|
+
cwd = cwd["folders"][p]
|
|
95
|
+
elif parts[1] in cwd["folders"]:
|
|
96
|
+
cwd = cwd["folders"][parts[1]]
|
|
97
|
+
path_stack.append(parts[1])
|
|
98
|
+
else:
|
|
99
|
+
print("cd: no such directory")
|
|
100
|
+
|
|
101
|
+
elif command.startswith("makir "):
|
|
102
|
+
name = command.split(" ", 1)[1]
|
|
103
|
+
cwd["folders"][name] = {"files": [], "folders": {}}
|
|
104
|
+
|
|
105
|
+
elif command.startswith("touch "):
|
|
106
|
+
name = command.split(" ", 1)[1]
|
|
107
|
+
if not name.endswith(".txt"):
|
|
108
|
+
name += ".txt"
|
|
109
|
+
cwd["files"].append(name)
|
|
110
|
+
user["file_contents"][name] = ""
|
|
111
|
+
|
|
112
|
+
elif command.startswith("cat "):
|
|
113
|
+
name = command.split(" ", 1)[1]
|
|
114
|
+
if not name.endswith(".txt"):
|
|
115
|
+
name += ".txt"
|
|
116
|
+
print(user["file_contents"].get(name, ""))
|
|
117
|
+
|
|
118
|
+
elif command.startswith("rm "):
|
|
119
|
+
name = command.split(" ", 1)[1]
|
|
120
|
+
if name in cwd["files"]:
|
|
121
|
+
cwd["files"].remove(name)
|
|
122
|
+
user["file_contents"].pop(name, None)
|
|
123
|
+
else:
|
|
124
|
+
print("rm: no such file")
|
|
125
|
+
|
|
126
|
+
elif command.startswith("ping "):
|
|
127
|
+
subprocess.run(["ping", "-c", "4", command.split()[1]])
|
|
128
|
+
|
|
129
|
+
else:
|
|
130
|
+
print(f"{command}: command not found")
|
|
131
|
+
|
|
132
|
+
except KeyboardInterrupt:
|
|
133
|
+
print()
|
|
134
|
+
|
|
135
|
+
# ---------- MAIN ----------
|
|
136
|
+
def main():
|
|
137
|
+
while True:
|
|
138
|
+
print("\n1) Login\n2) Create Account\n3) Guest\n4) Exit")
|
|
139
|
+
choice = input(">>> ")
|
|
140
|
+
|
|
141
|
+
if choice == "1":
|
|
142
|
+
u = input("user: ")
|
|
143
|
+
p = input("pass: ")
|
|
144
|
+
accounts = load_accounts()
|
|
145
|
+
user = next((a for a in accounts if a["username"] == u and a["password"] == p), None)
|
|
146
|
+
if user:
|
|
147
|
+
terminal(user)
|
|
148
|
+
save_accounts(accounts)
|
|
149
|
+
else:
|
|
150
|
+
print("ERROR: Invalid credentials")
|
|
151
|
+
|
|
152
|
+
elif choice == "2":
|
|
153
|
+
u = input("Username: ")
|
|
154
|
+
p = input("Password: ")
|
|
155
|
+
t = input("User Type: ")
|
|
156
|
+
accounts = load_accounts()
|
|
157
|
+
accounts.append({
|
|
158
|
+
"username": u,
|
|
159
|
+
"password": p,
|
|
160
|
+
"sudo": "False",
|
|
161
|
+
"usertype": t,
|
|
162
|
+
"fs": {"files": [], "folders": {}}
|
|
163
|
+
})
|
|
164
|
+
save_accounts(accounts)
|
|
165
|
+
print("Account created")
|
|
166
|
+
|
|
167
|
+
elif choice == "3":
|
|
168
|
+
terminal({
|
|
169
|
+
"username": f"guest{random.randint(1000,9999)}",
|
|
170
|
+
"sudo": "False",
|
|
171
|
+
"usertype": "Guest",
|
|
172
|
+
"fs": {"files": [], "folders": {}}
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
elif choice == "4":
|
|
176
|
+
sys.exit()
|
|
177
|
+
|
|
178
|
+
# ---------- ENTRY ----------
|
|
179
|
+
if __name__ == "__main__":
|
|
180
|
+
main()
|
|
12
181
|
|
|
13
182
|
# ---------- JSON HELPERS ----------
|
|
14
183
|
def load_accounts():
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ArunCode_Term/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
2
|
+
ArunCode_Term/main.py,sha256=5w44DBSYm7iBukmtMMFPbd_hkk8-ONTDAeGdpLJroJM,10742
|
|
3
|
+
ArunCode_Term/Data/__init__.py,sha256=KvagenBNqSLYLDIDungnjiz1Y-mWMTxwdB-RC6FIS14,16
|
|
4
|
+
aruncode_term-0.1.1.dist-info/METADATA,sha256=PLoS8Jaegn2XxDrfIPLe4ycy9ofzU5gY253j4y-ix7s,241
|
|
5
|
+
aruncode_term-0.1.1.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
+
aruncode_term-0.1.1.dist-info/top_level.txt,sha256=aXCiGtDl1bZueLXUxULvV5XfgRHjdwqmdqla7Qpbl8U,14
|
|
7
|
+
aruncode_term-0.1.1.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
ArunCode_Term/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
2
|
-
ArunCode_Term/main.py,sha256=T-B3E9mIJUm_ehMNmCWGlUS7LSLxiuIwJq4bz4li0sI,5366
|
|
3
|
-
ArunCode_Term/Data/__init__.py,sha256=KvagenBNqSLYLDIDungnjiz1Y-mWMTxwdB-RC6FIS14,16
|
|
4
|
-
aruncode_term-0.1.0.dist-info/METADATA,sha256=i3Ek7JxMC5Wp65EgGPFuiERTLBDrg6XTgXgTCaN6AzE,241
|
|
5
|
-
aruncode_term-0.1.0.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
|
|
6
|
-
aruncode_term-0.1.0.dist-info/top_level.txt,sha256=aXCiGtDl1bZueLXUxULvV5XfgRHjdwqmdqla7Qpbl8U,14
|
|
7
|
-
aruncode_term-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|