예제 #1
0
파일: crypto.py 프로젝트: unikmhz/npui
def includeme(config):
    cfg = config.registry.settings
    enabled_for = make_config_dict(cfg, 'netprofile.auth.enabled_for.')
    default_hash = make_config_dict(cfg, 'netprofile.auth.default_hash.')

    _DEFAULT_HANDLERS.update(default_hash)

    for subject, methods in enabled_for.items():
        methods = aslist(methods)
        default = _DEFAULT_HANDLERS.setdefault(subject, 'scrypt')
        if default not in methods:
            methods.append(default)
        _ENABLED_HANDLERS[subject] = methods

    for scheme in _HANDLERS:
        _HANDLERS[scheme] = _HANDLERS[scheme](cfg)
예제 #2
0
파일: tasks.py 프로젝트: hermes-jr/npui
def task_generate(srv_ids=(), station_ids=()):
	cfg = app.settings
	rconf = make_config_dict(cfg, 'netprofile.rt.redis.')
	factory = ConfigGeneratorFactory(cfg, app.mmgr)

	ret = []
	sess = DBSession()
	rsess = redis.Redis(**rconf)
	loc = sys_localizer(app.mmgr.cfg.registry)

	q = sess.query(Server)
	if len(srv_ids) > 0:
		q = q.filter(Server.id.in_(srv_ids))
	if len(station_ids) > 0:
		q = q.filter(Server.host_id.in_(station_ids))
	for srv in q:
		gen = factory.get(srv.type.generator_name)
		logger.info('Generating config of type %s for host %s', srv.type.generator_name, str(srv.host))
		gen.generate(srv)
		ret.append(loc.translate(_('Successfully generated %s configuration for host %s.')) % (
			srv.type.name,
			str(srv.host)
		))

	hosts = factory.deploy()
	ret.append(loc.translate(_('Successfully deployed configuration for hosts: %s.')) % (', '.join(hosts),))

	factory.restore_umask()
	transaction.commit()
	return ret
예제 #3
0
파일: __init__.py 프로젝트: annndrey/npui
def _pdf_style_sheet(cfg):
	settings = cfg.registry.settings
	try:
		ffamily = _register_fonts(settings)
	except ttfonts.TTFError:
		logger.error('Can\'t find or register configured fonts. PDF generation will be disabled.')
		return None
	if ffamily == 'Times-Roman':
		fonts = ('Times-Roman', 'Times-Bold', 'Times-Italic', 'Times-BoldItalic')
	else:
		fonts = (ffamily, ffamily + '_b', ffamily + '_i', ffamily + '_bi')

	ss = styles.StyleSheet1()

	ss.add(styles.ParagraphStyle(
		name='default',
		fontName=fonts[0],
		fontSize=10,
		leading=12
	))
	ss.add(styles.ParagraphStyle(
		name='body',
		parent=ss['default'],
		spaceBefore=6
	))
	ss.add(styles.ParagraphStyle(
		name='bold',
		parent=ss['body'],
		fontName=fonts[1],
		alias='strong'
	))
	ss.add(styles.ParagraphStyle(
		name='italic',
		parent=ss['body'],
		fontName=fonts[2],
		alias='em'
	))
	ss.add(styles.ParagraphStyle(
		name='title',
		parent=ss['body'],
		fontName=fonts[1],
		fontSize=14
	))
	ss.add(styles.ParagraphStyle(
		name='table_header',
		parent=ss['body'],
		fontName=fonts[1],
		alias='th'
	))

	custom_ss = make_config_dict(settings, 'netprofile.pdf_styles.')
	if len(custom_ss) > 0:
		custom_ss = as_dict(custom_ss)
		for name in custom_ss:
			pass # FIXME: write this

	logger.debug('Loaded preconfigured PDF fonts and styles.')
	return ss
예제 #4
0
파일: rt.py 프로젝트: annndrey/npui
 def app(self):
     cfg = make_config_dict(self.reg.settings, 'netprofile.rt.')
     settings = {
         'template_path':
         os.path.join(os.path.dirname(netprofile.__file__), 'templates')
     }
     app = tornado.web.Application(self.routes, **settings)
     app.sess = self
     app.hm = self.reg.getUtility(IHookManager)
     return app
예제 #5
0
파일: __init__.py 프로젝트: annndrey/npui
def _pdf_style_sheet(cfg):
    settings = cfg.registry.settings
    try:
        ffamily = _register_fonts(settings)
    except ttfonts.TTFError:
        logger.error(
            'Can\'t find or register configured fonts. PDF generation will be disabled.'
        )
        return None
    if ffamily == 'Times-Roman':
        fonts = ('Times-Roman', 'Times-Bold', 'Times-Italic',
                 'Times-BoldItalic')
    else:
        fonts = (ffamily, ffamily + '_b', ffamily + '_i', ffamily + '_bi')

    ss = styles.StyleSheet1()

    ss.add(
        styles.ParagraphStyle(name='default',
                              fontName=fonts[0],
                              fontSize=10,
                              leading=12))
    ss.add(
        styles.ParagraphStyle(name='body', parent=ss['default'],
                              spaceBefore=6))
    ss.add(
        styles.ParagraphStyle(name='bold',
                              parent=ss['body'],
                              fontName=fonts[1],
                              alias='strong'))
    ss.add(
        styles.ParagraphStyle(name='italic',
                              parent=ss['body'],
                              fontName=fonts[2],
                              alias='em'))
    ss.add(
        styles.ParagraphStyle(name='title',
                              parent=ss['body'],
                              fontName=fonts[1],
                              fontSize=14))
    ss.add(
        styles.ParagraphStyle(name='table_header',
                              parent=ss['body'],
                              fontName=fonts[1],
                              alias='th'))

    custom_ss = make_config_dict(settings, 'netprofile.pdf_styles.')
    if len(custom_ss) > 0:
        custom_ss = as_dict(custom_ss)
        for name in custom_ss:
            pass  # FIXME: write this

    logger.debug('Loaded preconfigured PDF fonts and styles.')
    return ss
예제 #6
0
파일: rt.py 프로젝트: annndrey/npui
	def app(self):
		cfg = make_config_dict(self.reg.settings, 'netprofile.rt.')
		settings = {
			'template_path' : os.path.join(
				os.path.dirname(netprofile.__file__),
				'templates'
			)
		}
		app = tornado.web.Application(self.routes, **settings)
		app.sess = self
		app.hm = self.reg.getUtility(IHookManager)
		return app
예제 #7
0
파일: views.py 프로젝트: baloon11/npui
def js_webshell(request):
	request.response.content_type = 'text/javascript'
	request.response.charset = 'UTF-8'
	rtcfg = make_config_dict(request.registry.settings, 'netprofile.rt.')
	mmgr = request.registry.getUtility(IModuleManager)
	return {
		'cur_loc' : get_locale_name(request),
		'res_ajs' : mmgr.get_autoload_js(request),
		'res_ctl' : mmgr.get_controllers(request),
		'rt_host' : rtcfg.get('host', 'localhost'),
		'rt_port' : rtcfg.get('port', 8808),
		'modules' : mmgr.get_module_browser()
	}
예제 #8
0
파일: rt.py 프로젝트: annndrey/npui
def configure(mmgr, reg):
	cfg = reg.settings
	rconf = make_config_dict(cfg, 'netprofile.rt.redis.')
	trconf = rconf.copy()
	if 'db' in rconf:
		del trconf['db']
		trconf['selected_db'] = rconf['db']
	if 'socket_timeout' in rconf:
		del trconf['socket_timeout']
	if 'charset' in rconf:
		del trconf['charset']
	if 'decode_responses' in rconf:
		del trconf['decode_responses']
	return RTSession(reg, rconf, trconf)
예제 #9
0
파일: rt.py 프로젝트: baloon11/npui
def run(sess, app):
	cfg = make_config_dict(sess.reg.settings, 'netprofile.rt.')
	sslopts = None
	if cfg.get('ssl'):
		sslopts = {}
		if 'certfile' in cfg:
			sslopts['certfile'] = cfg['certfile']
		if 'keyfile' in cfg:
			sslopts['keyfile'] = cfg['keyfile']
	http_server = tornado.httpserver.HTTPServer(app, ssl_options=sslopts)
	http_server.listen(cfg.get('port'))
#	http_server.bind(cfg.get('port'))
#	http_server.start(0)
	tornado.ioloop.IOLoop.instance().start()
예제 #10
0
파일: rt.py 프로젝트: annndrey/npui
def configure(mmgr, reg):
    cfg = reg.settings
    rconf = make_config_dict(cfg, 'netprofile.rt.redis.')
    trconf = rconf.copy()
    if 'db' in rconf:
        del trconf['db']
        trconf['selected_db'] = rconf['db']
    if 'socket_timeout' in rconf:
        del trconf['socket_timeout']
    if 'charset' in rconf:
        del trconf['charset']
    if 'decode_responses' in rconf:
        del trconf['decode_responses']
    return RTSession(reg, rconf, trconf)
예제 #11
0
파일: rt.py 프로젝트: unikmhz/npui
def run(sess):
    cfg = make_config_dict(sess.reg.settings, 'netprofile.rt.')
    sslopts = None
    if cfg.get('ssl'):
        sslopts = {}
        if 'certfile' in cfg:
            sslopts['certfile'] = cfg['certfile']
        if 'keyfile' in cfg:
            sslopts['keyfile'] = cfg['keyfile']
    app = sess.app()
    http_server = tornado.httpserver.HTTPServer(app, ssl_options=sslopts)
    http_server.bind(int(cfg.get('port', 8808)))
    http_server.start(int(cfg.get('processes', 0)))
    sess.add_sockjs_routes(app)
    iol = tornado.ioloop.IOLoop.current()
    setup_celery(sess.reg)
    iol.start()

    return 0
예제 #12
0
파일: __init__.py 프로젝트: annndrey/npui
def _register_fonts(settings):
    default_fontdir = settings.get('netprofile.fonts.directory', '')
    default_family = settings.get('netprofile.fonts.default_family', 'tinos')
    fontcfg = make_config_dict(settings, 'netprofile.fonts.family.')
    fontcfg = as_dict(fontcfg)
    for fname, cfg in fontcfg.items():
        if 'normal' not in cfg:
            continue
        fname = cfg.get('name', fname)
        fontdir = cfg.get('directory', default_fontdir)
        pdfmetrics.registerFont(
            ttfonts.TTFont(fname, os.path.join(fontdir, cfg['normal'])))
        reg = {'normal': fname}

        if 'bold' in cfg:
            reg['bold'] = fname + '_b'
            pdfmetrics.registerFont(
                ttfonts.TTFont(reg['bold'], os.path.join(fontdir,
                                                         cfg['bold'])))
        else:
            reg['bold'] = fname

        if 'italic' in cfg:
            reg['italic'] = fname + '_i'
            pdfmetrics.registerFont(
                ttfonts.TTFont(reg['italic'],
                               os.path.join(fontdir, cfg['italic'])))
        else:
            reg['italic'] = fname

        if 'bold_italic' in cfg:
            reg['boldItalic'] = fname + '_bi'
            pdfmetrics.registerFont(
                ttfonts.TTFont(reg['boldItalic'],
                               os.path.join(fontdir, cfg['bold_italic'])))
        else:
            reg['boldItalic'] = fname

        pdfmetrics.registerFontFamily(fname, **reg)

    if default_family in fontcfg:
        return default_family
    return 'Times-Roman'
예제 #13
0
파일: rt.py 프로젝트: annndrey/npui
def run(sess):
    cfg = make_config_dict(sess.reg.settings, 'netprofile.rt.')
    sslopts = None
    if cfg.get('ssl'):
        sslopts = {}
        if 'certfile' in cfg:
            sslopts['certfile'] = cfg['certfile']
        if 'keyfile' in cfg:
            sslopts['keyfile'] = cfg['keyfile']
    app = sess.app()
    http_server = tornado.httpserver.HTTPServer(app, ssl_options=sslopts)
    http_server.bind(int(cfg.get('port', 8808)))
    http_server.start(int(cfg.get('processes', 0)))
    sess.add_sockjs_routes(app)
    iol = tornado.ioloop.IOLoop.current()
    setup_celery(sess.reg)
    tcelery.setup_nonblocking_producer(celery_app, io_loop=iol)
    iol.start()

    return 0
예제 #14
0
파일: celery.py 프로젝트: annndrey/npui
def _parse_ini_settings(reg, celery):
    settings = reg.settings
    cfg = make_config_dict(settings, 'celery.')
    newconf = {}

    if 'broker' in cfg:
        newconf['BROKER_URL'] = cfg['broker']
    if 'broker.heartbeat' in cfg:
        newconf['BROKER_HEARTBEAT'] = cfg['broker.heartbeat']
    if 'broker.heartbeat.checkrate' in cfg:
        newconf['BROKER_HEARTBEAT_CHECKRATE'] = cfg[
            'broker.heartbeat.checkrate']
    if 'broker.use_ssl' in cfg:
        newconf['BROKER_USE_SSL'] = cfg['broker.use_ssl']
    if 'broker.pool_limit' in cfg:
        newconf['BROKER_POOL_LIMIT'] = cfg['broker.pool_limit']
    if 'broker.connection.timeout' in cfg:
        newconf['BROKER_CONNECTION_TIMEOUT'] = cfg['broker.connection.timeout']
    if 'broker.connection.retry' in cfg:
        newconf['BROKER_CONNECTION_RETRY'] = cfg['broker.connection.retry']
    if 'broker.connection.max_retries' in cfg:
        newconf['BROKER_CONNECTION_MAX_RETRIES'] = cfg[
            'broker.connection.max_retries']
    if 'broker.login_method' in cfg:
        newconf['BROKER_LOGIN_METHOD'] = cfg['broker.login_method']

    if 'backend' in cfg:
        newconf['CELERY_RESULT_BACKEND'] = cfg['backend']
    if 'task_result_expires' in cfg:
        newconf['CELERY_TASK_RESULT_EXPIRES'] = cfg['task_result_expires']
    if 'task_publish_retry' in cfg:
        newconf['CELERY_TASK_PUBLISH_RETRY'] = cfg['task_publish_retry']
    if 'enable_utc' in cfg:
        newconf['CELERY_ENABLE_UTC'] = cfg['enable_utc']
    if 'timezone' in cfg:
        newconf['CELERY_TIMEZONE'] = cfg['timezone']
    if 'always_eager' in cfg:
        newconf['CELERY_ALWAYS_EAGER'] = cfg['always_eager']
    if 'eager_propagates_exceptions' in cfg:
        newconf['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = cfg[
            'eager_propagates_exceptions']
    if 'ignore_result' in cfg:
        newconf['CELERY_IGNORE_RESULT'] = cfg['ignore_result']
    if 'store_errors_even_if_ignored' in cfg:
        newconf['CELERY_STORE_ERRORS_EVEN_IF_IGNORED'] = cfg[
            'store_errors_even_if_ignored']
    if 'message_compression' in cfg:
        newconf['CELERY_MESSAGE_COMPRESSION'] = cfg['message_compression']
    if 'max_cached_results' in cfg:
        newconf['CELERY_MAX_CACHED_RESULTS'] = cfg['max_cached_results']
    if 'chord_propagates' in cfg:
        newconf['CELERY_CHORD_PROPAGATES'] = cfg['chord_propagates']
    if 'track_started' in cfg:
        newconf['CELERY_TRACK_STARTED'] = cfg['track_started']
    if 'default_rate_limit' in cfg:
        newconf['CELERY_DEFAULT_RATE_LIMIT'] = cfg['default_rate_limit']
    if 'disable_rate_limits' in cfg:
        newconf['CELERY_DISABLE_RATE_LIMITS'] = cfg['disable_rate_limits']
    if 'acks_late' in cfg:
        newconf['CELERY_ACKS_LATE'] = cfg['acks_late']

    if 'accept_content' in cfg:
        newconf['CELERY_ACCEPT_CONTENT'] = aslist(cfg['accept_content'])
    else:
        newconf['CELERY_ACCEPT_CONTENT'] = ('msgpack', )

    if 'task_serializer' in cfg:
        newconf['CELERY_TASK_SERIALIZER'] = cfg['task_serializer']
    else:
        newconf['CELERY_TASK_SERIALIZER'] = 'msgpack'
    if 'result_serializer' in cfg:
        newconf['CELERY_RESULT_SERIALIZER'] = cfg['result_serializer']
    else:
        newconf['CELERY_RESULT_SERIALIZER'] = 'msgpack'
    if 'event_serializer' in cfg:
        newconf['CELERY_EVENT_SERIALIZER'] = cfg['event_serializer']
    else:
        newconf['CELERY_EVENT_SERIALIZER'] = 'msgpack'

    if 'result_exchange' in cfg:
        newconf['CELERY_RESULT_EXCHANGE'] = cfg['result_exchange']
    if 'result_exchange_type' in cfg:
        newconf['CELERY_RESULT_EXCHANGE_TYPE'] = cfg['result_exchange_type']
    if 'result_persistent' in cfg:
        newconf['CELERY_RESULT_PERSISTENT'] = cfg['result_persistent']
    if 'routes' in cfg:
        newconf['CELERY_ROUTES'] = aslist(cfg['routes'])
    if 'worker_direct' in cfg:
        newconf['CELERY_WORKER_DIRECT'] = cfg['worker_direct']
    if 'create_missing_queues' in cfg:
        newconf['CELERY_CREATE_MISSING_QUEUES'] = cfg['create_missing_queues']
    if 'enable_remote_control' in cfg:
        newconf['CELERY_ENABLE_REMOTE_CONTROL'] = cfg['enable_remote_control']

    if 'send_task_error_emails' in cfg:
        newconf['CELERY_SEND_TASK_ERROR_EMAILS'] = cfg[
            'send_task_error_emails']


#	if 'admins' in cfg:
#		FIXME: list of tuples
    if 'server_email' in cfg:
        newconf['SERVER_EMAIL'] = cfg['server_email']
    if 'email_host' in cfg:
        newconf['EMAIL_HOST'] = cfg['email_host']
    if 'email_host_user' in cfg:
        newconf['EMAIL_HOST_USER'] = cfg['email_host_user']
    if 'email_host_password' in cfg:
        newconf['EMAIL_HOST_PASSWORD'] = cfg['email_host_password']
    if 'email_port' in cfg:
        newconf['EMAIL_PORT'] = cfg['email_port']
    if 'email_use_ssl' in cfg:
        newconf['EMAIL_USE_SSL'] = cfg['email_use_ssl']
    if 'email_use_tls' in cfg:
        newconf['EMAIL_USE_TLS'] = cfg['email_use_tls']
    if 'email_timeout' in cfg:
        newconf['EMAIL_TIMEOUT'] = cfg['email_timeout']

    if 'send_events' in cfg:
        newconf['CELERY_SEND_EVENTS'] = cfg['send_events']
    if 'send_task_sent_event' in cfg:
        newconf['CELERY_SEND_TASK_SENT_EVENT'] = cfg['send_task_sent_event']
    if 'event_queue_ttl' in cfg:
        newconf['CELERY_EVENT_QUEUE_TTL'] = cfg['event_queue_ttl']
    if 'event_queue_expires' in cfg:
        newconf['CELERY_EVENT_QUEUE_EXPIRES'] = cfg['event_queue_expires']
    if 'redirect_stdouts' in cfg:
        newconf['CELERY_REDIRECT_STDOUTS'] = cfg['redirect_stdouts']
    if 'redirect_stdouts_level' in cfg:
        newconf['CELERY_REDIRECT_STDOUTS_LEVEL'] = cfg[
            'redirect_stdouts_level']

    if 'queue_ha_policy' in cfg:
        qhp = aslist(cfg['queue_ha_policy'])
        if len(qhp) == 1:
            qhp = qhp[0]
        newconf['CELERY_QUEUE_HA_POLICY'] = qhp

    if 'security_key' in cfg:
        newconf['CELERY_SECURITY_KEY'] = cfg['security_key']
    if 'security_certificate' in cfg:
        newconf['CELERY_SECURITY_CERTIFICATE'] = cfg['security_certificate']
    if 'security_cert_store' in cfg:
        newconf['CELERY_SECURITY_CERT_STORE'] = cfg['security_cert_store']

    if 'default_queue' in cfg:
        newconf['CELERY_DEFAULT_QUEUE'] = cfg['default_queue']
    if 'default_exchange' in cfg:
        newconf['CELERY_DEFAULT_EXCHANGE'] = cfg['default_exchange']
    if 'default_exchange_type' in cfg:
        newconf['CELERY_DEFAULT_EXCHANGE_TYPE'] = cfg['default_exchange_type']
    if 'default_routing_key' in cfg:
        newconf['CELERY_DEFAULT_ROUTING_KEY'] = cfg['default_routing_key']
    if 'default_delivery_mode' in cfg:
        newconf['CELERY_DEFAULT_DELIVERY_MODE'] = cfg['default_delivery_mode']

    if 'concurrency' in cfg:
        newconf['CELERYD_CONCURRENCY'] = cfg['concurrency']
    if 'prefetch_multiplier' in cfg:
        newconf['CELERYD_PREFETCH_MULTIPLIER'] = cfg['prefetch_multiplier']
    if 'force_execv' in cfg:
        newconf['CELERYD_FORCE_EXECV'] = cfg['force_execv']
    if 'worker_lost_wait' in cfg:
        newconf['CELERYD_WORKER_LOST_WAIT'] = cfg['worker_lost_wait']
    if 'max_tasks_per_child' in cfg:
        newconf['CELERYD_MAX_TASKS_PER_CHILD'] = cfg['max_tasks_per_child']
    if 'task_time_limit' in cfg:
        newconf['CELERYD_TASK_TIME_LIMIT'] = cfg['task_time_limit']
    if 'task_soft_time_limit' in cfg:
        newconf['CELERYD_TASK_SOFT_TIME_LIMIT'] = cfg['task_soft_time_limit']
    if 'state_db' in cfg:
        newconf['CELERYD_STATE_DB'] = cfg['state_db']
    if 'timer_precision' in cfg:
        newconf['CELERYD_TIMER_PRECISION'] = cfg['timer_precision']
    if 'hijack_root_logger' in cfg:
        newconf['CELERYD_HIJACK_ROOT_LOGGER'] = cfg['hijack_root_logger']
    if 'log_color' in cfg:
        newconf['CELERYD_LOG_COLOR'] = cfg['log_color']
    if 'log_format' in cfg:
        newconf['CELERYD_LOG_FORMAT'] = cfg['log_format']
    if 'task_log_format' in cfg:
        newconf['CELERYD_TASK_LOG_FORMAT'] = cfg['task_log_format']
    if 'pool' in cfg:
        newconf['CELERYD_POOL'] = cfg['pool']
    if 'pool_restarts' in cfg:
        newconf['CELERYD_POOL_RESTARTS'] = cfg['pool_restarts']
    if 'autoscaler' in cfg:
        newconf['CELERYD_AUTOSCALER'] = cfg['autoscaler']
    if 'autoreloader' in cfg:
        newconf['CELERYD_AUTORELOADER'] = cfg['autoreloader']
    if 'consumer' in cfg:
        newconf['CELERYD_CONSUMER'] = cfg['consumer']
    if 'timer' in cfg:
        newconf['CELERYD_TIMER'] = cfg['timer']

    if 'celerymon_log_format' in cfg:
        newconf['CELERYMON_LOG_FORMAT'] = cfg['celerymon_log_format']

    if 'broadcast_queue' in cfg:
        newconf['CELERY_BROADCAST_QUEUE'] = cfg['broadcast_queue']
    if 'broadcast_exchange' in cfg:
        newconf['CELERY_BROADCAST_EXCHANGE'] = cfg['broadcast_exchange']
    if 'broadcast_exchange_type' in cfg:
        newconf['CELERY_BROADCAST_EXCHANGE_TYPE'] = cfg[
            'broadcast_exchange_type']

    if 'scheduler' in cfg:
        newconf['CELERYBEAT_SCHEDULER'] = cfg['scheduler']
    if 'schedule_filename' in cfg:
        newconf['CELERYBEAT_SCHEDULE_FILENAME'] = cfg['schedule_filename']
    if 'sync_every' in cfg:
        newconf['CELERYBEAT_SYNC_EVERY'] = cfg['sync_every']
    if 'max_loop_interval' in cfg:
        newconf['CELERYBEAT_MAX_LOOP_INTERVAL'] = cfg['max_loop_interval']

    # FIXME: complex python values!
    opts = make_config_dict(cfg, 'schedule.')
    if len(opts) > 0:
        newconf['CELERYBEAT_SCHEDULE'] = as_dict(opts)

    if 'redis_max_connections' in cfg:
        newconf['CELERY_REDIS_MAX_CONNECTIONS'] = cfg['redis_max_connections']

    opts = make_config_dict(cfg, 'broker.transport_options.')
    if len(opts) > 0:
        newconf['BROKER_TRANSPORT_OPTIONS'] = opts

    opts = make_config_dict(cfg, 'task_publish_retry_policy.')
    if len(opts) > 0:
        newconf['CELERY_TASK_PUBLISH_RETRY_POLICY'] = opts

    opts = make_config_dict(cfg, 'result_tables.')
    if len(opts) > 0:
        newconf['CELERY_RESULT_DB_TABLENAMES'] = opts

    opts = make_config_dict(cfg, 'result_options.')
    if len(opts) > 0:
        newconf['CELERY_RESULT_ENGINE_OPTIONS'] = opts

    opts = make_config_dict(cfg, 'cache_options.')
    if len(opts) > 0:
        newconf['CELERY_CACHE_BACKEND_OPTIONS'] = opts

    opts = make_config_dict(cfg, 'mongodb_options.')
    if len(opts) > 0:
        newconf['CELERY_MONGODB_BACKEND_SETTINGS'] = opts

    cass = make_config_dict(cfg, 'cassandra.')
    if 'servers' in cass:
        newconf['CASSANDRA_SERVERS'] = aslist(cass['servers'])
    if 'keyspace' in cass:
        newconf['CASSANDRA_KEYSPACE'] = cass['keyspace']
    if 'column_family' in cass:
        newconf['CASSANDRA_COLUMN_FAMILY'] = cass['column_family']
    if 'read_consistency' in cass:
        newconf['CASSANDRA_READ_CONSISTENCY'] = cass['read_consistency']
    if 'write_consistency' in cass:
        newconf['CASSANDRA_WRITE_CONSISTENCY'] = cass['write_consistency']
    if 'detailed_mode' in cass:
        newconf['CASSANDRA_DETAILED_MODE'] = cass['detailed_mode']
    opts = make_config_dict(cass, 'options.')
    if len(opts) > 0:
        newconf['CASSANDRA_OPTIONS'] = opts

    opts = make_config_dict(cfg, 'queues.')
    if len(opts) > 0:
        newconf['CELERY_QUEUES'] = opts
    else:
        newconf['CELERY_QUEUES'] = _default_queues

    mm = reg.getUtility(IModuleManager)

    opts = []
    if 'imports' in cfg:
        opts = aslist(cfg['imports'])
    for imp in mm.get_task_imports():
        opts.append(imp)
    if len(opts) > 0:
        newconf['CELERY_IMPORTS'] = opts

    opts = []
    if 'include' in cfg:
        opts = aslist(cfg['include'])
    # FIXME: hook module include here (?)
    if len(opts) > 0:
        newconf['CELERY_INCLUDE'] = opts

    if len(newconf) > 0:
        if isinstance(celery, Celery):
            celery.config_from_object(newconf)
        else:
            celery.update(newconf)
예제 #15
0
파일: __init__.py 프로젝트: unikmhz/npui
def _pdf_style_sheet(cfg):
    settings = cfg.registry.settings
    try:
        ffamily = _register_fonts(settings)
    except ttfonts.TTFError:
        logger.error('Can\'t find or register configured fonts. '
                     'PDF generation will be disabled.')
        return None
    if ffamily == 'Times-Roman':
        fonts = ('Times-Roman',
                 'Times-Bold',
                 'Times-Italic',
                 'Times-BoldItalic')
    else:
        fonts = (ffamily, ffamily + '_b', ffamily + '_i', ffamily + '_bi')

    ss = styles.StyleSheet1()

    ss.add(styles.ParagraphStyle(
        name='default',
        fontName=fonts[0],
        fontSize=10,
        leading=12,
        bulletFontName=fonts[0],
        bulletFontSize=10,
        bulletAnchor='start',
        bulletIndent=-1 * cm
    ))
    ss.add(styles.ParagraphStyle(
        name='body',
        parent=ss['default'],
        spaceBefore=6
    ))
    ss.add(styles.ParagraphStyle(
        name='bold',
        parent=ss['body'],
        fontName=fonts[1],
        bulletFontName=fonts[1]
    ), alias='strong')
    ss.add(styles.ParagraphStyle(
        name='italic',
        parent=ss['body'],
        fontName=fonts[2],
        bulletFontName=fonts[2]
    ), alias='em')
    ss.add(styles.ParagraphStyle(
        name='left',
        parent=ss['body'],
        alignment=TA_LEFT
    ))
    ss.add(styles.ParagraphStyle(
        name='center',
        parent=ss['body'],
        alignment=TA_CENTER
    ))
    ss.add(styles.ParagraphStyle(
        name='right',
        parent=ss['body'],
        alignment=TA_RIGHT
    ))
    ss.add(styles.ParagraphStyle(
        name='justify',
        parent=ss['body'],
        alignment=TA_JUSTIFY
    ))
    ss.add(styles.ParagraphStyle(
        name='heading',
        parent=ss['default'],
        spaceBefore=14
    ))
    ss.add(styles.ParagraphStyle(
        name='title',
        parent=ss['heading'],
        fontName=fonts[1],
        bulletFontName=fonts[1],
        fontSize=16,
        bulletFontSize=16,
        alignment=TA_CENTER
    ))
    ss.add(styles.ParagraphStyle(
        name='heading1',
        parent=ss['heading'],
        fontName=fonts[1],
        bulletFontName=fonts[1],
        fontSize=14,
        bulletFontSize=14
    ), alias='h1')
    ss.add(styles.ParagraphStyle(
        name='heading2',
        parent=ss['heading'],
        fontName=fonts[1],
        bulletFontName=fonts[1],
        fontSize=12,
        bulletFontSize=12
    ), alias='h2')
    ss.add(styles.ParagraphStyle(
        name='heading3',
        parent=ss['heading'],
        fontName=fonts[1],
        bulletFontName=fonts[1],
        fontSize=11,
        bulletFontSize=11
    ), alias='h3')
    ss.add(styles.ParagraphStyle(
        name='heading4',
        parent=ss['heading'],
        fontName=fonts[1],
        bulletFontName=fonts[1]
    ), alias='h4')
    ss.add(styles.ParagraphStyle(
        name='heading5',
        parent=ss['heading'],
        fontName=fonts[2],
        bulletFontName=fonts[2]
    ), alias='h5')
    ss.add(styles.ParagraphStyle(
        name='caption',
        parent=ss['body'],
        fontName=fonts[2],
        bulletFontName=fonts[2]
    ))
    ss.add(styles.ParagraphStyle(
        name='table_header',
        parent=ss['body'],
        fontName=fonts[1],
        bulletFontName=fonts[1]
    ), alias='th')

    custom_ss = make_config_dict(settings, 'netprofile.pdf_styles.')
    if len(custom_ss) > 0:
        custom_ss = as_dict(custom_ss)
        for name in custom_ss:
            pass  # FIXME: write this

    logger.debug('Loaded preconfigured PDF fonts and styles.')
    return ss
예제 #16
0
파일: ldap.py 프로젝트: annndrey/npui
def includeme(config):
	global _ldap_active, LDAPConn

	settings = config.registry.settings
	conn_cfg = make_config_dict(settings, 'netprofile.ldap.connection.')
	ssl_cfg = make_config_dict(conn_cfg, 'ssl.')
	auth_cfg = make_config_dict(conn_cfg, 'auth.')

	ldap_host = None
	server_opts = {}
	tls_opts = {}
	conn_opts = { 'lazy' : True }

	if 'uri' in conn_cfg:
		ldap_host = conn_cfg['uri']
	elif 'host' in conn_cfg:
		ldap_host = conn_cfg['host']

	if 'port' in conn_cfg:
		server_opts['port'] = conn_cfg['port']
	if 'protocol' in conn_cfg:
		conn_opts['version'] = conn_cfg['protocol']
	if 'type' in auth_cfg:
		value = auth_cfg['type']
		proc = None
		if value in ('anon', 'anonymous'):
			proc = ldap3.AUTH_ANONYMOUS
		elif value == 'simple':
			proc = ldap3.AUTH_SIMPLE
		elif value == 'sasl':
			proc = ldap3.AUTH_SASL
		elif value == 'ntlm':
			proc = ldap3.NTLM
		if proc:
			conn_opts['authentication'] = proc
	if ('user' in auth_cfg) and ('password' in auth_cfg):
		conn_opts['user'] = auth_cfg['user']
		conn_opts['password'] = auth_cfg['password']
		if 'authentication' not in conn_opts:
			conn_opts['authentication'] = ldap3.AUTH_SIMPLE
		bind = None
		bind_cfg = auth_cfg.get('bind')
		if bind_cfg == 'none':
			bind = ldap3.AUTO_BIND_NONE
		elif bind_cfg == 'no-tls':
			bind = ldap3.AUTO_BIND_NO_TLS
		elif bind_cfg == 'tls-before-bind':
			bind = ldap3.AUTO_BIND_TLS_BEFORE_BIND
		elif bind_cfg == 'tls-after-bind':
			bind = ldap3.AUTO_BIND_TLS_AFTER_BIND
		if bind:
			conn_opts['auto_bind'] = bind

	if ('key.file' in ssl_cfg) and ('cert.file' in ssl_cfg):
		tls_opts['local_private_key_file'] = ssl_cfg['key.file']
		tls_opts['local_certificate_file'] = ssl_cfg['cert.file']
	# TODO: version= in tls_opts
	if 'validate' in ssl_cfg:
		value = ssl_cfg['validate']
		if value == 'none':
			tls_opts['validate'] = ssl.CERT_NONE
		elif value == 'optional':
			tls_opts['validate'] = ssl.CERT_OPTIONAL
		elif value == 'required':
			tls_opts['validate'] = ssl.CERT_REQUIRED
	if 'ca.file' in ssl_cfg:
		tls_opts['ca_certs_file'] = ssl_cfg['ca.file']
	if 'altnames' in ssl_cfg:
		tls_opts['valid_names'] = aslist(ssl_cfg['altnames'])
	if 'ca.path' in ssl_cfg:
		tls_opts['ca_certs_path'] = ssl_cfg['ca.path']
	if 'ca.data' in ssl_cfg:
		tls_opts['ca_certs_data'] = ssl_cfg['ca.data']
	if 'key.password' in ssl_cfg:
		tls_opts['local_private_key_password'] = ssl_cfg['key.password']

	tls = None
	if len(tls_opts):
		tls = ldap3.Tls(**tls_opts)
		server_opts['use_ssl'] = True

	server = ldap3.Server(ldap_host, tls=tls, **server_opts)
	LDAPConn = ldap3.Connection(server, client_strategy=ldap3.REUSABLE, **conn_opts)
	LDAPConn.open()

	def get_system_ldap(request):
		return LDAPConn
	config.add_request_method(get_system_ldap, str('ldap'), reify=True)

	config.scan()
예제 #17
0
파일: ldap.py 프로젝트: annndrey/npui
def includeme(config):
    global _ldap_active, LDAPConn

    settings = config.registry.settings
    conn_cfg = make_config_dict(settings, 'netprofile.ldap.connection.')
    ssl_cfg = make_config_dict(conn_cfg, 'ssl.')
    auth_cfg = make_config_dict(conn_cfg, 'auth.')

    ldap_host = None
    server_opts = {}
    tls_opts = {}
    conn_opts = {'lazy': True}

    if 'uri' in conn_cfg:
        ldap_host = conn_cfg['uri']
    elif 'host' in conn_cfg:
        ldap_host = conn_cfg['host']

    if 'port' in conn_cfg:
        server_opts['port'] = conn_cfg['port']
    if 'protocol' in conn_cfg:
        conn_opts['version'] = conn_cfg['protocol']
    if 'type' in auth_cfg:
        value = auth_cfg['type']
        proc = None
        if value in ('anon', 'anonymous'):
            proc = ldap3.AUTH_ANONYMOUS
        elif value == 'simple':
            proc = ldap3.AUTH_SIMPLE
        elif value == 'sasl':
            proc = ldap3.AUTH_SASL
        elif value == 'ntlm':
            proc = ldap3.NTLM
        if proc:
            conn_opts['authentication'] = proc
    if ('user' in auth_cfg) and ('password' in auth_cfg):
        conn_opts['user'] = auth_cfg['user']
        conn_opts['password'] = auth_cfg['password']
        if 'authentication' not in conn_opts:
            conn_opts['authentication'] = ldap3.AUTH_SIMPLE
        bind = None
        bind_cfg = auth_cfg.get('bind')
        if bind_cfg == 'none':
            bind = ldap3.AUTO_BIND_NONE
        elif bind_cfg == 'no-tls':
            bind = ldap3.AUTO_BIND_NO_TLS
        elif bind_cfg == 'tls-before-bind':
            bind = ldap3.AUTO_BIND_TLS_BEFORE_BIND
        elif bind_cfg == 'tls-after-bind':
            bind = ldap3.AUTO_BIND_TLS_AFTER_BIND
        if bind:
            conn_opts['auto_bind'] = bind

    if ('key.file' in ssl_cfg) and ('cert.file' in ssl_cfg):
        tls_opts['local_private_key_file'] = ssl_cfg['key.file']
        tls_opts['local_certificate_file'] = ssl_cfg['cert.file']
    # TODO: version= in tls_opts
    if 'validate' in ssl_cfg:
        value = ssl_cfg['validate']
        if value == 'none':
            tls_opts['validate'] = ssl.CERT_NONE
        elif value == 'optional':
            tls_opts['validate'] = ssl.CERT_OPTIONAL
        elif value == 'required':
            tls_opts['validate'] = ssl.CERT_REQUIRED
    if 'ca.file' in ssl_cfg:
        tls_opts['ca_certs_file'] = ssl_cfg['ca.file']
    if 'altnames' in ssl_cfg:
        tls_opts['valid_names'] = aslist(ssl_cfg['altnames'])
    if 'ca.path' in ssl_cfg:
        tls_opts['ca_certs_path'] = ssl_cfg['ca.path']
    if 'ca.data' in ssl_cfg:
        tls_opts['ca_certs_data'] = ssl_cfg['ca.data']
    if 'key.password' in ssl_cfg:
        tls_opts['local_private_key_password'] = ssl_cfg['key.password']

    tls = None
    if len(tls_opts):
        tls = ldap3.Tls(**tls_opts)
        server_opts['use_ssl'] = True

    server = ldap3.Server(ldap_host, tls=tls, **server_opts)
    LDAPConn = ldap3.Connection(server,
                                client_strategy=ldap3.REUSABLE,
                                **conn_opts)
    LDAPConn.open()

    def get_system_ldap(request):
        return LDAPConn

    config.add_request_method(get_system_ldap, str('ldap'), reify=True)

    config.scan()
예제 #18
0
파일: celery.py 프로젝트: hermes-jr/npui
def _parse_ini_settings(reg, celery):
	settings = reg.settings
	cfg = make_config_dict(settings, 'celery.')
	newconf = {}

	if 'broker' in cfg:
		newconf['BROKER_URL'] = cfg['broker']
	if 'broker.heartbeat' in cfg:
		newconf['BROKER_HEARTBEAT'] = cfg['broker.heartbeat']
	if 'broker.heartbeat.checkrate' in cfg:
		newconf['BROKER_HEARTBEAT_CHECKRATE'] = cfg['broker.heartbeat.checkrate']
	if 'broker.use_ssl' in cfg:
		newconf['BROKER_USE_SSL'] = cfg['broker.use_ssl']
	if 'broker.pool_limit' in cfg:
		newconf['BROKER_POOL_LIMIT'] = cfg['broker.pool_limit']
	if 'broker.connection.timeout' in cfg:
		newconf['BROKER_CONNECTION_TIMEOUT'] = cfg['broker.connection.timeout']
	if 'broker.connection.retry' in cfg:
		newconf['BROKER_CONNECTION_RETRY'] = cfg['broker.connection.retry']
	if 'broker.connection.max_retries' in cfg:
		newconf['BROKER_CONNECTION_MAX_RETRIES'] = cfg['broker.connection.max_retries']
	if 'broker.login_method' in cfg:
		newconf['BROKER_LOGIN_METHOD'] = cfg['broker.login_method']

	if 'backend' in cfg:
		newconf['CELERY_RESULT_BACKEND'] = cfg['backend']
	if 'task_result_expires' in cfg:
		newconf['CELERY_TASK_RESULT_EXPIRES'] = cfg['task_result_expires']
	if 'task_publish_retry' in cfg:
		newconf['CELERY_TASK_PUBLISH_RETRY'] = cfg['task_publish_retry']
	if 'enable_utc' in cfg:
		newconf['CELERY_ENABLE_UTC'] = cfg['enable_utc']
	if 'timezone' in cfg:
		newconf['CELERY_TIMEZONE'] = cfg['timezone']
	if 'always_eager' in cfg:
		newconf['CELERY_ALWAYS_EAGER'] = cfg['always_eager']
	if 'eager_propagates_exceptions' in cfg:
		newconf['CELERY_EAGER_PROPAGATES_EXCEPTIONS'] = cfg['eager_propagates_exceptions']
	if 'ignore_result' in cfg:
		newconf['CELERY_IGNORE_RESULT'] = cfg['ignore_result']
	if 'store_errors_even_if_ignored' in cfg:
		newconf['CELERY_STORE_ERRORS_EVEN_IF_IGNORED'] = cfg['store_errors_even_if_ignored']
	if 'message_compression' in cfg:
		newconf['CELERY_MESSAGE_COMPRESSION'] = cfg['message_compression']
	if 'max_cached_results' in cfg:
		newconf['CELERY_MAX_CACHED_RESULTS'] = cfg['max_cached_results']
	if 'chord_propagates' in cfg:
		newconf['CELERY_CHORD_PROPAGATES'] = cfg['chord_propagates']
	if 'track_started' in cfg:
		newconf['CELERY_TRACK_STARTED'] = cfg['track_started']
	if 'default_rate_limit' in cfg:
		newconf['CELERY_DEFAULT_RATE_LIMIT'] = cfg['default_rate_limit']
	if 'disable_rate_limits' in cfg:
		newconf['CELERY_DISABLE_RATE_LIMITS'] = cfg['disable_rate_limits']
	if 'acks_late' in cfg:
		newconf['CELERY_ACKS_LATE'] = cfg['acks_late']

	if 'accept_content' in cfg:
		newconf['CELERY_ACCEPT_CONTENT'] = aslist(cfg['accept_content'])
	else:
		newconf['CELERY_ACCEPT_CONTENT'] = ('msgpack',)

	if 'task_serializer' in cfg:
		newconf['CELERY_TASK_SERIALIZER'] = cfg['task_serializer']
	else:
		newconf['CELERY_TASK_SERIALIZER'] = 'msgpack'
	if 'result_serializer' in cfg:
		newconf['CELERY_RESULT_SERIALIZER'] = cfg['result_serializer']
	else:
		newconf['CELERY_RESULT_SERIALIZER'] = 'msgpack'
	if 'event_serializer' in cfg:
		newconf['CELERY_EVENT_SERIALIZER'] = cfg['event_serializer']
	else:
		newconf['CELERY_EVENT_SERIALIZER'] = 'msgpack'

	if 'result_exchange' in cfg:
		newconf['CELERY_RESULT_EXCHANGE'] = cfg['result_exchange']
	if 'result_exchange_type' in cfg:
		newconf['CELERY_RESULT_EXCHANGE_TYPE'] = cfg['result_exchange_type']
	if 'result_persistent' in cfg:
		newconf['CELERY_RESULT_PERSISTENT'] = cfg['result_persistent']
	if 'routes' in cfg:
		newconf['CELERY_ROUTES'] = aslist(cfg['routes'])
	if 'worker_direct' in cfg:
		newconf['CELERY_WORKER_DIRECT'] = cfg['worker_direct']
	if 'create_missing_queues' in cfg:
		newconf['CELERY_CREATE_MISSING_QUEUES'] = cfg['create_missing_queues']
	if 'enable_remote_control' in cfg:
		newconf['CELERY_ENABLE_REMOTE_CONTROL'] = cfg['enable_remote_control']

	if 'send_task_error_emails' in cfg:
		newconf['CELERY_SEND_TASK_ERROR_EMAILS'] = cfg['send_task_error_emails']
#	if 'admins' in cfg:
#		FIXME: list of tuples
	if 'server_email' in cfg:
		newconf['SERVER_EMAIL'] = cfg['server_email']
	if 'email_host' in cfg:
		newconf['EMAIL_HOST'] = cfg['email_host']
	if 'email_host_user' in cfg:
		newconf['EMAIL_HOST_USER'] = cfg['email_host_user']
	if 'email_host_password' in cfg:
		newconf['EMAIL_HOST_PASSWORD'] = cfg['email_host_password']
	if 'email_port' in cfg:
		newconf['EMAIL_PORT'] = cfg['email_port']
	if 'email_use_ssl' in cfg:
		newconf['EMAIL_USE_SSL'] = cfg['email_use_ssl']
	if 'email_use_tls' in cfg:
		newconf['EMAIL_USE_TLS'] = cfg['email_use_tls']
	if 'email_timeout' in cfg:
		newconf['EMAIL_TIMEOUT'] = cfg['email_timeout']

	if 'send_events' in cfg:
		newconf['CELERY_SEND_EVENTS'] = cfg['send_events']
	if 'send_task_sent_event' in cfg:
		newconf['CELERY_SEND_TASK_SENT_EVENT'] = cfg['send_task_sent_event']
	if 'event_queue_ttl' in cfg:
		newconf['CELERY_EVENT_QUEUE_TTL'] = cfg['event_queue_ttl']
	if 'event_queue_expires' in cfg:
		newconf['CELERY_EVENT_QUEUE_EXPIRES'] = cfg['event_queue_expires']
	if 'redirect_stdouts' in cfg:
		newconf['CELERY_REDIRECT_STDOUTS'] = cfg['redirect_stdouts']
	if 'redirect_stdouts_level' in cfg:
		newconf['CELERY_REDIRECT_STDOUTS_LEVEL'] = cfg['redirect_stdouts_level']

	if 'queue_ha_policy' in cfg:
		qhp = aslist(cfg['queue_ha_policy'])
		if len(qhp) == 1:
			qhp = qhp[0]
		newconf['CELERY_QUEUE_HA_POLICY'] = qhp

	if 'security_key' in cfg:
		newconf['CELERY_SECURITY_KEY'] = cfg['security_key']
	if 'security_certificate' in cfg:
		newconf['CELERY_SECURITY_CERTIFICATE'] = cfg['security_certificate']
	if 'security_cert_store' in cfg:
		newconf['CELERY_SECURITY_CERT_STORE'] = cfg['security_cert_store']

	if 'default_queue' in cfg:
		newconf['CELERY_DEFAULT_QUEUE'] = cfg['default_queue']
	if 'default_exchange' in cfg:
		newconf['CELERY_DEFAULT_EXCHANGE'] = cfg['default_exchange']
	if 'default_exchange_type' in cfg:
		newconf['CELERY_DEFAULT_EXCHANGE_TYPE'] = cfg['default_exchange_type']
	if 'default_routing_key' in cfg:
		newconf['CELERY_DEFAULT_ROUTING_KEY'] = cfg['default_routing_key']
	if 'default_delivery_mode' in cfg:
		newconf['CELERY_DEFAULT_DELIVERY_MODE'] = cfg['default_delivery_mode']

	if 'concurrency' in cfg:
		newconf['CELERYD_CONCURRENCY'] = cfg['concurrency']
	if 'prefetch_multiplier' in cfg:
		newconf['CELERYD_PREFETCH_MULTIPLIER'] = cfg['prefetch_multiplier']
	if 'force_execv' in cfg:
		newconf['CELERYD_FORCE_EXECV'] = cfg['force_execv']
	if 'worker_lost_wait' in cfg:
		newconf['CELERYD_WORKER_LOST_WAIT'] = cfg['worker_lost_wait']
	if 'max_tasks_per_child' in cfg:
		newconf['CELERYD_MAX_TASKS_PER_CHILD'] = cfg['max_tasks_per_child']
	if 'task_time_limit' in cfg:
		newconf['CELERYD_TASK_TIME_LIMIT'] = cfg['task_time_limit']
	if 'task_soft_time_limit' in cfg:
		newconf['CELERYD_TASK_SOFT_TIME_LIMIT'] = cfg['task_soft_time_limit']
	if 'state_db' in cfg:
		newconf['CELERYD_STATE_DB'] = cfg['state_db']
	if 'timer_precision' in cfg:
		newconf['CELERYD_TIMER_PRECISION'] = cfg['timer_precision']
	if 'hijack_root_logger' in cfg:
		newconf['CELERYD_HIJACK_ROOT_LOGGER'] = cfg['hijack_root_logger']
	if 'log_color' in cfg:
		newconf['CELERYD_LOG_COLOR'] = cfg['log_color']
	if 'log_format' in cfg:
		newconf['CELERYD_LOG_FORMAT'] = cfg['log_format']
	if 'task_log_format' in cfg:
		newconf['CELERYD_TASK_LOG_FORMAT'] = cfg['task_log_format']
	if 'pool' in cfg:
		newconf['CELERYD_POOL'] = cfg['pool']
	if 'pool_restarts' in cfg:
		newconf['CELERYD_POOL_RESTARTS'] = cfg['pool_restarts']
	if 'autoscaler' in cfg:
		newconf['CELERYD_AUTOSCALER'] = cfg['autoscaler']
	if 'autoreloader' in cfg:
		newconf['CELERYD_AUTORELOADER'] = cfg['autoreloader']
	if 'consumer' in cfg:
		newconf['CELERYD_CONSUMER'] = cfg['consumer']
	if 'timer' in cfg:
		newconf['CELERYD_TIMER'] = cfg['timer']

	if 'celerymon_log_format' in cfg:
		newconf['CELERYMON_LOG_FORMAT'] = cfg['celerymon_log_format']

	if 'broadcast_queue' in cfg:
		newconf['CELERY_BROADCAST_QUEUE'] = cfg['broadcast_queue']
	if 'broadcast_exchange' in cfg:
		newconf['CELERY_BROADCAST_EXCHANGE'] = cfg['broadcast_exchange']
	if 'broadcast_exchange_type' in cfg:
		newconf['CELERY_BROADCAST_EXCHANGE_TYPE'] = cfg['broadcast_exchange_type']

	if 'scheduler' in cfg:
		newconf['CELERYBEAT_SCHEDULER'] = cfg['scheduler']
	if 'schedule_filename' in cfg:
		newconf['CELERYBEAT_SCHEDULE_FILENAME'] = cfg['schedule_filename']
	if 'sync_every' in cfg:
		newconf['CELERYBEAT_SYNC_EVERY'] = cfg['sync_every']
	if 'max_loop_interval' in cfg:
		newconf['CELERYBEAT_MAX_LOOP_INTERVAL'] = cfg['max_loop_interval']

	# FIXME: complex python values!
	opts = make_config_dict(cfg, 'schedule.')
	if len(opts) > 0:
		newconf['CELERYBEAT_SCHEDULE'] = as_dict(opts)

	if 'redis_max_connections' in cfg:
		newconf['CELERY_REDIS_MAX_CONNECTIONS'] = cfg['redis_max_connections']

	opts = make_config_dict(cfg, 'broker.transport_options.')
	if len(opts) > 0:
		newconf['BROKER_TRANSPORT_OPTIONS'] = opts

	opts = make_config_dict(cfg, 'task_publish_retry_policy.')
	if len(opts) > 0:
		newconf['CELERY_TASK_PUBLISH_RETRY_POLICY'] = opts

	opts = make_config_dict(cfg, 'result_tables.')
	if len(opts) > 0:
		newconf['CELERY_RESULT_DB_TABLENAMES'] = opts

	opts = make_config_dict(cfg, 'result_options.')
	if len(opts) > 0:
		newconf['CELERY_RESULT_ENGINE_OPTIONS'] = opts

	opts = make_config_dict(cfg, 'cache_options.')
	if len(opts) > 0:
		newconf['CELERY_CACHE_BACKEND_OPTIONS'] = opts

	opts = make_config_dict(cfg, 'mongodb_options.')
	if len(opts) > 0:
		newconf['CELERY_MONGODB_BACKEND_SETTINGS'] = opts

	cass = make_config_dict(cfg, 'cassandra.')
	if 'servers' in cass:
		newconf['CASSANDRA_SERVERS'] = aslist(cass['servers'])
	if 'keyspace' in cass:
		newconf['CASSANDRA_KEYSPACE'] = cass['keyspace']
	if 'column_family' in cass:
		newconf['CASSANDRA_COLUMN_FAMILY'] = cass['column_family']
	if 'read_consistency' in cass:
		newconf['CASSANDRA_READ_CONSISTENCY'] = cass['read_consistency']
	if 'write_consistency' in cass:
		newconf['CASSANDRA_WRITE_CONSISTENCY'] = cass['write_consistency']
	if 'detailed_mode' in cass:
		newconf['CASSANDRA_DETAILED_MODE'] = cass['detailed_mode']
	opts = make_config_dict(cass, 'options.')
	if len(opts) > 0:
		newconf['CASSANDRA_OPTIONS'] = opts

	opts = make_config_dict(cfg, 'queues.')
	if len(opts) > 0:
		newconf['CELERY_QUEUES'] = opts
	else:
		newconf['CELERY_QUEUES'] = _default_queues

	mm = reg.getUtility(IModuleManager)

	opts = []
	if 'imports' in cfg:
		opts = aslist(cfg['imports'])
	for imp in mm.get_task_imports():
		opts.append(imp)
	if len(opts) > 0:
		newconf['CELERY_IMPORTS'] = opts

	opts = []
	if 'include' in cfg:
		opts = aslist(cfg['include'])
	# FIXME: hook module include here (?)
	if len(opts) > 0:
		newconf['CELERY_INCLUDE'] = opts

	if len(newconf) > 0:
		if isinstance(celery, Celery):
			celery.config_from_object(newconf)
		else:
			celery.update(newconf)
예제 #19
-1
파일: __init__.py 프로젝트: unikmhz/npui
def _register_fonts(settings):
    global DEFAULT_FONT

    first_fname = None
    default_fontdir = settings.get('netprofile.fonts.directory', '')
    default_family = settings.get('netprofile.fonts.default_family', 'tinos')
    fontcfg = make_config_dict(settings, 'netprofile.fonts.family.')
    fontcfg = as_dict(fontcfg)
    for fname, cfg in fontcfg.items():
        if 'normal' not in cfg:
            continue
        fname = cfg.get('name', fname)
        if first_fname is None:
            first_fname = fname
        fontdir = cfg.get('directory', default_fontdir)
        pdfmetrics.registerFont(ttfonts.TTFont(
            fname,
            os.path.join(fontdir, cfg['normal'])))
        reg = {'normal': fname}

        if 'bold' in cfg:
            reg['bold'] = fname + '_b'
            pdfmetrics.registerFont(ttfonts.TTFont(
                reg['bold'],
                os.path.join(fontdir, cfg['bold'])))
        else:
            reg['bold'] = fname

        if 'italic' in cfg:
            reg['italic'] = fname + '_i'
            pdfmetrics.registerFont(ttfonts.TTFont(
                reg['italic'],
                os.path.join(fontdir, cfg['italic'])))
        else:
            reg['italic'] = fname

        if 'bold_italic' in cfg:
            reg['boldItalic'] = fname + '_bi'
            pdfmetrics.registerFont(ttfonts.TTFont(
                reg['boldItalic'],
                os.path.join(fontdir, cfg['bold_italic'])))
        else:
            reg['boldItalic'] = fname

        pdfmetrics.registerFontFamily(fname, **reg)

    DEFAULT_FONT = 'Times-Roman'
    if default_family in fontcfg:
        DEFAULT_FONT = fontcfg[default_family].get('name', default_family)
    elif first_fname:
        DEFAULT_FONT = first_fname
    return DEFAULT_FONT