diff --git a/bin/__init__.py b/bin/__init__.py new file mode 100644 index 0000000..1f7d74b --- /dev/null +++ b/bin/__init__.py @@ -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}') diff --git a/bin/background.py b/bin/background.py new file mode 100644 index 0000000..3403419 --- /dev/null +++ b/bin/background.py @@ -0,0 +1,6 @@ +import circuitos + +class App(circuitos.App): + def F_main(self): + self.os.launch(*self.argv[1:]) + self.exit() diff --git a/bin/init.py b/bin/init.py new file mode 100644 index 0000000..c2f017f --- /dev/null +++ b/bin/init.py @@ -0,0 +1,16 @@ +import circuitos +import shlex + +class App(circuitos.App): + def F_main(self): + with open('/etc/init/start') as f: + lines = f.readlines() + for line in lines: + if line.strip(): + last_pid = self.os.launch(*shlex.split(line)) + + self.transfer_console(last_pid) + self.next_function = 'loop' + + def F_loop(self): + pass diff --git a/bin/kill.py b/bin/kill.py new file mode 100644 index 0000000..8a71999 --- /dev/null +++ b/bin/kill.py @@ -0,0 +1,6 @@ +import circuitos + +class App(circuitos.App): + def F_main(self): + self.os.kill(int(self.argv[1])) + self.exit() diff --git a/bin/ps.py b/bin/ps.py new file mode 100644 index 0000000..e43d041 --- /dev/null +++ b/bin/ps.py @@ -0,0 +1,10 @@ +import circuitos + +class App(circuitos.App): + def F_main(self): + apps = self.os.apps + for pid, app in apps.items(): + args = app.argv[1:] + name = app.name + print(f'{pid} {name} {args}') + self.exit() diff --git a/bin/sh.py b/bin/sh.py new file mode 100644 index 0000000..6427fef --- /dev/null +++ b/bin/sh.py @@ -0,0 +1,33 @@ +import circuitos +import shlex +import console + +class App(circuitos.App): + def F_main(self): + self.jump('prompt') + + def F_prompt(self): + self.console.write(b'CicuitOS sh # ') + self.store['buf'] = [] + self.jump('input') + + def F_input(self): + raw_line = console.read(self.console, self.store['buf']) + if raw_line is not None: + line = shlex.split(raw_line.decode('ascii')) + if line: + try: + if line[0] == 'bg': + self.os.launch(*line[1:]) + elif line[0] == 'exit': + self.exit() + else: + pid = self.os.launch(*line) + self.wait(pid) + self.transfer_console(pid) + except circuitos.AppNotFound as e: + print('error: app not found') + self.jump('prompt') + + def F_loop(self): + pass diff --git a/code.py b/code.py new file mode 100644 index 0000000..ba71e58 --- /dev/null +++ b/code.py @@ -0,0 +1,2 @@ +import circuitos +circuitos.run() diff --git a/etc/init/start b/etc/init/start new file mode 100644 index 0000000..b001cf7 --- /dev/null +++ b/etc/init/start @@ -0,0 +1 @@ +sh