ArunCode-Term 0.1.0__tar.gz

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.
@@ -0,0 +1,2 @@
1
+ # Data package
2
+
@@ -0,0 +1,169 @@
1
+ # =========================
2
+ # ArunCode main.py
3
+ # =========================
4
+
5
+ import random
6
+ import sys
7
+ import json
8
+ import os
9
+ import subprocess
10
+ import readline
11
+ from importlib import resources
12
+
13
+ # ---------- JSON HELPERS ----------
14
+ def load_accounts():
15
+ with resources.files("aruncode.Data").joinpath("user_data.json").open("r") as f:
16
+ return json.load(f)
17
+
18
+ def save_accounts(accounts):
19
+ with resources.files("aruncode.Data").joinpath("user_data.json").open("w") as f:
20
+ json.dump(accounts, f, indent=4)
21
+
22
+ # ---------- TERMINAL ----------
23
+ def terminal(user):
24
+ hostname = "ArunCode.com"
25
+ cwd = user["fs"]
26
+ path_stack = ["~"]
27
+
28
+ if "file_contents" not in user:
29
+ user["file_contents"] = {}
30
+
31
+ def completer(text, state):
32
+ options = [i for i in list(cwd["folders"].keys()) + cwd["files"] if i.startswith(text)]
33
+ return options[state] if state < len(options) else None
34
+
35
+ readline.set_completer(completer)
36
+ readline.parse_and_bind("tab: complete")
37
+
38
+ def prompt():
39
+ path = "/".join(path_stack)
40
+ symbol = "#" if user["sudo"] == "True" else "$"
41
+ return f"{user['username']}@{hostname}/{user['usertype']}:{path} {symbol} "
42
+
43
+ def print_tree(directory, prefix=""):
44
+ for folder in directory["folders"]:
45
+ print(prefix + folder + "/")
46
+ print_tree(directory["folders"][folder], prefix + " ")
47
+ for file in directory["files"]:
48
+ print(prefix + file)
49
+
50
+ try:
51
+ while True:
52
+ command = input(prompt()).strip()
53
+
54
+ if command == "whoami":
55
+ print(user["username"])
56
+
57
+ elif command == "exit":
58
+ break
59
+
60
+ elif command == "clear":
61
+ os.system("clear")
62
+
63
+ elif command == "ls":
64
+ items = list(cwd["folders"].keys()) + cwd["files"]
65
+ print(" ".join(items) if items else "(empty)")
66
+
67
+ elif command == "pwd":
68
+ print("/".join(path_stack))
69
+
70
+ elif command == "tree":
71
+ print_tree(cwd)
72
+
73
+ elif command.startswith("cd"):
74
+ parts = command.split()
75
+ if len(parts) == 1 or parts[1] == "~":
76
+ cwd = user["fs"]
77
+ path_stack[:] = ["~"]
78
+ elif parts[1] == "..":
79
+ if len(path_stack) > 1:
80
+ path_stack.pop()
81
+ cwd = user["fs"]
82
+ for p in path_stack[1:]:
83
+ cwd = cwd["folders"][p]
84
+ elif parts[1] in cwd["folders"]:
85
+ cwd = cwd["folders"][parts[1]]
86
+ path_stack.append(parts[1])
87
+ else:
88
+ print("cd: no such directory")
89
+
90
+ elif command.startswith("makir "):
91
+ name = command.split(" ", 1)[1]
92
+ cwd["folders"][name] = {"files": [], "folders": {}}
93
+
94
+ elif command.startswith("touch "):
95
+ name = command.split(" ", 1)[1]
96
+ if not name.endswith(".txt"):
97
+ name += ".txt"
98
+ cwd["files"].append(name)
99
+ user["file_contents"][name] = ""
100
+
101
+ elif command.startswith("cat "):
102
+ name = command.split(" ", 1)[1]
103
+ if not name.endswith(".txt"):
104
+ name += ".txt"
105
+ print(user["file_contents"].get(name, ""))
106
+
107
+ elif command.startswith("rm "):
108
+ name = command.split(" ", 1)[1]
109
+ if name in cwd["files"]:
110
+ cwd["files"].remove(name)
111
+ user["file_contents"].pop(name, None)
112
+ else:
113
+ print("rm: no such file")
114
+
115
+ elif command.startswith("ping "):
116
+ subprocess.run(["ping", "-c", "4", command.split()[1]])
117
+
118
+ else:
119
+ print(f"{command}: command not found")
120
+
121
+ except KeyboardInterrupt:
122
+ print()
123
+
124
+ # ---------- MAIN ----------
125
+ def main():
126
+ while True:
127
+ print("\n1) Login\n2) Create Account\n3) Guest\n4) Exit")
128
+ choice = input(">>> ")
129
+
130
+ if choice == "1":
131
+ u = input("user: ")
132
+ p = input("pass: ")
133
+ accounts = load_accounts()
134
+ user = next((a for a in accounts if a["username"] == u and a["password"] == p), None)
135
+ if user:
136
+ terminal(user)
137
+ save_accounts(accounts)
138
+ else:
139
+ print("ERROR: Invalid credentials")
140
+
141
+ elif choice == "2":
142
+ u = input("Username: ")
143
+ p = input("Password: ")
144
+ t = input("User Type: ")
145
+ accounts = load_accounts()
146
+ accounts.append({
147
+ "username": u,
148
+ "password": p,
149
+ "sudo": "False",
150
+ "usertype": t,
151
+ "fs": {"files": [], "folders": {}}
152
+ })
153
+ save_accounts(accounts)
154
+ print("Account created")
155
+
156
+ elif choice == "3":
157
+ terminal({
158
+ "username": f"guest{random.randint(1000,9999)}",
159
+ "sudo": "False",
160
+ "usertype": "Guest",
161
+ "fs": {"files": [], "folders": {}}
162
+ })
163
+
164
+ elif choice == "4":
165
+ sys.exit()
166
+
167
+ # ---------- ENTRY ----------
168
+ if __name__ == "__main__":
169
+ main()
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: ArunCode_Term
3
+ Version: 0.1.0
4
+ Summary: Your project description
5
+ Author: Arun
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+
9
+ # ArunCode
10
+
11
+ Terminal simulator written in Python with JSON-backed users.
@@ -0,0 +1,9 @@
1
+ README.md
2
+ pyproject.toml
3
+ ArunCode_Term/__init__.py
4
+ ArunCode_Term/main.py
5
+ ArunCode_Term.egg-info/PKG-INFO
6
+ ArunCode_Term.egg-info/SOURCES.txt
7
+ ArunCode_Term.egg-info/dependency_links.txt
8
+ ArunCode_Term.egg-info/top_level.txt
9
+ ArunCode_Term/Data/__init__.py
@@ -0,0 +1 @@
1
+ ArunCode_Term
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: ArunCode_Term
3
+ Version: 0.1.0
4
+ Summary: Your project description
5
+ Author: Arun
6
+ Requires-Python: >=3.8
7
+ Description-Content-Type: text/markdown
8
+
9
+ # ArunCode
10
+
11
+ Terminal simulator written in Python with JSON-backed users.
@@ -0,0 +1,3 @@
1
+ # ArunCode
2
+
3
+ Terminal simulator written in Python with JSON-backed users.
@@ -0,0 +1,16 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "ArunCode_Term"
7
+ version = "0.1.0"
8
+ description = "Your project description"
9
+ authors = [{name="Arun"}]
10
+ readme = "README.md"
11
+ requires-python = ">=3.8"
12
+ dependencies = []
13
+
14
+ [tool.setuptools.packages.find]
15
+ where = ["."]
16
+ include = ["ArunCode_Term*"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+