Python-ELMO is a Python library which offers an encapsulation of the binary tool ELMO, in order to manipulate it easily in Python and SageMath script.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

project_reader.py 1.7KB

  1. from project_base import SimulationProject
  2. import os, re
  3. import inspect
  4. PROJECTS_REPOSITORY = 'projects'
  5. class ProjectReader:
  6. def __init__(self):
  7. pass
  8. def get_projects(self):
  9. projects = {}
  10. for root, repositories, files in os.walk(PROJECTS_REPOSITORY):
  11. for filename in files:
  12. if re.fullmatch(r'.*project.*\.py', filename):
  13. # Encapsulation the project
  14. complete_filename = root+'/'+filename
  15. globals = {
  16. #'__builtins__': {'__build_class__': __build_class__},
  17. 'SimulationProject': SimulationProject,
  18. }
  19. locals = {}
  20. # Read the project code
  21. with open(complete_filename, 'r') as _file:
  22. project = '\n'.join(_file.readlines())
  23. exec(project, globals, locals)
  24. # Extract the simulations
  25. for key, obj in locals.item():
  26. if inspect.isclass(obj) and issubclass(obj, SimulationProject):
  27. if key in projects:
  28. print('Warning! Multiplie simulation with the same name. Simulation ignored: {} in {}'.format(key, complete_filename[len(PROJECTS_REPOSITORY)+1:]))
  29. else:
  30. obj.set_project_directory(root[len(PROJECTS_REPOSITORY)+1:])
  31. projects[key] = obj
  32. return projects
  33. def get_project_classes(self):
  34. return self.get_projects().values()