Files
  • main.py
  • models.py
  • requirements.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

# Okay, this is EPIC
#  _______________________________________
# /                                       \
# |                                       |
# |      The pyNIX Operating System       |
# |                                       |
# \_______________________________________/
#
#
# Visit the website for the documentation : 
#
# Check out the package manager :

# TODO: mongodb

# The Package Importer (credits to https://stackoverflow.com/questions/18747043/import-python-module-over-the-internet-multiple-protocols-or-dynamically-create)
# Make the package importer

from requests import get
from imp import new_module
from models import *
def pkg_add(pkg_name):
	root = 'http://pynix--a5rocks.repl.co/pkg-control/'
	package_valid = get(f'{root}{pkg_name}/valid').text
	if package_valid == 'True':
		package_code = get(f'{root}{pkg_name}/pkg.py').text
		pkg_module = new_module(pkg_name)
		exec(package_code, pkg_module.__dict__)
		return pkg_module
	else:
		raise ValueError

# Initialization
user = User()
pkgs = []
command_list = {}
default_pkgs = ['authentication', 'filesystem']

for pkg in default_pkgs:
	pkgs.append(pkg_add(pkg))
	command_list.update(pkgs[-1].commands)

# The loop behind the OS
while True:
	command_and_args = input(f'@{user.username}: ')
	command = command_and_args.split(' ')[0].lower()
	args = command_and_args.split(' ')[1:]
	command_context = Context(user, command_and_args)

	# Package control first
	if command == 'pkg':
		if args == []:
			print('You entered nothing!')
		elif args[0] == 'add':
			if len(args) == 1:
				print('Please include a package to add')
			else:
				try:
					pkgs.append(pkg_add(args[1]))
				except:
					print(f'\'{args[1]}\' is not an available package. Run \'pkg list\' to get all the available packages.')
				else:
					command_list.update(pkgs[-1].commands)
		elif args[0] == 'list':
			print(get('https://pynix--a5rocks.repl.co/pkg-control/list/source.txt').text)
		elif args[0] == 'current':
			print('\n'.join([str(pkg) for pkg in pkgs]))
	elif command in command_list:
		try:
			print(command_list[command](command_context))
		except Exception as e:
			print(f'\'{command}\' failed because of:\n{e}')
	else:
		print(f'\'{command}\' is not a loaded command.')
	print('')