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.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

project_reader.py 1.7KB

4 anos atrás
4 anos atrás
4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142
  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.items():
  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()