Skip to content

Commit 5be4edc

Browse files
committed
fixed!!
1 parent 87c60c7 commit 5be4edc

File tree

7 files changed

+93
-171
lines changed

7 files changed

+93
-171
lines changed

Main.py

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
<<<<<<< Updated upstream
21
from file_system.virtual_fs import * # Import everything from virtual_fs.py
32

43
run = True
5-
=======
6-
from file_system import *
7-
8-
9-
>>>>>>> Stashed changes
104

115
def get_multiline_input(existing_content=""):
126
"""Function to get multiline input from the user, showing existing content."""
@@ -18,55 +12,13 @@ def get_multiline_input(existing_content=""):
1812
print(existing_content)
1913
print("\nYou can now modify the content. Continue editing...\n")
2014

21-
<<<<<<< Updated upstream
2215
content = []
2316
while True:
2417
line = input()
2518
if line.strip().upper() == "DONE": # If the user types DONE, stop collecting input
2619
break
2720
content.append(line)
2821
return "\n".join(content) # Join the content with newlines between each line
29-
=======
30-
def main():
31-
while True:
32-
command = input("Admin@Python-Terminal ~ % ").strip()
33-
if not command:
34-
continue
35-
36-
parts = command.split(" ", 1)
37-
cmd = parts[0].lower()
38-
arg = parts[1] if len(parts) > 1 else None
39-
40-
if cmd == "mkdir" and arg:
41-
print(create_folder(arg))
42-
elif cmd == "touch" and arg:
43-
print(create_file(arg))
44-
elif cmd == "ls":
45-
contents = list_contents()
46-
if isinstance(contents, list):
47-
print("\n".join(contents) if contents else "Directory is empty.")
48-
else:
49-
print(contents)
50-
elif cmd == "cat" and arg:
51-
print(cat(arg))
52-
elif cmd == "rm" and arg:
53-
print(delete_file(arg))
54-
elif cmd == "rmdir" and arg:
55-
print(delete_folder(arg))
56-
elif cmd == "cd" and arg:
57-
print(change_directory(arg))
58-
elif cmd == "cd ..":
59-
print(go_back())
60-
elif cmd == "pwd":
61-
print(print_working_directory())
62-
elif cmd == "help":
63-
display_help()
64-
elif cmd == "quit":
65-
print("Exiting the program. Goodbye!")
66-
break
67-
else:
68-
print(f"zsh: command not found: {command}")
69-
>>>>>>> Stashed changes
7022

7123
while run:
7224
user_input = input(f"Admin@Python-terminal {current_path} % ")
-6.15 KB
Binary file not shown.

file_system.py

Lines changed: 0 additions & 123 deletions
This file was deleted.

file_system/__init__.py

Whitespace-only changes.
194 Bytes
Binary file not shown.
3.68 KB
Binary file not shown.

file_system/virtual_fs.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Virtual filesystem definition
2+
virtual_fs = {
3+
"/": {"bin": {}, "boot": {}, "dev": {}, "etc": {}, "home": {}, "lib": {}, "media": {}, "mnt": {}, "opt": {}, "sbin": {}, "srv": {}, "tmp": {}, "usr": {}, "proc": {}},
4+
"/home": {"user": {}},
5+
"/home/user": {"file1.txt": "HelloWorld!", "documents": {}},
6+
"/var": {},
7+
"/tmp": {},
8+
}
9+
10+
current_path = "/"
11+
12+
def cd(path=None):
13+
"""Change the current directory in the virtual filesystem."""
14+
global current_path
15+
if not path or path.strip() == "":
16+
return
17+
elif path == "..":
18+
if current_path != "/":
19+
current_path = "/".join(current_path.rstrip("/").split("/")[:-1])
20+
if current_path == "":
21+
current_path = "/"
22+
elif path in virtual_fs.get(current_path, {}):
23+
if isinstance(virtual_fs[current_path][path], dict):
24+
current_path = current_path.rstrip("/") + "/" + path
25+
else:
26+
print(f"cd: no such file or directory: {path}")
27+
28+
def ls():
29+
"""List the contents of the current directory."""
30+
contents = virtual_fs.get(current_path, {})
31+
for item in contents:
32+
print(item)
33+
34+
def cat(filename):
35+
"""Simulate opening and reading a file."""
36+
global current_path
37+
current_dir_contents = virtual_fs.get(current_path, {})
38+
39+
if filename in current_dir_contents:
40+
if isinstance(current_dir_contents[filename], str):
41+
print(current_dir_contents[filename])
42+
else:
43+
print(f"cat: {filename}: Is a directory")
44+
else:
45+
print(f"cat: {filename}: No such file or directory")
46+
47+
def edit(filename, new_content):
48+
"""Simulate editing the content of a file."""
49+
global current_path
50+
current_dir_contents = virtual_fs.get(current_path, {})
51+
52+
if filename in current_dir_contents:
53+
if isinstance(current_dir_contents[filename], str):
54+
# Update the content of the file
55+
current_dir_contents[filename] = new_content
56+
print(f"File '{filename}' has been updated.")
57+
else:
58+
print(f"edit: {filename}: Is a directory")
59+
else:
60+
print(f"edit: {filename}: No such file or directory")
61+
62+
def pwd():
63+
print(current_path)
64+
65+
def mkdir(directory_name):
66+
"""Create a new directory in the current directory."""
67+
global current_path
68+
69+
# Get the current directory's contents
70+
current_dir_contents = virtual_fs.get(current_path, {})
71+
72+
# Check if the directory already exists
73+
if directory_name in current_dir_contents:
74+
print(f"mkdir: cannot create directory '{directory_name}': File exists")
75+
else:
76+
# Create the new directory as an empty dictionary
77+
current_dir_contents[directory_name] = {}
78+
print(f"Directory '{directory_name}' created.")
79+
80+
def touch(filename):
81+
"""Create a new empty text file in the current directory."""
82+
global current_path
83+
84+
# Get the current directory's contents
85+
current_dir_contents = virtual_fs.get(current_path, {})
86+
87+
# Check if the file already exists
88+
if filename in current_dir_contents:
89+
print(f"touch: cannot create file '{filename}': File exists")
90+
else:
91+
# Create the new file with empty content (represented as an empty string)
92+
current_dir_contents[filename] = ""
93+
print(f"File '{filename}' created.")

0 commit comments

Comments
 (0)