Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to execute local python script if command is not a user command #2

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("______________________________________________")
Expand All @@ -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")
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\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/")

Expand All @@ -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:
Expand Down