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.

create-project.py 2.4KB

  1. import os, shutil
  2. import re
  3. print('Creation of a new simulation project...')
  4. ### Create the repository of the projects
  5. global_path = 'projects'
  6. os.makedirs(global_path, exist_ok=True)
  7. ### Get the project classname
  8. project_classname = ''
  9. search = re.compile(r'[^a-zA-Z0-9_]').search
  10. while not project_classname:
  11. classname = input(' - What is the project classname? ')
  12. if search(classname):
  13. print(' > Illegal characters detected! Please enter a name with only the following characters : a-z, A-Z, 0-9, and "_".')
  14. else:
  15. project_classname = classname.strip()
  16. ### Get and create the project repository
  17. search = re.compile(r'[^a-zA-Z0-9.-_/]').search
  18. project_repository = ''
  19. while not project_repository:
  20. repository = input(' - What is the project repository? ')
  21. if search(repository):
  22. print('Illegal characters detected! Please enter a name with only the following characters : a-z, A-Z, 0-9, ".", "-", "_" and "/".')
  23. else:
  24. try:
  25. os.makedirs(global_path+'/'+repository, exist_ok=False)
  26. project_repository = repository
  27. except FileExistsError:
  28. print('Error, a project with this repository already exists!')
  29. project_path = global_path+'/'+repository
  30. ### Add contents in the project
  31. files_from_ELMO = [
  32. 'Examples/elmoasmfunctions.o',
  33. 'Examples/elmoasmfunctions.s',
  34. 'Examples/elmoasmfunctionsdef.h',
  35. 'Examples/DPATraces/MBedAES/vector.o',
  36. ]
  37. files_from_templates = [
  38. 'elmoasmfunctionsdef-extension.h',
  39. 'Makefile',
  40. 'project.c'
  41. ]
  42. for filename in files_from_ELMO:
  43. shutil.copy('elmo/'+filename, project_path)
  44. for filename in files_from_templates:
  45. shutil.copy('templates/'+filename, project_path)
  46. shutil.copy('elmo/'+'Examples/DPATraces/MBedAES/MBedAES.ld', project_path+'/'+'project.ld')
  47. ### Create the project class
  48. with open('templates/projectclass.py') as _source:
  49. code = ''.join(_source.readlines())
  50. code = code.replace('{{PROJECTCLASSNAME}}', project_classname)
  51. with open(project_path+'/'+'projectclass.py', 'w') as _dest:
  52. _dest.write(code)
  53. print('')
  54. print('Creation complete !')
  55. print(' - Project repository: {}'.format(os.path.abspath(project_path)))
  56. print(' - Project class "{}" in {}'.format(project_classname, os.path.abspath(project_path+'/'+'projectclass.py')))
  57. print(' - Linker script: {}'.format(os.path.abspath(project_path+'/'+'project.ld')))
  58. print('')
  59. print('Please don\'t to compile the project with the present Makefile before using it!')