Exemplo n.º 1
0
from pypes.filters import ConsoleOutputWriter

class HelloWorld(Component):
    __metatype__ = 'ADAPTER'

    def __init__(self):
        Component.__init__(self)

    def run(self):
        while True:
            for data in self.receive_all('in'):
                message = 'Hello %s' % data
                self.send('out', message)
            self.yield_ctrl()

hello   = HelloWorld()          # our custom component 
printer = ConsoleOutputWriter() # writes to console (STDOUT)

Network = {
       hello: {printer:('out','in')}
}

if __name__ == '__main__':
    # create a new data flow
    p = Dataflow(Network)
    # send some data through the data flow
    for name in ['Tom', 'Dick', 'Harry']:
        p.send(name)
    # shut down the data flow
    p.close() 
Exemplo n.º 2
0
    def update(self, jsconfig):
        statusText = 'Unidentified Error Saving Project'
        # close any existing workflow
        if self.Workflow is not None:
            try:
                self.Workflow.close()
            except:
                pass

        # set the new updated config from the UI
        try:
            self._config = json.loads(jsconfig)
        except:
            statusText = 'This Project Configuration is Bad'
        else:
            # Check for valid input component
            (in_status, inputs) = self.config_has_valid_input()
            (out_status, outputs) = self.config_has_valid_output()

            if in_status is False:
                statusText = 'Unable To Save Configuration<br><br>No Valid Adapter Specified<br>.'

            # Check for valid output component
            elif out_status is False:
                statusText = 'Unable To Save Configuration<br><br>No Valid Publisher Specified<br>.'

            else:
                # translate the current config into a usable DAG
                result = self.translate()
                if result is False:
                    statusText = 'Error Translating Supplied Configuration'
                # check the connectivity of the graph
                elif not self.is_connected(inputs, outputs):
                    statusText = 'Unable To Save Project<br><br>Found Broken Path Between Adapter and Publisher.<br>'
                else:
                    # Build the new workflow
                    try:
                        try:
                            # get the core count from the config
                            cores = int(config['cores'])
                            # has to be at least 1
                            if cores < 1:
                                cores = 1
                        except:
                            log.warning(
                                'Could not get core count from config.')
                            traceback.print_exc()
                            log.warning('Defaulting to core count of 1')
                            cores = 1

                        #log.info('Core count: %s' % cores)
                        self.Workflow = Dataflow(self.Graph, cores)
                    except:
                        statusText = 'Error Constructing Workflow'
                    else:
                        statusText = 'Project Successfully Saved'
                        # Save config here...
                        fp = None
                        try:
                            fp = open('projects/default.txt', 'w')
                            fp.write(jsconfig)
                        except:
                            log.error('Unable to save configuration')
                        else:
                            log.info('Configuration successfully saved')
                        finally:
                            if fp is not None:
                                fp.close()

        return statusText
Exemplo n.º 3
0
    def run(self):
        while True:
            for line in self.receive_all('in'):
                if self.regex.match(line):
                    self.send('out', line)
            self.yield_ctrl()


class Printer(Component):
    __metatype__ = 'PUBLISHER'

    def __init__(self):
        Component.__init__(self)

    def run(self):
        while True:
            for data in self.receive_all('in'):
                print data
            self.yield_ctrl()


tail = Tail(open('/var/log/syslog', 'r'))
grep = Grep('.*pants.*')
printer = Printer()

pipe = Dataflow({tail: {grep: ('out', 'in')}, grep: {printer: ('out', 'in')}})

while True:
    pipe.send(None)
    time.sleep(0.1)
Exemplo n.º 4
0
            doubler2: ("out", "in")
        },
    }
    return graph


if __name__ == '__main__':
    quadrupler = pypes.component.HigherOrderComponent(
        quadrupler_network_factory())
    quadrupler.__metatype__ = "ADAPTER"
    printer = Printer()
    doubler = Doubler()
    doubler.__metatype__ = "ADAPTER"

    network = {
        quadrupler: {
            printer: ("out", "in"),
        },
    }
    #network = {
    #doubler: {
    #printer: ("out", "in"),
    #},
    #}

    from pypes.pipeline import Dataflow
    pipeline = Dataflow(network)
    for number in range(1, 5):
        pipeline.send(number)
    pipeline.close()