script.py 809 B

1234567891011121314151617181920212223242526272829303132333435
  1. import subprocess
  2. import os
  3. from core.Models.Neurone import Neurone
  4. class ScriptNotFound(Exception):
  5. pass
  6. class ScriptNotExecutable(Exception):
  7. pass
  8. class Script(Neurone):
  9. def __init__(self, *args , **kwargs):
  10. Neurone.__init__(self)
  11. # get message to spell out loud
  12. script_path = kwargs.get('path', "")
  13. # test that the file exist and is executable
  14. if self.is_exe(script_path):
  15. p = subprocess.Popen(script_path, stdout=subprocess.PIPE, shell=True)
  16. (output, err) = p.communicate()
  17. def is_exe(self, fpath):
  18. returned_value = True
  19. if not os.path.isfile(fpath):
  20. raise ScriptNotFound()
  21. if not os.access(fpath, os.X_OK):
  22. raise ScriptNotExecutable()
  23. return returned_value