class example(BaseRecipe): inputs = { 'executable': ExecField('--executable', help="Command to run", default="/bin/ls") } outputs = {'stdout': StringField()} def go(self): self.logger.info("Starting example recipe run") super(example, self).go() self.logger.info("This is a log message") my_process = subprocess.Popen([self.inputs['executable']], stdout=subprocess.PIPE, stderr=subprocess.PIPE) sout, serr = communicate_returning_strings(my_process) self.outputs['stdout'] = sout log_process_output(self.inputs['executable'], sout, serr, self.logger) if my_process.returncode == 0: return 0 else: self.logger.warn("Return code (%d) is not 0." % my_process.returncode) return 1
class ExecFieldTest(unittest.TestCase): """ Tests for :class:`lofarpipe.support.lofaringredient.ExecField` """ def setUp(self): from lofarpipe.support.lofaringredient import ExecField self.execfield = ExecField(default='/bin/ls') def test_validator(self): """ ``/etc/passwd`` should always exist as a file on disk, but not be executable. ``/bin/ls`` should always exist, and must be executable. """ self.assertFalse(self.execfield.is_valid("/etc/passwd")) self.assertTrue(self.execfield.is_valid("/bin/ls")) def test_default(self): """ Check that default is correctly set. """ self.assertEqual(self.execfield.default, "/bin/ls")
def setUp(self): from lofarpipe.support.lofaringredient import ExecField self.execfield = ExecField(default='/bin/ls')