__init__.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. import importlib
  2. import re
  3. from colorama import Fore
  4. from glob import glob
  5. from toolset.utils.output_helper import log
  6. databases = {}
  7. db_folders = glob("/FrameworkBenchmarks/toolset/databases/*/")
  8. # Loads all the databases from the folders in this directory
  9. # and checks to see if they've implemented the required methods
  10. for folder in db_folders:
  11. # regex that grabs the characters between "toolset/database/"
  12. # and the final "/" in the db folder string to get the db name
  13. db_name = re.findall(r'.+\/(.+)\/$', folder, re.M)[0]
  14. # ignore generated __pycache__ folder
  15. if db_name == '__pycache__':
  16. continue
  17. spec = importlib.util.spec_from_file_location("Database", "%s%s.py" % (folder, db_name))
  18. db = importlib.util.module_from_spec(spec)
  19. spec.loader.exec_module(db)
  20. if not hasattr(db.Database, "get_current_world_table")\
  21. or not hasattr(db.Database, "test_connection"):
  22. log("Database %s does not implement the required methods" % (db_name),
  23. color=Fore.RED)
  24. databases[db_name] = db.Database