49 lines
1.6 KiB
Python
49 lines
1.6 KiB
Python
|
import importlib.util
|
||
|
import sys
|
||
|
import os
|
||
|
|
||
|
class loader():
|
||
|
def __init__(self, bar):
|
||
|
self.instructions = {}
|
||
|
self.loadedpaths = []
|
||
|
self.bar = bar
|
||
|
|
||
|
def RISloading(self, path, IR):
|
||
|
count = 0
|
||
|
for i in range(len(os.listdir(path))):
|
||
|
i = os.listdir(path)[i]
|
||
|
if os.path.isdir(path+"/"+i):
|
||
|
for f in os.listdir(path+"/"+i):
|
||
|
if os.path.isfile(path+"/"+i+"/"+f):
|
||
|
count += 1
|
||
|
else:
|
||
|
count += 1
|
||
|
stat = self.bar(count)
|
||
|
stat.__iter__()
|
||
|
for i in range(len(os.listdir(path))):
|
||
|
i = os.listdir(path)[i]
|
||
|
if os.path.isdir(path+"/"+i):
|
||
|
for f in os.listdir(path+"/"+i):
|
||
|
if os.path.isfile(path+"/"+i+"/"+f):
|
||
|
self.loadIS(path+"/"+i+"/"+f, IR)
|
||
|
stat.__next__()
|
||
|
else:
|
||
|
self.loadIS(path+"/"+i, IR)
|
||
|
stat.__next__()
|
||
|
try:
|
||
|
stat.__next__()
|
||
|
except StopIteration:
|
||
|
pass
|
||
|
|
||
|
|
||
|
def loadIS(self, path, IR):
|
||
|
spec = importlib.util.spec_from_file_location(os.path.basename(path), path)
|
||
|
module = importlib.util.module_from_spec(spec)
|
||
|
sys.modules[os.path.basename(path)] = module
|
||
|
spec.loader.exec_module(module)
|
||
|
try:
|
||
|
self.instructions[os.path.basename(path)] = module.main(IR)
|
||
|
except:
|
||
|
self.instructions[os.path.basename(path)] = module.main()
|
||
|
self.loadedpaths.append(path)
|