__init__.py 959 B

123456789101112131415161718192021222324252627
  1. import imp
  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 generate __pycache__ folder
  15. if db_name == '__pycache__':
  16. continue
  17. db = imp.load_source("Database", "%s%s.py" % (folder, db_name))
  18. if not hasattr(db.Database, "get_current_world_table")\
  19. or not hasattr(db.Database, "test_connection"):
  20. log("Database %s does not implement the required methods" + db_name,
  21. color=Fore.RED)
  22. databases[db_name] = db.Database