class FileInputNode(InputNode): label = _(u"File") description = _(u"Read the content of a file") def __init__(self, *args, **kwargs): InputNode.__init__(self, *args, **kwargs) self.filepath = InterfaceValue(self, 'filepath', default='', type=Interface.PARAMETER, slot=False, doc="file to read") self.output = InterfaceStream(self, 'output', default='EOF', type=Interface.OUTPUT, doc="file content") def run(self): # Read file content and pass to output interface if empty(self.filepath.value): raise FlowError(_("Filepath empty, cannot read file.")) self.info(_("Read content of file '%s'") % self.filepath.value) f = open(self.filepath.value, 'rb') for line in f: self.output.write(line) self.output.flush() f.close()
class CommandLineStdinInputNode(InputNode): label = _(u"CLI Stdin") description = _(u"Read the Command-Line Interface standard input") def __init__(self, *args, **kwargs): InputNode.__init__(self, *args, **kwargs) self.output = InterfaceStream(self, 'output', default='EOF', type=Interface.OUTPUT, doc="standard input content") def run(self): for line in sys.stdin: self.output.write(line) self.output.flush()