示例#1
0
def before_request():
	"""This function is run before the request is handled by Flask. It is used
	to connect to MySQL and Redis, and to tell old Internet Explorer versions
	to go away.
	"""

	# Check for MSIE version <= 10.0
	if (request.user_agent.browser == "msie" and int(round(float(request.user_agent.version))) <= 10):
		return render_template('foad.html')

	# Connect to redis
	try:
		g.redis = redis.StrictRedis(host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], db=0)
		g.redis.get('foo') # it doesnt matter that this key doesnt exist, its just to force a test call to redis.
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the REDIS server')

	# Connect to database
	try:
		g.db = mysql.connect(host=app.config['MYSQL_HOST'], port=app.config['MYSQL_PORT'], user=app.config['MYSQL_USER'], passwd=app.config['MYSQL_PASS'], db=app.config['MYSQL_NAME'], charset="utf8")
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the MariaDB server')

	# This would ideally go in app.py, but it can't as it depends on 
	# cortex.lib.user which it can't import due to a cyclic dependency
	app.jinja_env.globals['does_user_have_permission'] = does_user_have_permission
	app.jinja_env.globals['does_user_have_system_permission'] = does_user_have_system_permission
示例#2
0
def before_request():
	"""This function is run before the request is handled by Flask. It is used
	to connect to MySQL and Redis, and to tell old Internet Explorer versions
	to go away.
	"""

	# Check for MSIE version <= 10.0
	if (request.user_agent.browser == "msie" and int(round(float(request.user_agent.version))) <= 10):
		return render_template('foad.html')

	# Connect to redis
	try:
		g.redis = redis.StrictRedis(host=app.config['REDIS_HOST'], port=app.config['REDIS_PORT'], db=0)
		g.redis.get('foo') # it doesnt matter that this key doesnt exist, its just to force a test call to redis.
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the REDIS server')

	# Connect to database
	try:
		g.db = mysql.connect(host=app.config['MYSQL_HOST'], port=app.config['MYSQL_PORT'], user=app.config['MYSQL_USER'], passwd=app.config['MYSQL_PASS'], db=app.config['MYSQL_NAME'], charset="utf8")
	except Exception as ex:
		logerr()
		return fatalerr(message='Cortex could not connect to the MariaDB server')

	# This would ideally go in app.py, but it can't as it depends on 
	# cortex.lib.user which it can't import due to a cyclic dependency
	app.jinja_env.globals['does_user_have_permission'] = does_user_have_permission
	app.jinja_env.globals['does_user_have_system_permission'] = does_user_have_system_permission
示例#3
0
def error_handler(error):
    """Handles generic exceptions within the application, displaying the
	traceback if the application is running in debug mode."""

    # Record the error in the log
    logerr()

    ## If we're handling a workflow view handler we don't need to show the fatal
    ## error screen, instead we'll use a standard error screen. the fatal error
    ## screen exists in case a flaw occurs which prevents rendering of the
    ## layout - but that can't happen with a workflow.
    if 'workflow' in g:
        if g.workflow:
            app.logger.warn("Workflow error occured")
            return stderr(
                "Workflow error",
                "An error occured in the workflow function - " +
                type(error).__name__ + ": " + str(error))

    # Get the traceback
    if app.debug:
        debug = traceback.format_exc()
    else:
        debug = "Ask your system administrator to consult the error log for this application."

    # Output a fatal error
    return fatalerr(debug=debug)
示例#4
0
文件: core.py 项目: jrdan/cortex
def neocortex_connect():
	"""This function connects to the neocortex job daemon using the Pyro4
	Remote Procedure Call (RPC) library."""

	# Connect, and perform some set up, including setting up a pre-shared
	# message signing key
	proxy = Pyro4.Proxy('PYRO:neocortex@localhost:1888')
	proxy._pyroHmacKey = app.config['NEOCORTEX_KEY']
	proxy._pyroTimeout = 5

	# Ping the server to ensure it's alive
	try:
		proxy.ping()
	except Pyro4.errors.PyroError as ex:
		abort(fatalerr(message="An error occured when connecting to the neocortex task engine: " + str(ex)))

	return proxy
示例#5
0
def neocortex_connect():
	"""This function connects to the neocortex job daemon using the Pyro4
	Remote Procedure Call (RPC) library."""

	# Connect, and perform some set up, including setting up a pre-shared
	# message signing key
	proxy = Pyro4.Proxy('PYRO:neocortex@localhost:1888')
	proxy._pyroHmacKey = app.config['NEOCORTEX_KEY']
	proxy._pyroTimeout = 5

	# Ping the server to ensure it's alive
	try:
		proxy.ping()
	except Pyro4.errors.PyroError as ex:
		abort(fatalerr(message="An error occured when connecting to the neocortex task engine: " + str(ex)))

	return proxy
示例#6
0
def error_handler(error):
	"""Handles generic exceptions within the application, displaying the
	traceback if the application is running in debug mode."""

	# Record the error in the log
	logerr()

	## If we're handling a workflow view handler we don't need to show the fatal
	## error screen, instead we'll use a standard error screen. the fatal error
	## screen exists in case a flaw occurs which prevents rendering of the 
	## layout - but that can't happen with a workflow.
	if 'workflow' in g:
		if g.workflow:
			app.logger.warn("Workflow error occured")
			return stderr("Workflow error","An error occured in the workflow function - " + type(error).__name__ + ": " + str(error))

	# Get the traceback
	if app.debug:
		debug = traceback.format_exc()
	else:
		debug = "Ask your system administrator to consult the error log for this application."

	# Output a fatal error
	return fatalerr(debug=debug)