Beispiel #1
0
    def setup(self):

        self.port = self.master.config.get('port', name=self.name)
        self.webroot = self.master.config.get('root', name=self.name)
        self.logpath = self.master.config.get('log', name=self.name)

        # Creste the root object
        root = File(self.webroot)
        root.noisy = False
        root.putChild('', Redirect('lumina.html'))

        # List of resources that we want added
        resources = {'rest/command': RestCommand(self),
                     'rest/info': RestInfo(self),
                    }

        # Traverse all resources and add them to the tree. Add empty
        # resources for the path elements between our resources and the root.
        for (path, resource) in resources.items():
            elements = path.split('/')

            # Traverse the path and either append to an existing resource
            # or add a new one.
            base = root
            for element in elements[:-1]:
                res = base.getStaticEntity(element)
                if res is None:
                    res = Resource()
                    res.noisy = False
                base.putChild(element, res)
                base = res      # pylint: disable=redefined-variable-type

            # Add our resource to the tree
            base.putChild(elements[-1], resource)

        # Create the site
        self.site = Site(root, logPath=self.logpath)
        self.site.noisy = False

        self.master.reactor.listenTCP(self.port, self.site)

        self.log.info("Logging access in {p}", p=self.logpath)

        # Ready
        self.status.set_GREEN()