Prepare for refresh
This commit is contained in:
@@ -1,4 +1,34 @@
|
||||
from os.path import dirname, basename, isfile
|
||||
import glob
|
||||
modules = glob.glob(dirname(__file__)+"/*/ai.py")
|
||||
__all__ = ['.'.join(f.split('.')[:-1]) for f in modules if isfile(f)]
|
||||
from os.path import dirname, basename, isfile, getmtime
|
||||
from importlib import import_module
|
||||
from glob import glob
|
||||
|
||||
modules = glob(dirname(__file__)+"/*/ai.py")
|
||||
__all__ = []
|
||||
|
||||
class UploadedAi:
|
||||
def __init__(self, name, module, constructor, date):
|
||||
self.name = name
|
||||
self.module = module
|
||||
self.constructor = constructor
|
||||
self.date = date
|
||||
|
||||
for path in [f for f in modules if isfile(f)]:
|
||||
# Remove the .py
|
||||
toto = '.'.join(path.split('.')[:-1])
|
||||
|
||||
# Compute the name
|
||||
name = toto.split('/')[-2]
|
||||
|
||||
# Find the module
|
||||
module = import_module('.'.join(toto.split('/')[-3:]))
|
||||
|
||||
# Find the constructor
|
||||
constructor = getattr(module, 'Ai')
|
||||
|
||||
# Moment when the file was last modified
|
||||
date = getmtime(path)
|
||||
|
||||
# Append to the list of uploaded ais
|
||||
__all__.append(UploadedAi(name, module, constructor, date))
|
||||
|
||||
__all__ = sorted(__all__, key = lambda ai: ai.name)
|
||||
|
||||
Reference in New Issue
Block a user