Example #1
0
class Brain(service.MultiService):
    def __init__(self, mamayo_root, wsgi_root=None, include_status=True):
        service.MultiService.__init__(self)

        self.mamayo_root = mamayo_root
        if wsgi_root is None:
            wsgi_root = self.mamayo_root.child('public_wsgi')
        self.wsgi_root = wsgi_root
        self.log_root = self.mamayo_root.child('logs')
        if not self.log_root.exists():
            self.log_root.createDirectory()

        self.registry = ApplicationRegistry(self.wsgi_root)
        self.registry.application_factory = self.create_application
        self.web_root = MamayoDispatchResource(self.registry)
        self.status_resource = MamayoStatusResource(self.registry)

        if include_status:
            well_known = Resource()
            self.web_root.putChild('.well-known', well_known)
            well_known.putChild('mamayo', self.status_resource)

        self.web_site = Site(self.web_root)

    def create_application(self, name, **kwargs):
        app_log_directory = self.log_root.child(name)
        if not app_log_directory.exists():
            app_log_directory.createDirectory()
        app_log = app_log_directory.child('current')
        return MamayoChildApplication(name=name, log_path=app_log, **kwargs)

    def startService(self):
        service.MultiService.startService(self)
        self.registry.scan_and_watch()
Example #2
0
class Brain(service.MultiService):
    def __init__(self, mamayo_root, wsgi_root=None, include_status=True):
        service.MultiService.__init__(self)

        self.mamayo_root = mamayo_root
        if wsgi_root is None:
            wsgi_root = self.mamayo_root.child("public_wsgi")
        self.wsgi_root = wsgi_root
        self.log_root = self.mamayo_root.child("logs")
        if not self.log_root.exists():
            self.log_root.createDirectory()

        self.registry = ApplicationRegistry(self.wsgi_root)
        self.registry.application_factory = self.create_application
        self.web_root = MamayoDispatchResource(self.registry)
        self.status_resource = MamayoStatusResource(self.registry)

        if include_status:
            well_known = Resource()
            self.web_root.putChild(".well-known", well_known)
            well_known.putChild("mamayo", self.status_resource)

        self.web_site = Site(self.web_root)

    def create_application(self, name, **kwargs):
        app_log_directory = self.log_root.child(name)
        if not app_log_directory.exists():
            app_log_directory.createDirectory()
        app_log = app_log_directory.child("current")
        return MamayoChildApplication(name=name, log_path=app_log, **kwargs)

    def startService(self):
        service.MultiService.startService(self)
        self.registry.scan_and_watch()
Example #3
0
def test_nested_application():
    "A mamayo app can be one directory nested deeply in the document root."
    app = mock.Mock()
    explorer = FakeExplorer({('spam', 'eggs', 'app'): app})
    dispatch = MamayoDispatchResource(explorer)

    for bogus_prepath in [['spam'], ['spam', 'eggs'], ['eggs']]:
        request = mock.Mock(prepath=bogus_prepath)
        assert dispatch.getChildWithDefault('', request) is dispatch
        assert dispatch.getChildWithDefault('something', request) is dispatch
        dispatch.render(request)
        assert not app.as_resource().render.called

    request = mock.Mock(prepath=['spam', 'eggs', 'app'])
    assert dispatch.getChildWithDefault('', request) is app.as_resource()
    assert dispatch.getChildWithDefault('something', request) is app.as_resource()
    dispatch.render(request)
    app.as_resource().render.assert_called_once_with(request)
Example #4
0
def test_basic_application():
    "A mamayo app can be one directory in the document root."
    app = mock.Mock()
    explorer = FakeExplorer({('foo',): app})
    dispatch = MamayoDispatchResource(explorer)

    request = mock.Mock(prepath=[])
    assert dispatch.getChildWithDefault('', request) is dispatch
    assert dispatch.getChildWithDefault('something', request) is dispatch
    dispatch.render(request)
    assert not app.as_resource().render.called

    request = mock.Mock(prepath=['foo'])
    assert dispatch.getChildWithDefault('something', request) is app.as_resource()
    dispatch.render(request)
    app.as_resource().render.assert_called_once_with(request)
Example #5
0
    def __init__(self, mamayo_root, wsgi_root=None, include_status=True):
        service.MultiService.__init__(self)

        self.mamayo_root = mamayo_root
        if wsgi_root is None:
            wsgi_root = self.mamayo_root.child('public_wsgi')
        self.wsgi_root = wsgi_root
        self.log_root = self.mamayo_root.child('logs')
        if not self.log_root.exists():
            self.log_root.createDirectory()

        self.registry = ApplicationRegistry(self.wsgi_root)
        self.registry.application_factory = self.create_application
        self.web_root = MamayoDispatchResource(self.registry)
        self.status_resource = MamayoStatusResource(self.registry)

        if include_status:
            well_known = Resource()
            self.web_root.putChild('.well-known', well_known)
            well_known.putChild('mamayo', self.status_resource)

        self.web_site = Site(self.web_root)
Example #6
0
def test_root_as_application():
    "The document root is a possible place for a mamayo app."
    app = mock.Mock()
    explorer = FakeExplorer({(): app})
    dispatch = MamayoDispatchResource(explorer)

    request = mock.Mock(prepath=[])
    assert dispatch.getChildWithDefault('', request) is app.as_resource()
    assert dispatch.getChildWithDefault('something', request) is app.as_resource()
    dispatch.render(request)
    app.as_resource().render.assert_called_once_with(request)
Example #7
0
    def __init__(self, mamayo_root, wsgi_root=None, include_status=True):
        service.MultiService.__init__(self)

        self.mamayo_root = mamayo_root
        if wsgi_root is None:
            wsgi_root = self.mamayo_root.child("public_wsgi")
        self.wsgi_root = wsgi_root
        self.log_root = self.mamayo_root.child("logs")
        if not self.log_root.exists():
            self.log_root.createDirectory()

        self.registry = ApplicationRegistry(self.wsgi_root)
        self.registry.application_factory = self.create_application
        self.web_root = MamayoDispatchResource(self.registry)
        self.status_resource = MamayoStatusResource(self.registry)

        if include_status:
            well_known = Resource()
            self.web_root.putChild(".well-known", well_known)
            well_known.putChild("mamayo", self.status_resource)

        self.web_site = Site(self.web_root)