Esempio n. 1
0
def load_configuration(global_conf, app_conf):
    """Build the application configuration dict."""
    app_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {}
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(check(struct(
        {
            'app_conf': default(app_conf),
            'app_dir': default(app_dir),
            'app_name': default('Harmony Tiles'),
            'debug': pipe(guess_bool, default(False)),
            'global_conf': default(global_conf),
            'log_level': pipe(
                default('WARNING'),
                function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': default('harmony-tiles'),
            'projects_base_dir': pipe(
                function(lambda value: os.path.abspath(value)),
                not_none,
                ),
        },
        default='drop',
        drop_none_values=False,
    ))(conf))
    return conf
Esempio n. 2
0
def load_configuration(global_conf, app_conf):
    """Build the application configuration dict."""
    app_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {}
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(check(struct(
        {
            'app_conf': default(app_conf),
            'app_dir': default(app_dir),
            'cache_dir': default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'database.collections.states': default('states'),
            'database.collections.subscriptions': default('subscriptions'),
            'database.collections.tasks': default('tasks'),
            'database.host_name': default('localhost'),
            'database.name': default('webrokeit'),
            'database.port': pipe(input_to_int, default(27017)),
            'debug': pipe(guess_bool, default(False)),
            'global_conf': default(global_conf),
            'log_level': pipe(
                default('WARNING'),
                function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': default('webrokeit'),
        },
        default='drop',
        drop_none_values=False,
    ))(conf))
    return conf
Esempio n. 3
0
def load_configuration(global_conf, app_conf):
    """Build the application configuration dict."""
    app_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {}
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(check(struct(
        {
            'app_conf': default(app_conf),
            'app_dir': default(app_dir),
            'app_name': default('Harmony Jobs'),
            'cache_dir': default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'cdn.url': default('http://localhost:7000'),
            'custom_templates_dir': default(None),
            'database.host_name': default('localhost'),
            'database.name': default('harmony'),
            'database.port': pipe(input_to_int, default(27017)),
            'debug': pipe(guess_bool, default(False)),
            'global_conf': default(global_conf),
            'log_level': pipe(
                default('WARNING'),
                function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': default('harmony-jobs'),
            'static_files': pipe(guess_bool, default(False)),
            'static_files_dir': default(os.path.join(app_dir, 'static')),
            'webrokeit.database.collections.states': default('states'),
            'webrokeit.database.collections.subscriptions': default('subscriptions'),
            'webrokeit.database.collections.tasks': default('tasks'),
            'webrokeit.database.host_name': default('localhost'),
            'webrokeit.database.name': default('webrokeit'),
            'webrokeit.database.port': pipe(input_to_int, default(27017)),
            'webrokeit.url.base': default('http;//localhost:8765'),
            'webrokeit.url.emit': default('http://localhost:8765/emit'),
        },
        default='drop',
        drop_none_values=False,
    ))(conf))

    # Assets
    conf.update(check(struct(
        {
            'cdn.bootstrap.css': default(
                urlparse.urljoin(conf['cdn.url'], '/bootstrap/2.2.2/css/bootstrap.min.css')
                ),
            'cdn.bootstrap.js': default(urlparse.urljoin(conf['cdn.url'], '/bootstrap/2.2.2/js/bootstrap.js')),
            'cdn.html5shiv.js': default(urlparse.urljoin(conf['cdn.url'], '/html5shiv/html5shiv.js')),
            'cdn.jquery.js': default(urlparse.urljoin(conf['cdn.url'], '/jquery/jquery-1.9.1.min.js')),
            'cdn.plupload.js': default(urlparse.urljoin(conf['cdn.url'], '/plupload/plupload.full.js')),
            'cdn.underscore.js': default(urlparse.urljoin(conf['cdn.url'], '/underscore/underscore.js')),
        },
        default=noop,
    ))(conf))
    return conf
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = plastic_auth_api.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'database': conv.default('plastic_auth_api'),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'global_conf': conv.set_value(global_conf),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'mongodb_address': conv.default('localhost'),
            'mongodb_port': conv.pipe(
                conv.input_to_int,
                conv.default(27017),
                ),
            'package_name': conv.default(u'plastic-auth-api'),
            'realm': conv.default(u'Plastic-Auth API'),
            'plastic_auth_ui.name': conv.default(u'Plastic-Auth-UI'),
            'zmq_push_socket': conv.not_none,
            'zmq_sub_socket': conv.not_none,
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'Plastic-Auth Web API Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    components = dict(
        conf = conf,
        contexts = contexts,
        conv = conv,
        db = pymongo.Connection(conf['mongodb_address'], conf['mongodb_port'])[conf['database']],
        model = model,
        )
    model.init(components)
Esempio n. 5
0
def load_configuration(global_conf, app_conf):
    """Build the application configuration dict."""
    app_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {}
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(check(struct(
        {
            'app_conf': default(app_conf),
            'app_dir': default(app_dir),
            'app_name': default('Harmony Viewer'),
            'cache_dir': default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'cdn.url': pipe(cleanup_line, not_none),
            'custom_templates_dir': default(None),
            'debug': pipe(guess_bool, default(False)),
            'global_conf': default(global_conf),
            'log_level': pipe(
                default('WARNING'),
                function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': default('harmony-viewer'),
            'projects_base_dir': pipe(cleanup_line, not_none),
            'static_files': pipe(guess_bool, default(False)),
            'static_files_dir': default(os.path.join(app_dir, 'static')),
            'tile_server_url_scheme': pipe(cleanup_line, not_none),
        },
        default='drop',
        drop_none_values=False,
    ))(conf))

    # Assets
    conf.update(check(struct(
        {
            'cdn.bootstrap.css': default(
                urlparse.urljoin(conf['cdn.url'], '/bootstrap/2.2.2/css/bootstrap.min.css')
                ),
            'cdn.bootstrap.js': default(urlparse.urljoin(conf['cdn.url'], '/bootstrap/2.2.2/js/bootstrap.js')),
            'cdn.html5shiv.js': default(urlparse.urljoin(conf['cdn.url'], '/html5shiv/html5shiv.js')),
            'cdn.jquery.js': default(urlparse.urljoin(conf['cdn.url'], '/jquery/jquery-1.9.1.min.js')),
            'cdn.leaflet.css': default(urlparse.urljoin(conf['cdn.url'], '/leaflet/0.5.1/leaflet.css')),
            'cdn.leaflet.ie.css': default(urlparse.urljoin(conf['cdn.url'], '/leaflet/0.5.1/leaflet.ie.css')),
            'cdn.leaflet.js': default(urlparse.urljoin(conf['cdn.url'], '/leaflet/0.5.1/leaflet.js')),
            'cdn.plupload.js': default(urlparse.urljoin(conf['cdn.url'], '/plupload/plupload.full.js')),
            'cdn.underscore.js': default(urlparse.urljoin(conf['cdn.url'], '/underscore/underscore.js')),
        },
        default=noop,
    ))(conf))
    return conf
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = openfisca_web_api.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'country_package': conv.pipe(
                conv.make_input_to_slug(separator = u'_'),
                conv.test_in((
                    u'openfisca_france',
                    u'openfisca_tunisia',
                    u'openfisca_tunisia_pension',
                    )),
                conv.not_none,
                ),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'global_conf': conv.set_value(global_conf),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('openfisca-web-api'),
            'realm': conv.default(u'OpenFisca Web API'),
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'OpenFisca Web API Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    country_package = importlib.import_module(conf['country_package'])
    conv.State.TaxBenefitSystem = country_package.init_country()
Esempio n. 7
0
def load_configuration(global_conf, app_conf):
    """Build the application configuration dict."""
    app_dir = os.path.dirname(os.path.abspath(__file__))
    conf = {}
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(check(struct(
        {
            'app_conf': default(app_conf),
            'app_dir': default(app_dir),
            'cache_dir': default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'debug': pipe(guess_bool, default(False)),
            'global_conf': default(global_conf),
            },
        default='drop',
        drop_none_values=False,
        ))(conf))
    return conf
Esempio n. 8
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = ckanofworms.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'biryani1_i18n_dir': conv.pipe(
                conv.default(os.path.normpath(os.path.join(app_dir, '..', '..', 'biryani1', 'biryani1', 'i18n'))),
                conv.test(os.path.exists),
                ),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'ckan_url': conv.pipe(
                conv.make_input_to_url(full = True, error_if_fragment = True, error_if_path = True,
                    error_if_query = True),
                conv.not_none,
                ),
            'cookie': conv.default('ckan-of-worms'),
            'database': conv.default('ckan_of_worms'),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'domain': conv.default('data.gouv.fr'),
            'fedmsg.environment': conv.pipe(
                conv.empty_to_none,
                conv.test_in(['dev', 'prod', 'stg']),
                conv.default('dev'),
                ),
            'fedmsg.modname': conv.pipe(
                conv.empty_to_none,
                conv.test(lambda value: value == value.strip('.'), error = 'Value must not begin or end with a "."'),
                conv.default('ckan_of_worms'),
                ),
            'fedmsg.name': conv.pipe(
                conv.empty_to_none,
                conv.default('ckan_of_worms.{}'.format(hostname)),
                ),
            'fedmsg.topic_prefix': conv.pipe(
                conv.empty_to_none,
                conv.test(lambda value: value == value.strip('.'), error = 'Value must not begin or end with a "."'),
                conv.not_none,
                ),
            'global_conf': conv.set_value(global_conf),
#            'host_urls': conv.pipe(
#                conv.function(lambda host_urls: host_urls.split()),
#                conv.uniform_sequence(
#                    conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
#                        full = True, schemes = (u'ws', u'wss')),
#                    constructor = lambda host_urls: sorted(set(host_urls)),
#                    ),
#                ),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('ckan-of-worms'),
            'piwik.site_id': conv.pipe(conv.input_to_int, conv.default(0)),
            'piwik.url': conv.make_input_to_url(error_if_fragment=True, error_if_query = True),
            'piwik.domain': conv.default(False),
            'piwik.debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'realm': conv.default(u'CKAN-of-Worms'),
            # Whether this application serves its own static files.
            'static_files': conv.pipe(conv.guess_bool, conv.default(True)),
            'static_files_dir': conv.default(os.path.join(app_dir, 'static')),
            'sentry.dsn': conv.default(False),
            'weckan_url': conv.pipe(
                conv.make_input_to_url(full = True, error_if_fragment = True, error_if_path = True,
                    error_if_query = True),
                conv.not_none,
                ),
            'wiki_url': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_query = True),
                conv.not_none,
                ),
            'wiki_api_url': conv.pipe(
                conv.make_input_to_url(full = True, error_if_fragment = True, error_if_query = True),
                conv.not_none,
                ),
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug'] and not conf['sentry.dsn']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'CKAN-of-Worms Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Configure fedmsg.
    fedmsg.init(active = True, name = 'relay_inbound', **dict(
        (key[len('fedmsg.'):], value)
        for key, value in conf.iteritems()
        if key.startswith('fedmsg.') and key != 'fedmsg.name' and value is not None
        ))

    # Load MongoDB database.
    db = pymongo.Connection()[conf['database']]
    model.init(db)

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = [os.path.join(app_dir, 'templates')]

    # Configure WebAssets.
    conf['assets'] = configure_assets(debug = conf['debug'], static_dir = conf['static_files_dir'])
Esempio n. 9
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = dactylo.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(
        conv.check(
            conv.struct(
                {
                    'app_conf':
                    conv.set_value(app_conf),
                    'app_dir':
                    conv.set_value(app_dir),
                    'biryani1_i18n_dir':
                    conv.pipe(
                        conv.default(
                            os.path.normpath(
                                os.path.join(app_dir, '..', '..', 'biryani1',
                                             'biryani1', 'i18n'))),
                        conv.test(os.path.exists),
                    ),
                    'cache_dir':
                    conv.default(
                        os.path.join(os.path.dirname(app_dir), 'cache')),
                    'cookie':
                    conv.default('dactylo'),
                    'database':
                    conv.default('dactylo'),
                    'debug':
                    conv.pipe(conv.guess_bool, conv.default(False)),
                    'global_conf':
                    conv.set_value(global_conf),
                    #            'host_urls': conv.pipe(
                    #                conv.function(lambda host_urls: host_urls.split()),
                    #                conv.uniform_sequence(
                    #                    conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                    #                        full = True, schemes = (u'ws', u'wss')),
                    #                    constructor = lambda host_urls: sorted(set(host_urls)),
                    #                    ),
                    #                ),
                    'i18n_dir':
                    conv.default(os.path.join(app_dir, 'i18n')),
                    'log_level':
                    conv.pipe(
                        conv.default('WARNING'),
                        conv.function(lambda log_level: getattr(
                            logging, log_level.upper())),
                    ),
                    'package_name':
                    conv.default('dactylo'),
                    'piwik.site_id':
                    conv.input_to_int,
                    'piwik.url':
                    conv.make_input_to_url(full=True,
                                           error_if_fragment=True,
                                           error_if_path=True,
                                           error_if_query=True),
                    'realm':
                    conv.default(u'dactylo'),
                    # Whether this application serves its own static files.
                    'static_files':
                    conv.pipe(conv.guess_bool, conv.default(True)),
                    'static_files_dir':
                    conv.default(os.path.join(app_dir, 'static')),
                },
                default='drop',
            ))(conf))

    # Configure logging.
    logging.basicConfig(level=conf['log_level'], stream=sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get(
            'error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix',
                                                     'dactylo Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Load MongoDB database.
    db = pymongo.Connection()[conf['database']]
    model.init(db)

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = [os.path.join(app_dir, 'templates')]

    # Configure WebAssets.
    conf['assets'] = configure_assets(debug=conf['debug'],
                                      static_dir=conf['static_files_dir'])
Esempio n. 10
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = lawtocode.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'biryani1_i18n_dir': conv.pipe(
                conv.default(os.path.normpath(os.path.join(app_dir, '..', '..', 'biryani1', 'biryani1', 'i18n'))),
                conv.test(os.path.exists),
                ),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'cookie': conv.default('law-to-code'),
            'database': conv.default('lawtocode'),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'global_conf': conv.set_value(global_conf),
#            'host_urls': conv.pipe(
#                conv.function(lambda host_urls: host_urls.split()),
#                conv.uniform_sequence(
#                    conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
#                        full = True, schemes = (u'ws', u'wss')),
#                    constructor = lambda host_urls: sorted(set(host_urls)),
#                    ),
#                ),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('law-to-code'),
            'piwik.site_id': conv.input_to_int,
            'piwik.url': conv.make_input_to_url(full = True, error_if_fragment = True, error_if_path = True,
                error_if_query = True),
            'realm': conv.default(u'law-to-code'),
            # Whether this application serves its own static files.
            'static_files': conv.pipe(conv.guess_bool, conv.default(True)),
            'static_files_dir': conv.default(os.path.join(app_dir, 'static')),
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'law-to-code Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Load MongoDB database.
    db = pymongo.Connection()[conf['database']]
    model.init(db)

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = [os.path.join(app_dir, 'templates')]

    # Configure WebAssets.
    conf['assets'] = configure_assets(debug = conf['debug'], static_dir = conf['static_files_dir'])
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = openfisca_web_site.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'api.url': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                    full = True),
                conv.default(u'http://api.openfisca.fr/'),
                ),
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'cookie': conv.default('openfisca_web_site'),
            'custom_templates_dir': conv.pipe(
                conv.empty_to_none,
                conv.test(os.path.exists),
                ),
            'customs_dir': conv.default(None),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'global_conf': conv.set_value(global_conf),
            'google_analytics.key': conv.empty_to_none,
            'host_urls': conv.pipe(
                conv.function(lambda host_urls: host_urls.split()),
                conv.uniform_sequence(
                    conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                        full = True, schemes = (u'ws', u'wss')),
                    constructor = lambda host_urls: sorted(set(host_urls)),
                    ),
                ),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('openfisca-web-site'),
            'piwik.key': conv.input_to_int,
            'piwik.url': conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                full = True),
            'realm': conv.default(u'OpenFisca-Web-Site'),
            # Whether this application serves its own static files.
            'static_files': conv.pipe(conv.guess_bool, conv.default(True)),
            'static_files_dir': conv.default(os.path.join(app_dir, 'static')),
            'ui.url': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                    full = True),
                conv.default(u'http://ui.openfisca.fr/'),
                ),
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'OpenFisca-Web-Site Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = templates_dirs = []
    if conf['custom_templates_dir']:
        templates_dirs.append(conf['custom_templates_dir'])
    templates_dirs.append(os.path.join(app_dir, 'templates'))
Esempio n. 12
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = openfisca_web_ui.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'api.urls.fields': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_query = True, full = True),
                conv.not_none,
                ),
            'api.urls.legislations': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_query = True, full = True),
                conv.not_none,
                ),
            'api.urls.simulate': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_query = True, full = True),
                conv.not_none,
                ),
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'app_name': conv.pipe(conv.cleanup_line, conv.default('OpenFisca')),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'cookie': conv.default('openfisca-web-ui'),
            'customs_dir': conv.default(None),
            'database.host': conv.default('localhost'),
            'database.name': conv.default('openfisca_web_ui'),
            'database.port': conv.pipe(conv.input_to_int, conv.default(27017)),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'dev.build_js': conv.pipe(conv.guess_bool, conv.default(False)),
            'enabled.auth': conv.pipe(conv.guess_bool, conv.default(True)),
            'enabled.charts.locating': conv.pipe(conv.guess_bool, conv.default(True)),
            'global_conf': conv.set_value(global_conf),
#            'host_urls': conv.pipe(
#                conv.function(lambda host_urls: host_urls.split()),
#                conv.uniform_sequence(
#                    conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
#                        full = True, schemes = (u'ws', u'wss')),
#                    constructor = lambda host_urls: sorted(set(host_urls)),
#                    ),
#                ),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('openfisca-web-ui'),
            'persona.url': conv.pipe(
                conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                    full = True),
                conv.default(u'https://login.persona.org/'),
                ),
            'piwik.site_id': conv.input_to_int,
            'piwik.url': conv.make_input_to_url(full = True, error_if_fragment = True, error_if_path = True,
                error_if_query = True),
            # Whether this application serves its own static files.
            'static_files': conv.pipe(conv.guess_bool, conv.default(True)),
            'static_files_dir': conv.default(os.path.join(app_dir, 'static')),
            'www.url': conv.pipe(
                conv.make_input_to_url(full = True),
                conv.default(u'http://www.openfisca.fr/'),
                ),
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'OpenFisca-Web-UI Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Load MongoDB database.
    global db
    db = pymongo.Connection(conf['database.host'], conf['database.port'])[conf['database.name']]
    model.init(db)

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = [os.path.join(app_dir, 'templates')]
Esempio n. 13
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = weckan.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(
        conv.check(
            conv.struct(
                {
                    'app_conf':
                    conv.set_value(app_conf),
                    'app_dir':
                    conv.set_value(app_dir),
                    'cache_dir':
                    conv.default(
                        os.path.join(os.path.dirname(app_dir), 'cache')),
                    'cdn':
                    conv.pipe(
                        conv.make_input_to_url(),
                        conv.default('//localhost:7000'),
                    ),
                    'cookie':
                    conv.default('weckan'),
                    'custom_templates_dir':
                    conv.pipe(
                        conv.empty_to_none,
                        conv.test(os.path.exists),
                    ),
                    'customs_dir':
                    conv.default(None),
                    'debug':
                    conv.pipe(conv.guess_bool, conv.default(False)),
                    'global_conf':
                    conv.set_value(global_conf),
                    'host_urls':
                    conv.pipe(
                        conv.function(lambda host_urls: host_urls.split()),
                        conv.uniform_sequence(
                            conv.make_input_to_url(error_if_fragment=True,
                                                   error_if_path=True,
                                                   error_if_query=True,
                                                   full=True,
                                                   schemes=(u'ws', u'wss')),
                            constructor=lambda host_urls: sorted(set(host_urls)
                                                                 ),
                        ),
                    ),
                    'log_level':
                    conv.pipe(
                        conv.default('WARNING'),
                        conv.function(lambda log_level: getattr(
                            logging, log_level.upper())),
                    ),
                    'package_name':
                    conv.default('weckan'),
                    'realm':
                    conv.default(u'Weckan'),
                    'sqlalchemy.url':
                    conv.default(
                        'postgresql://*****:*****@localhost/ckan_default'
                    ),
                    # Whether this application serves its own static files.
                    'static_files':
                    conv.pipe(conv.guess_bool, conv.default(True)),
                    'static_files_dir':
                    conv.default(os.path.join(app_dir, 'static')),
                    'domain':
                    conv.default('data.gouv.fr'),
                    'home_url':
                    conv.default('http://www.data.gouv.fr'),
                    'wiki_url':
                    conv.default('http://wiki.data.gouv.fr/wiki'),
                    'wiki_api_url':
                    conv.default('http://wiki.data.gouv.fr/api.php'),
                    'questions_url':
                    conv.default('http://questions.data.gouv.fr'),
                    'ckan_url':
                    conv.default('http://ckan.data.gouv.fr'),
                    'cow_url':
                    conv.default('http://cow.data.gouv.fr'),
                    'sso_url':
                    conv.default('http://id.data.gouv.fr'),
                    'ws_url':
                    conv.default('http://log.data.gouv.fr'),
                    'territory_api_url':
                    conv.default('http://ou.comarquage.fr/api/v1'),
                    'bot_name':
                    conv.default('bot-at-data-gouv-fr'),
                    'https':
                    conv.pipe(conv.guess_bool, conv.default(False)),
                    'sentry.dsn':
                    conv.default(False),
                    'piwik.url':
                    conv.default(False),
                    'piwik.site_id':
                    conv.pipe(conv.input_to_int, conv.default(0)),
                    'piwik.in_debug':
                    conv.pipe(conv.guess_bool, conv.default(False)),
                    'piwik.domain':
                    conv.default(False),
                    'piwik.goals':
                    conv.default(''),
                },
                default='drop',
            ))(conf))

    # CDN configuration
    conf.update(
        conv.check(
            conv.struct(
                {
                    'bootstrap':
                    conv.pipe(
                        conv.make_input_to_url(),
                        conv.default(
                            urlparse.urljoin(conf['cdn'],
                                             '/bootstrap/latest/')),
                        conv.function(lambda url: url.rstrip(u'/') + u'/')),
                    'jquery.js':
                    conv.pipe(
                        conv.make_input_to_url(),
                        conv.default(
                            urlparse.urljoin(conf['cdn'],
                                             '/jquery/jquery.min.js')),
                    ),
                    #            'select2': conv.pipe(
                    #                conv.make_input_to_url(),
                    #                conv.default(urlparse.urljoin(conf['cdn'], '/select2/latest/')),
                    #                conv.function(lambda url: url.rstrip(u'/') + u'/')
                    #                ),
                },
                default=conv.noop,
            ))(conf))

    # Configure logging.
    logging.basicConfig(level=conf['log_level'], stream=sys.stderr)

    #    errorware = conf.setdefault('errorware', {})
    #    errorware['debug'] = conf['debug']
    #    if not errorware['debug']:
    #        errorware['error_email'] = conf['email_to']
    #        errorware['error_log'] = conf.get('error_log', None)
    #        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
    #        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'Weckan Error: ')
    #        errorware['from_address'] = conf['from_address']
    #        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Intialize CKAN model
    # For PostgreSQL we want to enforce utf-8.
    sqlalchemy_url = conf.get('sqlalchemy.url', '')
    if sqlalchemy_url.startswith('postgresql://'):
        extras = {'client_encoding': 'utf8'}
    else:
        extras = {}
    sql_engine = sqlalchemy.engine_from_config(conf, 'sqlalchemy.', **extras)
    model.init_model(sql_engine)

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = templates_dirs = []
    if conf['custom_templates_dir']:
        templates_dirs.append(conf['custom_templates_dir'])
    templates_dirs.append(os.path.join(app_dir, 'templates'))
Esempio n. 14
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = weckan.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(conv.check(conv.struct(
        {
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'cdn': conv.pipe(
                conv.make_input_to_url(),
                conv.default('//localhost:7000'),
                ),
            'cookie': conv.default('weckan'),
            'custom_templates_dir': conv.pipe(
                conv.empty_to_none,
                conv.test(os.path.exists),
                ),
            'customs_dir': conv.default(None),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'global_conf': conv.set_value(global_conf),
            'host_urls': conv.pipe(
                conv.function(lambda host_urls: host_urls.split()),
                conv.uniform_sequence(
                    conv.make_input_to_url(error_if_fragment = True, error_if_path = True, error_if_query = True,
                        full = True, schemes = (u'ws', u'wss')),
                    constructor = lambda host_urls: sorted(set(host_urls)),
                    ),
                ),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('weckan'),
            'realm': conv.default(u'Weckan'),
            'sqlalchemy.url': conv.default('postgresql://*****:*****@localhost/ckan_default'),
            # Whether this application serves its own static files.
            'static_files': conv.pipe(conv.guess_bool, conv.default(True)),
            'static_files_dir': conv.default(os.path.join(app_dir, 'static')),
            'domain': conv.default('data.gouv.fr'),
            'home_url': conv.default('http://www.data.gouv.fr'),
            'wiki_url': conv.default('http://wiki.data.gouv.fr/wiki'),
            'wiki_api_url': conv.default('http://wiki.data.gouv.fr/api.php'),
            'questions_url': conv.default('http://questions.data.gouv.fr'),
            'ckan_url': conv.default('http://ckan.data.gouv.fr'),
            'cow_url': conv.default('http://cow.data.gouv.fr'),
            'sso_url': conv.default('http://id.data.gouv.fr'),
            'ws_url': conv.default('http://log.data.gouv.fr'),
            'territory_api_url': conv.default('http://ou.comarquage.fr/api/v1'),
            'bot_name': conv.default('bot-at-data-gouv-fr'),
            'https': conv.pipe(conv.guess_bool, conv.default(False)),
            'sentry.dsn': conv.default(False),
            'piwik.url': conv.default(False),
            'piwik.site_id': conv.pipe(conv.input_to_int, conv.default(0)),
            'piwik.in_debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'piwik.domain': conv.default(False),
            'piwik.goals': conv.default(''),
            },
        default = 'drop',
        ))(conf))

    # CDN configuration
    conf.update(conv.check(conv.struct(
        {
            'bootstrap': conv.pipe(
                conv.make_input_to_url(),
                conv.default(urlparse.urljoin(conf['cdn'], '/bootstrap/latest/')),
                conv.function(lambda url: url.rstrip(u'/') + u'/')
                ),
            'jquery.js': conv.pipe(
                conv.make_input_to_url(),
                conv.default(urlparse.urljoin(conf['cdn'], '/jquery/jquery.min.js')),
                ),
#            'select2': conv.pipe(
#                conv.make_input_to_url(),
#                conv.default(urlparse.urljoin(conf['cdn'], '/select2/latest/')),
#                conv.function(lambda url: url.rstrip(u'/') + u'/')
#                ),
            },
        default = conv.noop,
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

#    errorware = conf.setdefault('errorware', {})
#    errorware['debug'] = conf['debug']
#    if not errorware['debug']:
#        errorware['error_email'] = conf['email_to']
#        errorware['error_log'] = conf.get('error_log', None)
#        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
#        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'Weckan Error: ')
#        errorware['from_address'] = conf['from_address']
#        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Intialize CKAN model
    # For PostgreSQL we want to enforce utf-8.
    sqlalchemy_url = conf.get('sqlalchemy.url', '')
    if sqlalchemy_url.startswith('postgresql://'):
        extras = {'client_encoding': 'utf8'}
    else:
        extras = {}
    sql_engine = sqlalchemy.engine_from_config(conf, 'sqlalchemy.', **extras)
    model.init_model(sql_engine)

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dirs = templates_dirs = []
    if conf['custom_templates_dir']:
        templates_dirs.append(conf['custom_templates_dir'])
    templates_dirs.append(os.path.join(app_dir, 'templates'))
Esempio n. 15
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = openfisca_web_site.conf  # Empty dictionary
    conf.update(strings.deep_decode(global_conf))
    conf.update(strings.deep_decode(app_conf))
    conf.update(
        conv.check(
            conv.struct(
                {
                    'app_conf':
                    conv.set_value(app_conf, handle_none_value=True),
                    'app_dir':
                    conv.set_value(app_dir, handle_none_value=True),
                    'cache_dir':
                    conv.default(
                        os.path.join(os.path.dirname(app_dir), 'cache')),
                    'cookie':
                    conv.default('openfisca_web_site'),
                    'custom_templates_dir':
                    conv.pipe(
                        conv.empty_to_none,
                        conv.test(os.path.exists),
                    ),
                    'customs_dir':
                    conv.default(None),
                    'debug':
                    conv.pipe(conv.guess_bool, conv.default(False)),
                    'global_conf':
                    conv.set_value(global_conf, handle_none_value=True),
                    'google_analytics.key':
                    conv.empty_to_none,
                    'host_urls':
                    conv.pipe(
                        conv.function(lambda host_urls: host_urls.split()),
                        conv.uniform_sequence(
                            conv.make_input_to_url(error_if_fragment=True,
                                                   error_if_path=True,
                                                   error_if_query=True,
                                                   full=True,
                                                   schemes=(u'ws', u'wss')),
                            constructor=lambda host_urls: sorted(set(host_urls)
                                                                 ),
                        ),
                    ),
                    'i18n_dir':
                    conv.default(os.path.join(app_dir, 'i18n')),
                    'languages':
                    conv.pipe(
                        conv.cleanup_line,
                        conv.function(lambda value: value.split(',')),
                        conv.uniform_sequence(conv.input_to_slug),
                    ),
                    'log_level':
                    conv.pipe(
                        conv.default('WARNING'),
                        conv.function(lambda log_level: getattr(
                            logging, log_level.upper())),
                    ),
                    'package_name':
                    conv.default('openfisca-web-site'),
                    'piwik.key':
                    conv.input_to_int,
                    'piwik.url':
                    conv.make_input_to_url(error_if_fragment=True,
                                           error_if_path=True,
                                           error_if_query=True,
                                           full=True),
                    'realm':
                    conv.default(u'OpenFisca-Web-Site'),
                    # Whether this application serves its own static files.
                    'static_files':
                    conv.pipe(conv.guess_bool, conv.default(True)),
                    'static_files_dir':
                    conv.default(os.path.join(app_dir, 'static')),
                    'twitter.access_token_key':
                    conv.cleanup_line,
                    'twitter.access_token_secret':
                    conv.cleanup_line,
                    'twitter.consumer_key':
                    conv.cleanup_line,
                    'twitter.consumer_secret':
                    conv.cleanup_line,
                    'urls.api':
                    conv.pipe(
                        conv.make_input_to_url(error_if_fragment=True,
                                               error_if_path=True,
                                               error_if_query=True,
                                               full=True),
                        conv.not_none,
                    ),
                    'urls.ui':
                    conv.pipe(
                        conv.make_input_to_url(error_if_fragment=True,
                                               error_if_path=True,
                                               error_if_query=True,
                                               full=True),
                        conv.not_none,
                    ),
                    'urls.other_www_by_country':
                    conv.pipe(
                        conv.cleanup_line,
                        conv.function(lambda value: value.split('\n')),
                        conv.uniform_sequence(
                            conv.pipe(
                                conv.function(lambda value: value.split('=')),
                                conv.uniform_sequence(conv.cleanup_line),
                            )),
                        conv.function(lambda value: dict(value)),
                        conv.uniform_mapping(
                            conv.noop,
                            conv.pipe(
                                conv.make_input_to_url(error_if_fragment=True,
                                                       error_if_path=True,
                                                       error_if_query=True,
                                                       full=True),
                                conv.not_none,
                            )),
                    ),
                },
                default='drop',
            ))(conf))

    # Configure logging.
    logging.basicConfig(level=conf['log_level'], stream=sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get(
            'error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get(
            'error_subject_prefix', 'OpenFisca-Web-Site Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Create the Mako TemplateLookup, with the default auto-escaping.
    templates.dir = os.path.join(app_dir, 'templates')
Esempio n. 16
0
def load_environment(global_conf, app_conf):
    """Configure the application environment."""
    conf = openfisca_web_api.conf  # Empty dictionary
    encoding = sys.stdout.encoding
    conf.update(strings.deep_decode(global_conf, encoding))
    conf.update(strings.deep_decode(app_conf, encoding))
    conf.update(conv.check(conv.struct(
        {
            'app_conf': conv.set_value(app_conf),
            'app_dir': conv.set_value(app_dir),
            'cache_dir': conv.default(os.path.join(os.path.dirname(app_dir), 'cache')),
            'country_package': conv.pipe(
                conv.make_input_to_slug(separator = u'_'),
                conv.test_in((
                    u'openfisca_france',
                    u'openfisca_tunisia',
                    u'openfisca_tunisia_pension',
                    )),
                conv.not_none,
                ),
            'debug': conv.pipe(conv.guess_bool, conv.default(False)),
            'global_conf': conv.set_value(global_conf),
            'i18n_dir': conv.default(os.path.join(app_dir, 'i18n')),
            'load_alert': conv.pipe(conv.guess_bool, conv.default(False)),
            'log_level': conv.pipe(
                conv.default('WARNING'),
                conv.function(lambda log_level: getattr(logging, log_level.upper())),
                ),
            'package_name': conv.default('openfisca-web-api'),
            'realm': conv.default(u'OpenFisca Web API'),
            },
        default = 'drop',
        ))(conf))

    # Configure logging.
    logging.basicConfig(level = conf['log_level'], stream = sys.stderr)

    errorware = conf.setdefault('errorware', {})
    errorware['debug'] = conf['debug']
    if not errorware['debug']:
        errorware['error_email'] = conf['email_to']
        errorware['error_log'] = conf.get('error_log', None)
        errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
        errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'OpenFisca Web API Error: ')
        errorware['from_address'] = conf['from_address']
        errorware['smtp_server'] = conf.get('smtp_server', 'localhost')

    # Initialize tax-benefit system.
    country_package = importlib.import_module(conf['country_package'])
    conv.State.TaxBenefitSystem = country_package.init_country()

    # Initialize caches, pre-fill with default values.
    country_decompositions = importlib.import_module('{}.decompositions'.format(conf['country_package']))
    default_tax_benefit_system = conv.State.TaxBenefitSystem()
    conv.State.decomposition_json_by_file_path = {}
    decomposition_file_path = os.path.join(default_tax_benefit_system.DECOMP_DIR,
        country_decompositions.DEFAULT_DECOMP_FILE)
    conv.State.decomposition_json_by_file_path[decomposition_file_path] = model.get_decomposition_json(
        decomposition_file_path, default_tax_benefit_system)
    conv.State.tax_benefit_system_instances_by_json = {} # TODO Rename: tax_benefit_system_instance_by_json
    # None key means that there are no attributes.
    conv.State.tax_benefit_system_instances_by_json[None] = default_tax_benefit_system