Пример #1
0
def make_lc(self, reactor, func):

    if DEBUG:
        self.stdout_length = 0
        self.stderr_length = 0

    def _(lc, reactor):
        if DEBUG:
            stdout = self.stdout.getvalue()
            stderr = self.stderr.getvalue()

            if self.stdout.getvalue()[self.stdout_length:]:
                print(self.stdout.getvalue()[self.stdout_length:],
                      file=sys.__stdout__)
            if self.stderr.getvalue()[self.stderr_length:]:
                print(self.stderr.getvalue()[self.stderr_length:],
                      file=sys.__stderr__)

            self.stdout_length = len(stdout)
            self.stderr_length = len(stderr)

        return func(lc, reactor)

    lc = LoopingCall(_)
    lc.a = (lc, reactor)
    lc.clock = reactor
    lc.start(0.1)
    return lc
Пример #2
0
def make_lc(self, reactor, func):

    if DEBUG:
        self.stdout_length = 0
        self.stderr_length = 0

    def _(lc, reactor):
        if DEBUG:
            stdout = self.stdout.getvalue()
            stderr = self.stderr.getvalue()

            if self.stdout.getvalue()[self.stdout_length:]:
                print(self.stdout.getvalue()[self.stdout_length:],
                      file=sys.__stdout__)
            if self.stderr.getvalue()[self.stderr_length:]:
                print(self.stderr.getvalue()[self.stderr_length:],
                      file=sys.__stderr__)

            self.stdout_length = len(stdout)
            self.stderr_length = len(stderr)

        return func(lc, reactor)

    lc = LoopingCall(_)
    lc.a = (lc, reactor)
    lc.clock = reactor
    lc.start(0.1)
    return lc
	def create(self):
		if self._connected is not None:
			return self._connected

		MODULE.info('Starting new module process: %s' % (self.module,))
		self.socket = self.get_socket_path()

		args = [
			MODULE_COMMAND, '-l', self.module_locale,
			'-d', str(self.module_debug_level), self.socket, self.module
		]

		MODULE.info('Module process: %s' % (' '.join(args)))
		self.process = Popen(args, executable=MODULE_COMMAND, shell=False)  # TODO: stdout, stderr

		connect = LoopingCall(self.connect)
		connect.a = (connect,)  # twisteds arguments
		self._connected = connect.start(0.05)
		return self._connected
Пример #4
0
    def _test_start_run(self):
        """
        A basic start, that enters the reactor.
        """
        code_location = os.path.abspath(self.mktemp())
        os.mkdir(code_location)

        with open(self.config, "w") as f:
            f.write("""{
   "controller": {
   },
   "workers": [
      {
         "type": "router",
         "options": {
            "pythonpath": ["."]
         },
         "realms": [
            {
               "name": "realm1",
               "roles": [
                  {
                     "name": "anonymous",
                     "permissions": [
                        {
                           "uri": "*",
                           "publish": true,
                           "subscribe": true,
                           "call": true,
                           "register": true
                        }
                     ]
                  }
               ]
            }
         ],
         "transports": [
            {
               "type": "web",
               "endpoint": {
                  "type": "tcp",
                  "port": 8080
               },
               "paths": {
            "/": {
              "directory": ".",
              "type": "static"
            },
                  "ws": {
                     "type": "websocket"
                  }
               }
            }
         ]
      },
      {
         "type": "container",
         "options": {
            "pythonpath": ["%s"]
         },
         "components": [
            {
               "type": "class",
               "classname": "test.AppSession",
               "realm": "realm1",
               "transport": {
                  "type": "websocket",
                  "endpoint": {
                     "type": "tcp",
                     "host": "127.0.0.1",
                     "port": 8080
                  },
                  "url": "ws://127.0.0.1:8080/ws"
               }
            }
         ]
      }
   ]
}
            """ % ("/".join(code_location.split(os.sep), )))

        with open(code_location + "/test.py", "w") as f:
            f.write("""#!/usr/bin/env python
from twisted.internet.defer import inlineCallbacks
from twisted.logger import Logger
from autobahn.twisted.wamp import ApplicationSession
from autobahn.wamp.exception import ApplicationError

class AppSession(ApplicationSession):

    log = Logger()

    @inlineCallbacks
    def onJoin(self, details):
        self.log.info("Loaded the component!")
        yield self.publish("com.bar", "test")
""")

        reactor = SelectReactor()

        def _check(lc):
            if "Loaded the component!" in self.stdout.getvalue():
                if reactor.running:
                    reactor.stop()
                lc.stop()

        lc = LoopingCall(_check)
        lc.a = (lc, )
        lc.clock = reactor

        # In case it hard-locks
        reactor.callLater(self._subprocess_timeout, reactor.stop)
        lc.start(0.1)

        cli.run(
            "crossbar",
            ["start", "--cbdir={}".format(self.cbdir), "--logformat=syslogd"],
            reactor=reactor)

        self.assertIn("Entering reactor event loop", self.stdout.getvalue())
        self.assertIn("Loaded the component!", self.stdout.getvalue())
Пример #5
0
    def _test_start_run(self):
        """
        A basic start, that enters the reactor.
        """
        code_location = os.path.abspath(self.mktemp())
        os.mkdir(code_location)

        with open(self.config, "w") as f:
            f.write("""{
   "controller": {
   },
   "workers": [
      {
         "type": "router",
         "options": {
            "pythonpath": ["."]
         },
         "realms": [
            {
               "name": "realm1",
               "roles": [
                  {
                     "name": "anonymous",
                     "permissions": [
                        {
                           "uri": "*",
                           "publish": true,
                           "subscribe": true,
                           "call": true,
                           "register": true
                        }
                     ]
                  }
               ]
            }
         ],
         "transports": [
            {
               "type": "web",
               "endpoint": {
                  "type": "tcp",
                  "port": 8080
               },
               "paths": {
            "/": {
              "directory": ".",
              "type": "static"
            },
                  "ws": {
                     "type": "websocket"
                  }
               }
            }
         ]
      },
      {
         "type": "container",
         "options": {
            "pythonpath": ["%s"]
         },
         "components": [
            {
               "type": "class",
               "classname": "test.AppSession",
               "realm": "realm1",
               "transport": {
                  "type": "websocket",
                  "endpoint": {
                     "type": "tcp",
                     "host": "127.0.0.1",
                     "port": 8080
                  },
                  "url": "ws://127.0.0.1:8080/ws"
               }
            }
         ]
      }
   ]
}
            """ % ("/".join(code_location.split(os.sep),)))

        with open(code_location + "/test.py", "w") as f:
            f.write("""#!/usr/bin/env python
from twisted.internet.defer import inlineCallbacks
from twisted.logger import Logger
from autobahn.twisted.wamp import ApplicationSession
from autobahn.wamp.exception import ApplicationError

class AppSession(ApplicationSession):

    log = Logger()

    @inlineCallbacks
    def onJoin(self, details):
        self.log.info("Loaded the component!")
        yield self.publish("com.bar", "test")
""")

        reactor = SelectReactor()

        def _check(lc):
            if "Loaded the component!" in self.stdout.getvalue():
                if reactor.running:
                    reactor.stop()
                lc.stop()

        lc = LoopingCall(_check)
        lc.a = (lc,)
        lc.clock = reactor

        # In case it hard-locks
        reactor.callLater(self._subprocess_timeout, reactor.stop)
        lc.start(0.1)

        cli.run("crossbar",
                ["start",
                 "--cbdir={}".format(self.cbdir),
                 "--logformat=syslogd"],
                reactor=reactor)

        self.assertIn("Entering reactor event loop", self.stdout.getvalue())
        self.assertIn("Loaded the component!", self.stdout.getvalue())