parent
4eee568840
commit
2f6ddb49ec
|
@ -7,7 +7,7 @@ def get_app_class(template):
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.strip():
|
if line.strip():
|
||||||
last_pid = self.os.launch(*shlex.split(line))
|
last_pid = self.launch(*shlex.split(line))
|
||||||
|
|
||||||
self.transfer_console(last_pid)
|
self.transfer_console(last_pid)
|
||||||
self.next_function = 'loop'
|
self.next_function = 'loop'
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import console
|
||||||
|
|
||||||
def get_app_class(template):
|
def get_app_class(template):
|
||||||
class App(template):
|
class App(template):
|
||||||
|
@ -10,13 +11,13 @@ def get_app_class(template):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for file in os.listdir(path):
|
for file in os.listdir(path):
|
||||||
self.console.write(file)
|
console.write_str(self.console, file + "\n")
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
try:
|
try:
|
||||||
os.stat(path)
|
os.stat(path)
|
||||||
self.console.write(path)
|
console.write_str(self.console, path + "\n")
|
||||||
except OSError:
|
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()
|
self.exit()
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import console
|
||||||
|
|
||||||
def get_app_class(template):
|
def get_app_class(template):
|
||||||
class App(template):
|
class App(template):
|
||||||
def F_main(self):
|
def F_main(self):
|
||||||
|
@ -5,7 +7,7 @@ def get_app_class(template):
|
||||||
for pid, app in apps.items():
|
for pid, app in apps.items():
|
||||||
args = app.argv[1:]
|
args = app.argv[1:]
|
||||||
name = app.name
|
name = app.name
|
||||||
self.console.write(f'{pid} {name} {args}')
|
console.write_str(self.console, f'{pid} {name} {args}\n')
|
||||||
self.exit()
|
self.exit()
|
||||||
|
|
||||||
return App
|
return App
|
||||||
|
|
10
bin/pwd.py
Normal file
10
bin/pwd.py
Normal file
|
@ -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
|
|
@ -19,11 +19,13 @@ def get_app_class(template):
|
||||||
if line:
|
if line:
|
||||||
try:
|
try:
|
||||||
if line[0] == 'bg':
|
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':
|
elif line[0] == 'exit':
|
||||||
self.exit()
|
self.exit()
|
||||||
else:
|
else:
|
||||||
pid = self.os.launch(*line)
|
pid = self.launch(*line)
|
||||||
self.wait(pid)
|
self.wait(pid)
|
||||||
self.transfer_console(pid)
|
self.transfer_console(pid)
|
||||||
except fibonaccios.exceptions.AppNotFound as e:
|
except fibonaccios.exceptions.AppNotFound as e:
|
||||||
|
|
|
@ -5,19 +5,22 @@ from fibonaccios.apploader import get_app
|
||||||
import fibonaccios.apploader # apploader hack
|
import fibonaccios.apploader # apploader hack
|
||||||
import time
|
import time
|
||||||
import usb_cdc
|
import usb_cdc
|
||||||
|
import os
|
||||||
|
|
||||||
class App:
|
class App:
|
||||||
def __init__(self, os, pid, name, *argv):
|
def __init__(self, os, pid, name, wd, *argv):
|
||||||
self.os = os
|
self.os = os
|
||||||
self.pid = pid
|
self.pid = pid
|
||||||
self.name = name
|
self.name = name
|
||||||
self.store = {}
|
self.store = {}
|
||||||
self.next_function = 'main'
|
self.next_function = 'main'
|
||||||
self.run_at = -1
|
self.run_at = -1
|
||||||
|
self.wd = wd
|
||||||
self.argv = (self,) + argv
|
self.argv = (self,) + argv
|
||||||
self.waiting_for = -1
|
self.waiting_for = -1
|
||||||
|
|
||||||
def iterate(self):
|
def iterate(self):
|
||||||
|
os.chdir(self.wd)
|
||||||
if time.monotonic() >= self.run_at and not self.waiting_for in self.os.apps:
|
if time.monotonic() >= self.run_at and not self.waiting_for in self.os.apps:
|
||||||
getattr(self, f'F_{self.next_function}')()
|
getattr(self, f'F_{self.next_function}')()
|
||||||
|
|
||||||
|
@ -34,6 +37,10 @@ class App:
|
||||||
else:
|
else:
|
||||||
raise NotConsoleController(self.os.controllers[-1])
|
raise NotConsoleController(self.os.controllers[-1])
|
||||||
|
|
||||||
|
def chdir(self, wd):
|
||||||
|
os.chdir(wd)
|
||||||
|
self.wd = os.getcwd()
|
||||||
|
|
||||||
def jump(self, function):
|
def jump(self, function):
|
||||||
self.next_function = function
|
self.next_function = function
|
||||||
|
|
||||||
|
@ -41,7 +48,10 @@ class App:
|
||||||
self.run_at = time.monotonic() + seconds
|
self.run_at = time.monotonic() + seconds
|
||||||
|
|
||||||
def exec(self, command, *argv):
|
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):
|
def wait(self, pid):
|
||||||
self.waiting_for = pid
|
self.waiting_for = pid
|
||||||
|
@ -65,7 +75,7 @@ class OS:
|
||||||
self.console = usb_cdc.console
|
self.console = usb_cdc.console
|
||||||
usb_cdc.console.timeout = 0
|
usb_cdc.console.timeout = 0
|
||||||
self.next_pidi = 0
|
self.next_pidi = 0
|
||||||
self.launch('init')
|
self.launch('init', '/')
|
||||||
|
|
||||||
def iterate(self):
|
def iterate(self):
|
||||||
pid = list(self.apps.keys())[self.next_pidi]
|
pid = list(self.apps.keys())[self.next_pidi]
|
||||||
|
@ -87,8 +97,8 @@ class OS:
|
||||||
while not self.controllers[-1] in self.apps.keys():
|
while not self.controllers[-1] in self.apps.keys():
|
||||||
self.controllers.pop()
|
self.controllers.pop()
|
||||||
|
|
||||||
def launch(self, app, *argv):
|
def launch(self, app, wd, *argv):
|
||||||
self.apps[self.next_new] = get_app(app)(self, self.next_new, app, *argv)
|
self.apps[self.next_new] = get_app(app)(self, self.next_new, app, wd, *argv)
|
||||||
self.next_new += 1
|
self.next_new += 1
|
||||||
return self.next_new - 1
|
return self.next_new - 1
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,7 @@ def read(console, buffer):
|
||||||
buffer.append(char)
|
buffer.append(char)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def write_str(console, string, encoding="utf-8"):
|
||||||
|
console.write(string.encode(encoding))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user