Browse Source

working directory tracking

closes #1
master
Samuel Sloniker 1 year ago
parent
commit
2f6ddb49ec
Signed by: kj7rrv
GPG Key ID: 1BB4029E66285A62
  1. 2
      bin/init.py
  2. 7
      bin/ls.py
  3. 4
      bin/ps.py
  4. 10
      bin/pwd.py
  5. 6
      bin/sh.py
  6. 20
      fibonaccios/__init__.py
  7. 4
      lib/console.py

2
bin/init.py

@ -7,7 +7,7 @@ def get_app_class(template):
lines = f.readlines()
for line in lines:
if line.strip():
last_pid = self.os.launch(*shlex.split(line))
last_pid = self.launch(*shlex.split(line))
self.transfer_console(last_pid)
self.next_function = 'loop'

7
bin/ls.py

@ -1,4 +1,5 @@
import os
import console
def get_app_class(template):
class App(template):
@ -10,13 +11,13 @@ def get_app_class(template):
try:
for file in os.listdir(path):
self.console.write(file)
console.write_str(self.console, file + "\n")
except OSError as e:
try:
os.stat(path)
self.console.write(path)
console.write_str(self.console, path + "\n")
except OSError:
self.console.write(f"ls: cannot access '{path}': No such file or directory")
console.write_str(self.console, f"ls: cannot access '{path}': No such file or directory\n")
self.exit()

4
bin/ps.py

@ -1,3 +1,5 @@
import console
def get_app_class(template):
class App(template):
def F_main(self):
@ -5,7 +7,7 @@ def get_app_class(template):
for pid, app in apps.items():
args = app.argv[1:]
name = app.name
self.console.write(f'{pid} {name} {args}')
console.write_str(self.console, f'{pid} {name} {args}\n')
self.exit()
return App

10
bin/pwd.py

@ -0,0 +1,10 @@
import os
import console
def get_app_class(template):
class App(template):
def F_main(self):
console.write_str(self.console, os.getcwd() + "\n")
self.exit()
return App

6
bin/sh.py

@ -19,11 +19,13 @@ def get_app_class(template):
if line:
try:
if line[0] == 'bg':
self.os.launch(*line[1:])
self.launch(*line[1:])
elif line[0] == 'cd':
self.chdir(line[1])
elif line[0] == 'exit':
self.exit()
else:
pid = self.os.launch(*line)
pid = self.launch(*line)
self.wait(pid)
self.transfer_console(pid)
except fibonaccios.exceptions.AppNotFound as e:

20
fibonaccios/__init__.py

@ -5,19 +5,22 @@ from fibonaccios.apploader import get_app
import fibonaccios.apploader # apploader hack
import time
import usb_cdc
import os
class App:
def __init__(self, os, pid, name, *argv):
def __init__(self, os, pid, name, wd, *argv):
self.os = os
self.pid = pid
self.name = name
self.store = {}
self.next_function = 'main'
self.run_at = -1
self.wd = wd
self.argv = (self,) + argv
self.waiting_for = -1
def iterate(self):
os.chdir(self.wd)
if time.monotonic() >= self.run_at and not self.waiting_for in self.os.apps:
getattr(self, f'F_{self.next_function}')()
@ -34,6 +37,10 @@ class App:
else:
raise NotConsoleController(self.os.controllers[-1])
def chdir(self, wd):
os.chdir(wd)
self.wd = os.getcwd()
def jump(self, function):
self.next_function = function
@ -41,7 +48,10 @@ class App:
self.run_at = time.monotonic() + seconds
def exec(self, command, *argv):
self.os.apps[self.pid] = get_app(command)(self.os, self.pid, command, *argv)
self.os.apps[self.pid] = get_app(command)(self.os, self.pid, command, self.wd, *argv)
def launch(self, command, *argv):
return self.os.launch(command, self.wd, *argv)
def wait(self, pid):
self.waiting_for = pid
@ -65,7 +75,7 @@ class OS:
self.console = usb_cdc.console
usb_cdc.console.timeout = 0
self.next_pidi = 0
self.launch('init')
self.launch('init', '/')
def iterate(self):
pid = list(self.apps.keys())[self.next_pidi]
@ -87,8 +97,8 @@ class OS:
while not self.controllers[-1] in self.apps.keys():
self.controllers.pop()
def launch(self, app, *argv):
self.apps[self.next_new] = get_app(app)(self, self.next_new, app, *argv)
def launch(self, app, wd, *argv):
self.apps[self.next_new] = get_app(app)(self, self.next_new, app, wd, *argv)
self.next_new += 1
return self.next_new - 1

4
lib/console.py

@ -15,3 +15,7 @@ def read(console, buffer):
buffer.append(char)
else:
return None
def write_str(console, string, encoding="utf-8"):
console.write(string.encode(encoding))

Loading…
Cancel
Save