script.py 824 B

123456789101112131415161718192021222324252627282930313233
  1. import subprocess
  2. import os
  3. from core.NeuronModule import NeuronModule
  4. class ScriptNotFound(Exception):
  5. pass
  6. class ScriptNotExecutable(Exception):
  7. pass
  8. class Script(NeuronModule):
  9. def __init__(self, **kwargs):
  10. # get message to spell out loud
  11. super(Script, self).__init__(**kwargs)
  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