Beispiel #1
0
	def processComponent (componentName, v):
		if collectionName is not None:
			componentName = "{:s}/{:s}".format(collectionName, componentName)

		# It's a class
		if IComponent.implementedBy(v):
			fileName = namedModule(v.__module__).__file__
			objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
			component = v()

		# It's a function (eg getComponent)
		elif callable(v):
			fileName = namedModule(v.__module__).__file__
			objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
			component = v()

			if not IComponent.providedBy(component):
				raise Error(
					"{:s}.{:s}() does not produce a valid Component".format(
						v.__module__,
						v.__name__
				))

		# It's a string - hopefully a '.fbp' or '.json'
		else:
			import graph
			fileName = os.path.join(moduleDir, str(v))
			objectName = None
			component = graph.loadFile(fileName)

			if not IComponent.providedBy(component):
				raise Error(
					"{:s} does not produce a valid Component".format(
						componentName
				))

		# Make sure we will check the ".py" file
		if fileName[-4:] == ".pyc":
			fileName = fileName[:-1]

		if component.ready:
			return defer.succeed((fileName, objectName, componentName, component))
		else:
			d = defer.Deferred()
			component.once("ready", lambda data: d.callback(
				(fileName, objectName, componentName, component)
			))
			return d
Beispiel #2
0
    def processComponent(componentName, v):
        if collectionName is not None:
            componentName = "{:s}/{:s}".format(collectionName, componentName)

        # It's a class
        if IComponent.implementedBy(v):
            fileName = namedModule(v.__module__).__file__
            objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
            component = v()

        # It's a function (eg getComponent)
        elif callable(v):
            fileName = namedModule(v.__module__).__file__
            objectName = "{:s}.{:s}".format(v.__module__, v.__name__)
            component = v()

            if not IComponent.providedBy(component):
                raise Error(
                    "{:s}.{:s}() does not produce a valid Component".format(
                        v.__module__, v.__name__))

        # It's a string - hopefully a '.fbp' or '.json'
        else:
            import graph
            fileName = os.path.join(moduleDir, str(v))
            objectName = None
            component = graph.loadFile(fileName)

            if not IComponent.providedBy(component):
                raise Error("{:s} does not produce a valid Component".format(
                    componentName))

        # Make sure we will check the ".py" file
        if fileName[-4:] == ".pyc":
            fileName = fileName[:-1]

        if component.ready:
            return defer.succeed(
                (fileName, objectName, componentName, component))
        else:
            d = defer.Deferred()
            component.once(
                "ready", lambda data: d.callback(
                    (fileName, objectName, componentName, component)))
            return d
Beispiel #3
0
                                help='WebSocket port for runtime',
                                default=3569)

    parser_run = subparsers.add_parser('run',
                                       help='Run a graph non-interactively')
    parser_run.add_argument('--file',
                            type=str,
                            help='Graph file .fbp|.json',
                            required=True)

    args = parser.parse_args(sys.argv[1:])
    if args.command == 'register':
        register(args.user, args.label, args.ip, args.port)

    elif args.command == 'runtime':
        from protoflo.server.server import runtime
        runtime(args.ip, args.port)

    elif args.command == 'run':
        from twisted.internet import reactor
        import graph, network

        def onRunning(net):
            @net.on("end")
            def stop(data):
                reactor.stop()

        network.Network.create(graph.loadFile(
            args.file)).addCallback(onRunning)
        reactor.run()
Beispiel #4
0
	parser_register.add_argument('--label', type=str, help='Label to use in UI for this runtime', default="ProtoFlo")
	parser_register.add_argument('--ip', type=str, help='WebSocket IP for runtime', default='ws://localhost')
	parser_register.add_argument('--port', type=int, help='WebSocket port for runtime', default=3569)

	parser_runtime = subparsers.add_parser('runtime', help='Start runtime')
	parser_runtime.add_argument('--ip', type=str, help='WebSocket IP for runtime', default='localhost')
	parser_runtime.add_argument('--port', type=int, help='WebSocket port for runtime', default=3569)

	parser_run = subparsers.add_parser('run', help='Run a graph non-interactively')
	parser_run.add_argument('--file', type=str, help='Graph file .fbp|.json', required=True)

	args = parser.parse_args(sys.argv[1:])
	if args.command == 'register':
		register(args.user, args.label, args.ip, args.port)

	elif args.command == 'runtime':
		from protoflo.server.server import runtime
		runtime(args.ip, args.port)

	elif args.command == 'run':
		from twisted.internet import reactor
		import graph, network

		def onRunning (net):
			@net.on("end")
			def stop (data):
				reactor.stop()

		network.Network.create(graph.loadFile(args.file)).addCallback(onRunning)
		reactor.run()