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.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

__main__.py 2.6KB

  1. import sys
  2. from .utils import Color
  3. if len(sys.argv) <= 1:
  4. print(Color.FAIL + 'Please enter an instruction.' + Color.ENDC)
  5. exit()
  6. command = sys.argv[1]
  7. if command == 'create-simulation':
  8. import os, shutil
  9. import re
  10. print('Creation of a new simulation project...')
  11. ### Create the repository of the projects
  12. global_path = 'projects'
  13. os.makedirs(global_path, exist_ok=True)
  14. ### Get the project classname
  15. project_classname = ''
  16. search = re.compile(r'[^a-zA-Z0-9_]').search
  17. while not project_classname:
  18. classname = input(' - What is the project classname? ')
  19. if search(classname):
  20. print(' > Illegal characters detected! Please enter a name with only the following characters : a-z, A-Z, 0-9, and "_".')
  21. else:
  22. project_classname = classname.strip()
  23. ### Get and create the project repository
  24. search = re.compile(r'[^a-zA-Z0-9.-_/]').search
  25. project_repository = ''
  26. while not project_repository:
  27. repository = input(' - What is the project repository? ')
  28. if search(repository):
  29. print('Illegal characters detected! Please enter a name with only the following characters : a-z, A-Z, 0-9, ".", "-", "_" and "/".')
  30. else:
  31. project_repository = repository
  32. project_path = global_path+'/'+repository
  33. from .manage import create_simulation
  34. project_path = create_simulation(project_path, classname)
  35. print('')
  36. print('Creation complete !')
  37. print(' - Project repository: {}'.format(project_path))
  38. print(' - Project class "{}" in {}'.format(project_classname, project_path+'/projectclass.py'))
  39. print(' - Linker script: {}'.format(project_path+'/project.ld'))
  40. print('')
  41. print('Please don\'t to compile the project with the present Makefile before using it!')
  42. exit()
  43. if command == 'run-server':
  44. from .server.servicethread import ListeningThread
  45. from .executorthread import ExecutorThread
  46. def do_main_program():
  47. global thread, stop
  48. thread = ListeningThread('localhost', 5000, ExecutorThread)
  49. thread.start()
  50. def program_cleanup(signum, frame):
  51. global thread, stop
  52. thread.stop()
  53. stop = True
  54. thread = None
  55. stop = False
  56. # Execute
  57. print("Executing...")
  58. do_main_program()
  59. print("Done ! And now, listening...")
  60. import signal
  61. signal.signal(signal.SIGINT, program_cleanup)
  62. signal.signal(signal.SIGTERM, program_cleanup)
  63. # Wait
  64. import time
  65. while not stop:
  66. time.sleep(1)
  67. exit()
  68. print(Color.FAIL + 'Unknown Command.' + Color.ENDC)
  69. exit()