Skip to content
Open
Show file tree
Hide file tree
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
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pyOS (prounounced "pious") is a python implemention of a psuedo unix-like operat

Requirements
-------------
- Python 2.7+
- Python 3.5+

Features
--------
Expand Down Expand Up @@ -36,4 +36,16 @@ Todo
Setup
-----
- cd into the pyOS directory
- run pyOS.py
- run pyOS.py
- Username: root
- Password: pass

```text
> python ./pyOS.py
STARTING
root x has permisison for /programs/login.py
user: root
password:
root x has permisison for /programs/interpreter.py
root@pyOS:/$
```
2 changes: 1 addition & 1 deletion documents/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

def run(shell, args):
for line in shell.stdin.read():
print line
print(line)
time.sleep(1*random.random())

def help():
Expand Down
2 changes: 1 addition & 1 deletion documents/producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import random

def run(shell, args):
for x in xrange(20):
for x in range(20):
shell.stdout.write(str(x))
time.sleep(1*random.random())

Expand Down
12 changes: 9 additions & 3 deletions kernel/filesystem.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import shutil
import imp
import glob

import importlib.util
from kernel.constants import BASEPATH

def abs_path(path):
Expand Down Expand Up @@ -91,7 +90,14 @@ def open_program(path):
x = abs_path(path)
if not is_dir(path):
try:
program = imp.load_source('program', x)

spec = importlib.util.spec_from_file_location("program", x)
if not spec:
return

program = importlib.util.module_from_spec(spec)
spec.loader.exec_module(program)

except IOError:
program = False
else:
Expand Down
6 changes: 3 additions & 3 deletions kernel/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sqlite3

from kernel.constants import METADATAFILE
from kernel.utils import calc_permission_number, calc_permission_string
from kernel.utils import calc_permission_number
from kernel.utils import convert_many

def build_meta_data_database(fsmatches):
Expand Down Expand Up @@ -49,7 +49,7 @@ def get_meta_data(path):
data = cur.fetchone()
if data:
## force data to be strings and not unicode
data = tuple(str(x) if type(x) == unicode else x for x in data)
data = tuple(str(x) if type(x) == str else x for x in data)
return data

def get_all_meta_data(path='/'):
Expand All @@ -62,7 +62,7 @@ def get_all_meta_data(path='/'):
data = cur.fetchall()
if data:
## force data to be strings and not unicode
data = [tuple(str(x) if type(x) == unicode else x for x in row) for row in data]
data = [tuple(str(x) if type(x) == str else x for x in row) for row in data]
return data

def add_path(path, owner, permission):
Expand Down
1 change: 0 additions & 1 deletion kernel/shell.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import re
import threading

import kernel.stream
Expand Down
2 changes: 1 addition & 1 deletion kernel/shutdown.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def run():
print "SHUTTING DOWN"
print("SHUTTING DOWN")
2 changes: 1 addition & 1 deletion kernel/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import kernel.userdata

def run():
print "STARTING"
print("STARTING")
kernel.userdata.build_user_data_database()
kernel.metadata.build_meta_data_database(kernel.filesystem.list_all('/'))

4 changes: 2 additions & 2 deletions kernel/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(self, name='', value=None, writer=None, reader=None):
self._line = 0
self.closed = False

def __nonzero__(self):
def __bool__(self):
return bool(self.reader)

def set_reader(self, callback):
Expand Down Expand Up @@ -58,7 +58,7 @@ def broadcast(self):
pass # self.reader()
else:
if any(self.value):
print "<%s> %s" % (self.name, '\n'.join(self.value[:-1])),
print("<%s> %s" % (self.name, '\n'.join(self.value[:-1])), end=' ')

def __repr__(self):
return "<Pipe(name=%s, value=%s, writer=%d, reader=%d)>" % (
Expand Down
4 changes: 2 additions & 2 deletions kernel/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ def wrapper(self, *args, **kwargs):
if laccess.isdigit():
laccess = list(set(args[int(laccess)]) & {'r', 'w'})[0]
if has_permission(path, 'root', laccess):
print "root %s has permisison for %s" % (laccess, path)
print("root %s has permisison for %s" % (laccess, path))
else:
print "root %s permission denied for %s" % (laccess, path)
print("root %s permission denied for %s" % (laccess, path))
return function(self, *args, **kwargs)
return wrapper
return real_decorator
Expand Down
4 changes: 2 additions & 2 deletions kernel/userdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_user_data(user):
data = cur.fetchone()
if data:
## force data to be strings and not unicode
data = tuple(str(x) if type(x) == unicode else x for x in data)
data = tuple(str(x) if type(x) == str else x for x in data)
return data

def get_all_user_data():
Expand All @@ -49,7 +49,7 @@ def get_all_user_data():
data = cur.fetchall()
if data:
## force data to be strings and not unicode
data = [tuple(str(x) if type(x) == unicode else x for x in row) for row in data]
data = [tuple(str(x) if type(x) == str else x for x in row) for row in data]
return data

#######################################
Expand Down
4 changes: 2 additions & 2 deletions programs/head.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ def run(shell, args):
shell.stdout.write("==> %s <==" % (x, ))
try:
f = shell.syscall.open_file(path, 'r')
for x in xrange(args.lineamount):
for x in range(args.lineamount):
shell.stdout.write(f.readline().rstrip())
f.close()
except IOError:
shell.stderr.write("%s does not exist" % (path))
if shell.stdin:
if args.paths:
shell.stdout.write("==> %% stdin %% <==")
for x in xrange(args.lineamount):
for x in range(args.lineamount):
shell.stdout.write(shell.stdin.readline())
shell.stdout.write("")
else:
Expand Down
2 changes: 1 addition & 1 deletion programs/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
def run(shell, args):
user = shell.get_var('USER')
while System.state >= RUNNING:
data = raw_input("%s@%s:%s$ "% (user, OSNAME, shell.get_path()))
data = input("%s@%s:%s$ "% (user, OSNAME, shell.get_path()))
data = data.strip()
if data:
cleaned, command = shell_expansion(shell, data)
Expand Down
4 changes: 2 additions & 2 deletions programs/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from kernel.system import System

def run(shell, args):
user = raw_input("user: ")
password = hashlib.sha256(getpass.getpass("password: ")).hexdigest()
user = input("user: ")
password = hashlib.sha256(getpass.getpass("password: ").encode('utf-8')).hexdigest()

if shell.syscall.correct_password(user, password): # == db(user).password
stuff = {
Expand Down
20 changes: 15 additions & 5 deletions programs/ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,32 @@ def ls(shell, relpath, args):
if a:
maxlen = max(max([len(x) for x in a]), 1)
# arbitrary line length
columns = (80 / maxlen) - 1
columns_max = 80
columns = (columns_max / maxlen) - 1
b = []
pos = 0
line = "\n"
to_add = ""
for i, x in enumerate(a):
newline = "\n" if not ((i + 1) % columns) else ""
if not ((i + 1) % columns):
newline = "\n"
spacing = ""
else:
newline = ""
spacing = " " * (maxlen - len(x) + 1)
b.append(x + spacing + newline)
shell.stdout.write(''.join(b).rstrip())
to_add = "%s%s%s" % (x, spacing, newline)
if pos < columns_max:
pos += len(to_add)
line += to_add
else:
b.append(line)
pos = 0
line = ""
shell.stdout.write("%s\n" % '\n'.join(b))
if len(args.paths) > 1:
shell.stdout.write("")
except OSError:
shell.stderr.write('ls: cannot acces %s: no such file or directory\n' % (relpath, ))
shell.stderr.write('ls: cannot access %s: no such file or directory\n' % (relpath, ))

def help():
return parser.help_msg()
6 changes: 3 additions & 3 deletions programs/sed.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@ def help():
{ commands } group of commands
s s/regex/replacement/flags
replacement
\L turn replacement lowercase until \U or \E
\L turn replacement lowercase until \\U or \E
\l turn the next char lowercase
\U turn replacement uppercase until \L or \E
\u turn the next char to uppercase
\\U turn replacement uppercase until \L or \E
\\u turn the next char to uppercase
\E Stop case conversion
\[n] number of inclusions
& matched pattern
Expand Down
2 changes: 1 addition & 1 deletion programs/tee.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def run(shell, args):
f.close()
else:
for line in shell.stdin.read():
print line
print(line)
shell.stdout.write(line)

def help():
Expand Down
2 changes: 1 addition & 1 deletion pyOS.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from kernel.system import System

if __name__ == '__main__':
System.run()
System.run()