How to use the psycopg.OperationalError function in psycopg

To help you get started, we’ve selected a few psycopg examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github odoo / odoo / bin / tinyerp-server.py View on Github external
dispatcher = netsvc.Dispatcher()
dispatcher.monitor(signal.SIGINT)

#---------------------------------------------------------------
# connect to the database and initialize it with base if needed
#---------------------------------------------------------------
logger.notifyChannel("init", netsvc.LOG_INFO, 'connecting to database')

import psycopg
import pooler

# try to connect to the database
try:
#	pooler.init()
	pass
except psycopg.OperationalError, err:
	logger.notifyChannel("init", netsvc.LOG_ERROR, "could not connect to database '%s'!" % (tools.config["db_name"],))

	msg = str(err).replace("FATAL:","").strip()
	db_msg = "database \"%s\" does not exist" % (tools.config["db_name"],)
	
	# Note: this is ugly but since psycopg only uses one exception for all errors
	# I don't think it's possible to do differently
	if msg == db_msg:
		print """
    this database does not exist

You need to create it using the command:

    createdb --encoding=UNICODE '%s'

When you run tinyerp-server for the first time it will initialise the