def make_app(global_conf, **app_conf):
        """Returns a Sync Server Application."""
        global_conf.update(app_conf)
        params = convert_config(global_conf)
        app = klass(urls, controllers, params, auth_class)

        if params.get('debug', False):
            app = TransLogger(app, logger_name='syncserver',
                              setup_console_handler=True)

        if params.get('profile', False):
            from repoze.profile.profiler import AccumulatingProfileMiddleware
            app = AccumulatingProfileMiddleware(app,
                                          log_filename='profile.log',
                                          cachegrind_filename='cachegrind.out',
                                          discard_first_request=True,
                                          flush_at_shutdown=True,
                                          path='/__profile__')

        if params.get('client_debug', False):
            # errors are displayed in the user client
            app = ErrorMiddleware(app, debug=True,
                                  show_exceptions_in_wsgi_errors=True)
        else:
            # errors are logged and a 500 is returned with an empty body
            # to avoid any security whole
            app = CatchErrorMiddleware(app, logger_name='syncserver')

        if wrapper is not None:
            app = wrapper(app)
        return app
Example #2
0
    def __init__(self, base):
        syncdir = os.path.dirname(base)
        self.topdir = os.path.split(syncdir)[0]

        if 'WEAVE_TESTFILE' in os.environ:
            test_filename = 'tests_%s.ini' % os.environ['WEAVE_TESTFILE']
        else:
            test_filename = 'tests.ini'

        while True:

            ini_file = os.path.join(self.topdir, test_filename)
            if os.path.exists(ini_file):
                break

            if ini_file == ("/%s" % test_filename) \
                or ini_file == test_filename:
                raise IOError("cannot locate %s" % test_filename)

            self.topdir = os.path.split(self.topdir)[0]

        cfg = RawConfigParser()
        cfg.read(ini_file)

        # loading loggers
        if cfg.has_section('loggers'):
            fileConfig(ini_file)

        here = {'here': os.path.dirname(os.path.realpath(ini_file))}
        config = dict([(key, value % here) for key, value in
                      cfg.items('DEFAULT') + cfg.items('app:main')])
        self.config = convert_config(config)
    def __init__(self, base):
        syncdir = os.path.dirname(base)
        self.topdir = os.path.split(syncdir)[0]

        if 'WEAVE_TESTFILE' in os.environ:
            test_filename = 'tests_%s.ini' % os.environ['WEAVE_TESTFILE']
        else:
            test_filename = 'tests.ini'

        while True:

            ini_file = os.path.join(self.topdir, test_filename)
            if os.path.exists(ini_file):
                break

            if ini_file == ("/%s" % test_filename) \
                or ini_file == test_filename:
                raise IOError("cannot locate %s" % test_filename)

            self.topdir = os.path.split(self.topdir)[0]

        cfg = RawConfigParser()
        cfg.read(ini_file)

        # loading loggers
        if cfg.has_section('loggers'):
            fileConfig(ini_file)

        here = {'here': os.path.dirname(os.path.realpath(ini_file))}
        config = dict([
            (key, value % here)
            for key, value in cfg.items('DEFAULT') + cfg.items('app:main')
        ])
        self.config = convert_config(config)
Example #4
0
def make_post_office(global_config, **local_config):
    """Creates a POST Office that simply queues messages in the broker.
    
    This is a factory function for integration with Paste.
    """
    config = global_config.copy()
    config.update(local_config)
    params = convert_config(config)
    return PostOffice(params)
Example #5
0
    def test_convert_config(self):
        config = {'one': '1', 'two': 'bla', 'three': 'false'}
        config = convert_config(config)

        self.assertTrue(config['one'])
        self.assertEqual(config['two'], 'bla')
        self.assertFalse(config['three'])

        # config also reads extra config files.
        __, filename = tempfile.mkstemp()
        try:
            with open(filename, 'w') as f:
                f.write(_EXTRA)

            config = {'one': '1', 'two': 'file:%s' % filename}
            config = convert_config(config)
            self.assertTrue(config['some.stuff'])
            self.assertEquals(config['other.thing'], 'ok')
        finally:
            os.remove(filename)
Example #6
0
    def test_convert_config(self):
        config = {'one': '1', 'two': 'bla', 'three': 'false'}
        config = convert_config(config)

        self.assertTrue(config['one'])
        self.assertEqual(config['two'], 'bla')
        self.assertFalse(config['three'])

        # config also reads extra config files.
        __, filename = tempfile.mkstemp()
        try:
            with open(filename, 'w') as f:
                f.write(_EXTRA)

            config = {'one': '1', 'two': 'file:%s' % filename}
            config = convert_config(config)
            self.assertTrue(config['some.stuff'])
            self.assertEquals(config['other.thing'], 'ok')
        finally:
            os.remove(filename)
Example #7
0
def make_post_office_router(global_config, **local_config):
    """Creates a POST Office that validates and routes messages.

    This is useful for development environments where running
    a separate validation/routing server is inconvenient.

    This is a factory function for integration with Paste.
    """
    config = global_config.copy()
    config.update(local_config)
    params = convert_config(config)
    return PostOffice(params, NotificationValidator())
def initenv(config=None):
    """Reads the config file and instanciates an auth and a storage.

    The WEAVE_TESTFILE=name environment variable can be used to point
    a particular tests_name.ini file.
    """
    topdir = os.path.split(_TOPDIR)[0]

    if 'WEAVE_TESTFILE' in os.environ:
        test_filename = 'tests_%s.ini' % os.environ['WEAVE_TESTFILE']
    else:
        test_filename = 'tests.ini'

    while True:
        ini_file = os.path.join(topdir, test_filename)
        if os.path.exists(ini_file):
            break

        topdir = os.path.split(topdir)[0]
        if topdir == '/':
            break

    if not os.path.exists(ini_file):
        raise IOError("cannot locate %s" % test_filename)

    if config is None:
        config = ini_file

    cfg = RawConfigParser()
    cfg.read(config)

    # loading loggers
    if cfg.has_section('loggers'):
        fileConfig(config)

    here = {'here': os.path.dirname(os.path.realpath(config))}
    config = dict([
        (key, value % here)
        for key, value in cfg.items('DEFAULT') + cfg.items('app:main')
    ])
    config = convert_config(config)
    auth = ServicesAuth.get_from_config(config)
    return topdir, config, auth
Example #9
0
def initenv(config=None):
    """Reads the config file and instanciates an auth and a storage.

    The WEAVE_TESTFILE=name environment variable can be used to point
    a particular tests_name.ini file.
    """
    topdir = os.path.split(_TOPDIR)[0]

    if 'WEAVE_TESTFILE' in os.environ:
        test_filename = 'tests_%s.ini' % os.environ['WEAVE_TESTFILE']
    else:
        test_filename = 'tests.ini'

    while True:
        ini_file = os.path.join(topdir, test_filename)
        if os.path.exists(ini_file):
            break

        topdir = os.path.split(topdir)[0]
        if topdir == '/':
            break

    if not os.path.exists(ini_file):
        raise IOError("cannot locate %s" % test_filename)

    if config is None:
        config = ini_file

    cfg = RawConfigParser()
    cfg.read(config)

    # loading loggers
    if cfg.has_section('loggers'):
        fileConfig(config)

    here = {'here': os.path.dirname(os.path.realpath(config))}
    config = dict([(key, value % here)for key, value in
                   cfg.items('DEFAULT') + cfg.items('app:main')])
    config = convert_config(config)
    auth = ServicesAuth.get_from_config(config)
    return topdir, config, auth
Example #10
0
def make_basic_auth(app, global_config, realm, **local_config):
    """App factory function for integration with Paste."""
    config = global_config.copy()
    config.update(local_config)
    params = convert_config(config)
    return BasicAuthMiddleware(app, realm, params)
Example #11
0
def make_client_agent(global_config, **local_config):
    config = global_config.copy()
    config.update(local_config)
    params = convert_config(config)
    return ClientAgent(params)