87 lines
2.7 KiB
Python
Executable File
87 lines
2.7 KiB
Python
Executable File
# BUGS-Python Mock Operating System Version 0 "Devvie"
|
|
from scripts.list_files import list_files
|
|
from scripts.say_greeting import say_greeting
|
|
from scripts.make_file import make_file
|
|
from scripts.touch_file import touch_file
|
|
from scripts.remove import remove
|
|
from scripts.help import help
|
|
from scripts.exit import exit
|
|
from scripts.make_directory import make_directory
|
|
from scripts.color_print import color_print
|
|
from scripts.p7c import p7c
|
|
from pathlib import Path
|
|
|
|
# Shitty test
|
|
# list_files.main()
|
|
|
|
if_verbose = 1
|
|
|
|
def verbose(strings):
|
|
if if_verbose == 1:
|
|
print(str(strings))
|
|
|
|
|
|
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
|
|
verbose(f"base_dir: {base_dir}")
|
|
config_file = base_dir / "config" / "pointerfile.txt"
|
|
|
|
if not config_file.exists():
|
|
color_print.cprint("Error", "DARKRED", sameline=True); print(": config file not found")
|
|
return None
|
|
|
|
# 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, args_list):
|
|
if command == "list_files":
|
|
list_files.main(args_list)
|
|
elif command == "say_greeting":
|
|
say_greeting.main(args_list)
|
|
elif command == "touch_file":
|
|
touch_file.main(args_list)
|
|
elif command == "make_file":
|
|
make_file.main(args_list)
|
|
elif command == "remove":
|
|
remove.main(args_list)
|
|
elif command == "help":
|
|
help.main(args_list)
|
|
elif command == "exit":
|
|
exit.main(args_list)
|
|
elif command == "make_directory":
|
|
make_directory.main(args_list)
|
|
elif command == "p7c":
|
|
p7c.main(args_list)
|
|
# use if else if else if else if to match the output
|
|
|
|
def cmdrun(keyword):
|
|
parsed = keyword.split()
|
|
verbose(parsed)
|
|
get_config_result = get_config_line(parsed[0])
|
|
verbose(get_config_result)
|
|
if not get_config_result == None:
|
|
match_command(get_config_result[1], parsed[1:])
|
|
return True
|
|
else:
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
print("\033[2J\033[H")
|
|
color_print.cprint("BUGPy-mOS 0 ", "GREEN", sameline=True); print("\"Devvie\"")
|
|
while True:
|
|
color_print.cprint("BUGS > ", "EMPHASIS", sameline=True)
|
|
inputs = input()
|
|
if not inputs.strip() == "":
|
|
if not cmdrun(inputs):
|
|
color_print.cprint("BAD COMMAND", "DARKRED")
|