From 03b55c5d2b4423894d114400a74697ef5d5b072d Mon Sep 17 00:00:00 2001 From: Reppad Date: Wed, 12 Jul 2023 17:48:52 +0200 Subject: [PATCH] trying to execute local python script if command is not a user command --- main.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 4f603ef..1ec6c7d 100644 --- a/main.py +++ b/main.py @@ -43,7 +43,7 @@ def boot(self): else: self.user_commands[command]() else: - self.unknown_function() + self.try_exec_script(command) def banner(self): print("______________________________________________") @@ -65,7 +65,7 @@ def welcome(self): def help(self): print(self.name+ " Version "+self.version+" user commands:\n") - print("\t`ls` - list files\n\t`cat filename` - print file\n\t`info filename` - info about selected file\n\t`rm filename` - remove file\n\t`ed filename` - text editor\n\t`banner` - system banner\n\t`cls` - clear screen\n\t`mhz` 160 - set CPU speed (80-160) in MHz\n\t`stats` - hardware and software information\n\t`reboot` - reboot the system") + print("\t`ls` - list files\n\t`cat filename` - print file\n\t`info filename` - info about selected file\n\t`rm filename` - remove file\n\t`ed filename` - text editor\n\t`banner` - system banner\n\t`cls` - clear screen\n\t`mhz` 160 - set CPU speed (80-160) in MHz\n\t`stats` - hardware and software information\n\t`reboot` - reboot the system\n\tYou can also run any Python script by typing its filename without `.py`") print("\nSystem created by Krzysztof Krystian Jankowski") print("Code available at github and smol.p1x.in/os/") @@ -78,6 +78,13 @@ def print_msg(self, message): def unknown_function(self): self.print_err("unknown function. Try 'help'.") + def try_exec_script(self,command): + if command+'.py' in uos.listdir(): + command = "import " + command + exec(command) + else: + self.unknown_function() + def set_cpu_mhz(self,freq="80"): freq = int(freq) if freq >= 80 and freq <= 160: