-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand_loader.py
55 lines (47 loc) · 1.58 KB
/
command_loader.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
import os
from importlib import import_module
from compiler import compile
def load(client):
wd = os.getcwd()
# set up native commands
folder_path = wd + '/commands'
error_module = []
filelist = [f for f in os.listdir(folder_path) if f.endswith('.py')]
for file in filelist:
filename = file[:-3]
print('Loading: ' + filename)
# try:
# load and set up function
command_module = import_module('commands.' + filename)
command_module.setup(client)
# except:
# print("An error has occured")
# error_module += [filename]
# compile user code
files = [ f[:-3] for f in os.listdir(wd + '/user_src') if f.endswith('.py')]
if not 'DONTFUCKINGTOUCHTHIS' in os.listdir():
os.system('mkdir DONTFUCKINGTOUCHTHIS')
for filename in files:
print('Compling: ' + filename)
compile(filename,wd + '/user_src/{}.py'.format(filename), wd + '/DONTFUCKINGTOUCHTHIS/{}.py'.format(filename))
# set up user command
folder_path = wd + '/DONTFUCKINGTOUCHTHIS'
filelist = [f for f in os.listdir(folder_path) if f.endswith('.py')]
for file in filelist:
filename = file[:-3]
print('Loading: ' + filename)
try:
# load and set up function
command_module = import_module('DONTFUCKINGTOUCHTHIS.' + filename)
command_module.setup(client)
except:
print("An error has occured")
error_module += [filename]
# try:
command_module = import_module('grader.main')
command_module.setup(client)
# print('Loaded: Grader')
# except:
# print('Failed to load: Grader')
# error_module += ['Grader']
return error_module