script.py 793 B

12345678910111213141516171819202122232425262728293031323334
  1. from core import Neurone
  2. import subprocess
  3. import os
  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