did some shi and finished two commands and a basic structure
This commit is contained in:
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Ignore every __pycache__ folder regardless of where it is
|
||||||
|
**/__pycache__/
|
||||||
|
|
||||||
|
# Ignore all compiled python files
|
||||||
|
*.pyc
|
||||||
50
bugpy-mos-0.py
Normal file
50
bugpy-mos-0.py
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# BUGS-Python Mock Operating System Version 0 "Devvie"
|
||||||
|
from scripts.list_files import list_files
|
||||||
|
from scripts.say_greeting import say_greeting
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Shitty test
|
||||||
|
# list_files.main()
|
||||||
|
|
||||||
|
|
||||||
|
def get_config_line(keyword):
|
||||||
|
# 1. Find the project root relative to this script
|
||||||
|
# Adjust the number of .parent calls based on where this function lives!
|
||||||
|
# If this is in main.py, it's just Path(__file__).parent
|
||||||
|
base_dir = Path(__file__).resolve().parent
|
||||||
|
config_file = base_dir / "config" / "pointerfile.txt"
|
||||||
|
|
||||||
|
if not config_file.exists():
|
||||||
|
return f"Error: {config_file} not found."
|
||||||
|
|
||||||
|
# 2. Open and search
|
||||||
|
with config_file.open("r") as f:
|
||||||
|
for line in f:
|
||||||
|
# .strip() removes whitespace/newlines
|
||||||
|
if line.strip().startswith(keyword):
|
||||||
|
parsed = line.strip().split(": ")
|
||||||
|
return [parsed[0], parsed[1]]
|
||||||
|
|
||||||
|
return None # Return None if keyword isn't found
|
||||||
|
|
||||||
|
def match_command(command):
|
||||||
|
if command == "list_files":
|
||||||
|
list_files.main()
|
||||||
|
elif command == "say_greeting":
|
||||||
|
say_greeting.main()
|
||||||
|
# use if else if else if else if to match the output
|
||||||
|
|
||||||
|
def cmdrun(keyword):
|
||||||
|
get_config_result = get_config_line(keyword)
|
||||||
|
if not get_config_result == None:
|
||||||
|
match_command(get_config_result[1])
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
print(get_config_line("dir"))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
print("BUGPy-mOS 0 \"Devvie\"")
|
||||||
|
while True:
|
||||||
|
inputs = input("BUGS > ")
|
||||||
|
cmdrun(inputs)
|
||||||
8
config/pointerfile.txt
Normal file
8
config/pointerfile.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
dir: list_files
|
||||||
|
ls: list_files
|
||||||
|
list_files: list_files
|
||||||
|
hi: say_greeting
|
||||||
|
hello: say_greeting
|
||||||
|
greeting: say_greeting
|
||||||
|
greetings: say_greeting
|
||||||
|
say_greeting: say_greeting
|
||||||
0
scripts/__init__.py
Normal file
0
scripts/__init__.py
Normal file
0
scripts/list_files/__init__.py
Normal file
0
scripts/list_files/__init__.py
Normal file
0
scripts/list_files/config.txt
Normal file
0
scripts/list_files/config.txt
Normal file
15
scripts/list_files/list_files.py
Normal file
15
scripts/list_files/list_files.py
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
def main():
|
||||||
|
# Set the directory path
|
||||||
|
script_dir = Path(__file__).resolve().parent
|
||||||
|
dir_path = Path("")
|
||||||
|
|
||||||
|
# Use the current script's directory or specify a path
|
||||||
|
base_path = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
for entry in dir_path.iterdir():
|
||||||
|
if entry.is_dir():
|
||||||
|
print(f"[FOLDER] {entry.name}")
|
||||||
|
elif entry.is_file():
|
||||||
|
print(f"[FILE] {entry.name}")
|
||||||
0
scripts/say_greeting/__init__.py
Normal file
0
scripts/say_greeting/__init__.py
Normal file
2
scripts/say_greeting/say_greeting.py
Normal file
2
scripts/say_greeting/say_greeting.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def main():
|
||||||
|
print("Hi!")
|
||||||
Reference in New Issue
Block a user