Compare commits
No commits in common. "95011656f07ce6cb423f0ae3dd5922046e82aaa3" and "163b0093a03f2ded22336410e7ad95551b3ea072" have entirely different histories.
95011656f0
...
163b0093a0
5
bin/__init__.py
Normal file
5
bin/__init__.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import os
|
||||||
|
|
||||||
|
imports = [ i[:-3] for i in os.listdir('/bin/') if i.endswith('.py') and not '__' in i ]
|
||||||
|
for module in imports:
|
||||||
|
exec(f'import bin.{module} as {module}')
|
6
bin/background.py
Normal file
6
bin/background.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import circuitos
|
||||||
|
|
||||||
|
class App(circuitos.App):
|
||||||
|
def F_main(self):
|
||||||
|
self.os.launch(*self.argv[1:])
|
||||||
|
self.exit()
|
|
@ -1,7 +1,7 @@
|
||||||
|
import circuitos
|
||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
def get_app_class(template):
|
class App(circuitos.App):
|
||||||
class App(template):
|
|
||||||
def F_main(self):
|
def F_main(self):
|
||||||
with open('/etc/init/start') as f:
|
with open('/etc/init/start') as f:
|
||||||
lines = f.readlines()
|
lines = f.readlines()
|
||||||
|
@ -14,5 +14,3 @@ def get_app_class(template):
|
||||||
|
|
||||||
def F_loop(self):
|
def F_loop(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return App
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
def get_app_class(template):
|
import circuitos
|
||||||
class App(template):
|
|
||||||
|
class App(circuitos.App):
|
||||||
def F_main(self):
|
def F_main(self):
|
||||||
self.os.kill(int(self.argv[1]))
|
self.os.kill(int(self.argv[1]))
|
||||||
self.exit()
|
self.exit()
|
||||||
|
|
||||||
return App
|
|
||||||
|
|
10
bin/ls.py
10
bin/ls.py
|
@ -1,10 +0,0 @@
|
||||||
import os
|
|
||||||
|
|
||||||
def get_app_class(template):
|
|
||||||
class App(template):
|
|
||||||
def F_main(self):
|
|
||||||
for file in os.listdir(self.argv[1]):
|
|
||||||
print(file)
|
|
||||||
self.exit()
|
|
||||||
|
|
||||||
return App
|
|
|
@ -1,5 +1,6 @@
|
||||||
def get_app_class(template):
|
import circuitos
|
||||||
class App(template):
|
|
||||||
|
class App(circuitos.App):
|
||||||
def F_main(self):
|
def F_main(self):
|
||||||
apps = self.os.apps
|
apps = self.os.apps
|
||||||
for pid, app in apps.items():
|
for pid, app in apps.items():
|
||||||
|
@ -7,5 +8,3 @@ def get_app_class(template):
|
||||||
name = app.name
|
name = app.name
|
||||||
print(f'{pid} {name} {args}')
|
print(f'{pid} {name} {args}')
|
||||||
self.exit()
|
self.exit()
|
||||||
|
|
||||||
return App
|
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import circuitos.exceptions
|
import circuitos
|
||||||
import shlex
|
import shlex
|
||||||
import console
|
import console
|
||||||
|
|
||||||
def get_app_class(template):
|
class App(circuitos.App):
|
||||||
class App(template):
|
|
||||||
def F_main(self):
|
def F_main(self):
|
||||||
self.jump('prompt')
|
self.jump('prompt')
|
||||||
|
|
||||||
|
@ -26,10 +25,9 @@ def get_app_class(template):
|
||||||
pid = self.os.launch(*line)
|
pid = self.os.launch(*line)
|
||||||
self.wait(pid)
|
self.wait(pid)
|
||||||
self.transfer_console(pid)
|
self.transfer_console(pid)
|
||||||
except circuitos.exceptions.AppNotFound as e:
|
except circuitos.AppNotFound as e:
|
||||||
print('error: app not found')
|
print('error: app not found')
|
||||||
self.jump('prompt')
|
self.jump('prompt')
|
||||||
|
|
||||||
def F_loop(self):
|
def F_loop(self):
|
||||||
pass
|
pass
|
||||||
return App
|
|
||||||
|
|
|
@ -1,106 +0,0 @@
|
||||||
import bin #this is at the end of the script in case any functions from bin
|
|
||||||
#depend on anything here
|
|
||||||
from circuitos.exceptions import *
|
|
||||||
from circuitos.apploader import get_app
|
|
||||||
import circuitos.apploader # apploader hack
|
|
||||||
import time
|
|
||||||
import usb_cdc
|
|
||||||
|
|
||||||
class App:
|
|
||||||
def __init__(self, os, pid, name, *argv):
|
|
||||||
self.os = os
|
|
||||||
self.pid = pid
|
|
||||||
self.name = name
|
|
||||||
self.store = {}
|
|
||||||
self.next_function = 'main'
|
|
||||||
self.run_at = -1
|
|
||||||
self.argv = (self,) + argv
|
|
||||||
self.waiting_for = -1
|
|
||||||
|
|
||||||
def iterate(self):
|
|
||||||
if time.monotonic() >= self.run_at and not self.waiting_for in self.os.apps:
|
|
||||||
getattr(self, f'F_{self.next_function}')()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def console(self):
|
|
||||||
if self.pid == self.os.controllers[-1]:
|
|
||||||
return self.os.console
|
|
||||||
else:
|
|
||||||
raise NotConsoleController(self.os.controllers[-1])
|
|
||||||
|
|
||||||
def transfer_console(self, recipient):
|
|
||||||
if self.pid == self.os.controllers[-1]:
|
|
||||||
self.os.controllers.append(recipient)
|
|
||||||
else:
|
|
||||||
raise NotConsoleController(self.os.controllers[-1])
|
|
||||||
|
|
||||||
def jump(self, function):
|
|
||||||
self.next_function = function
|
|
||||||
|
|
||||||
def sleep(self, seconds):
|
|
||||||
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)
|
|
||||||
|
|
||||||
def wait(self, pid):
|
|
||||||
self.waiting_for = pid
|
|
||||||
|
|
||||||
def end_wait(self):
|
|
||||||
self.waiting_for = -1
|
|
||||||
|
|
||||||
def on_exit(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def exit(self):
|
|
||||||
del self.os.apps[self.pid]
|
|
||||||
|
|
||||||
apploader.App = App # apploader hack
|
|
||||||
|
|
||||||
class OS:
|
|
||||||
def __init__(self):
|
|
||||||
self.apps = {}
|
|
||||||
self.next_new = 0
|
|
||||||
self.controllers = [0]
|
|
||||||
self.console = usb_cdc.console
|
|
||||||
usb_cdc.console.timeout = 0
|
|
||||||
self.next_pidi = 0
|
|
||||||
self.launch('init')
|
|
||||||
|
|
||||||
def iterate(self):
|
|
||||||
pid = list(self.apps.keys())[self.next_pidi]
|
|
||||||
function = self.apps[pid].iterate
|
|
||||||
|
|
||||||
function()
|
|
||||||
|
|
||||||
try:
|
|
||||||
self.apps[pid]
|
|
||||||
# If this succeds, the app did not exit and next_pidi should
|
|
||||||
# be incremented
|
|
||||||
self.next_pidi += 1
|
|
||||||
except KeyError:
|
|
||||||
# If self.apps[pid] failed, the app exited and next_pidi
|
|
||||||
# should not be incremented
|
|
||||||
pass
|
|
||||||
self.next_pidi = self.next_pidi % len(self.apps)
|
|
||||||
|
|
||||||
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)
|
|
||||||
self.next_new += 1
|
|
||||||
return self.next_new - 1
|
|
||||||
|
|
||||||
def kill(self, pid):
|
|
||||||
try:
|
|
||||||
del self.apps[pid]
|
|
||||||
except KeyError:
|
|
||||||
raise(NoSuchProcess(pid))
|
|
||||||
|
|
||||||
def run():
|
|
||||||
os = OS()
|
|
||||||
while True:
|
|
||||||
os.iterate()
|
|
||||||
|
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
_cache = {}
|
|
||||||
|
|
||||||
def get_app(app):
|
|
||||||
try:
|
|
||||||
return _cache[app]
|
|
||||||
except KeyError:
|
|
||||||
try:
|
|
||||||
module = __import__(f'/bin/{app}')
|
|
||||||
except AttributeError:
|
|
||||||
raise AppNotFound(app)
|
|
||||||
|
|
||||||
try:
|
|
||||||
app_class = module.get_app_class(App)
|
|
||||||
except AttributeError:
|
|
||||||
raise InvalidApp(app)
|
|
||||||
|
|
||||||
_cache[app] = app_class
|
|
||||||
|
|
||||||
return app_class
|
|
|
@ -1,18 +0,0 @@
|
||||||
class CircuitOSError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NoSuchProcess(CircuitOSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class AppNotFound(CircuitOSError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class InvalidApp(AppNotFound):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
class NotConsoleController(CircuitOSError):
|
|
||||||
pass
|
|
Loading…
Reference in New Issue
Block a user