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.

executorthread.py 2.7KB

4 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from servicethread import OneShotServiceThread
  2. import subprocess
  3. import shutil
  4. from project_reader import ProjectReader
  5. global_variables = {}
  6. class ExecutorThread(OneShotServiceThread):
  7. def __init__(self, ip, port, clientsocket, **kwargs):
  8. super().__init__(ip, port, clientsocket)
  9. self.projects = kwargs['projects'] if 'projects' in kwargs else None
  10. def execute(self):
  11. projects = self.projects
  12. if project is None:
  13. reader = ProjectReader()
  14. projects = {sc.get_project_label(): sc for sc in reader.get_project_classes()}
  15. print('Warning: need to research the projects.')
  16. else:
  17. print('Already have projects')
  18. data = self.protocol.get_data()
  19. self.protocol.please_assert(data)
  20. self.protocol.please_assert('project' in data)
  21. self.protocol.please_assert(data['project'] in projects)
  22. self.protocol.send_ack()
  23. # Get the project
  24. project = projects[data['project']]
  25. # Make the compilation
  26. if False:
  27. print('Compiling binary...')
  28. # Adapt the project source
  29. with open('binaries/Frodo/frodo-base.c', 'r') as _src_file:
  30. content = _src_file.read()
  31. with open('binaries/Frodo/frodo.c', 'w') as _dst_file:
  32. _dst_file.write(content.replace('%NEED_TO_FILL%', str(n)))
  33. # Compile the project
  34. make_directory = 'projects/{}/{}'.format(project.get_project_directory(), project.get_make_directory())
  35. process = subprocess.Popen('make', shell=True, cwd=make_directory, executable='/bin/bash', stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  36. output, error = process.communicate()
  37. if error and ('error' in error.decode('latin-1')):
  38. print("Error to compile")
  39. print(error)
  40. raise Exception()
  41. # Save last compilation data
  42. global_variables[project_name] = {
  43. 'last_n': n,
  44. }
  45. # Generate the trace by launching ELMO
  46. command = './elmo ../projects/{}/{}'.format(project.get_project_directory(), project.get_binary())
  47. process = subprocess.Popen(command, shell=True, cwd='elmo_online/elmo/', executable='/bin/bash', stdout=subprocess.PIPE)
  48. output, error = process.communicate()
  49. # Send results
  50. self.protocol.send_data({
  51. 'output': output.decode('latin-1') if output else None,
  52. 'error': error.decode('latin-1') if error else None,
  53. })
  54. self.protocol.close()