2014-12-16 09:54:29 -06:00
|
|
|
##########################################################################
|
|
|
|
#
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
#
|
2015-02-25 14:25:41 -06:00
|
|
|
# Copyright (C) 2013 - 2015, The pgAdmin Development Team
|
2014-12-16 09:54:29 -06:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
#
|
|
|
|
##########################################################################
|
|
|
|
|
2015-06-29 01:58:41 -05:00
|
|
|
"""This is the main application entry point for pgAdmin 4. If running on
|
2015-01-21 06:00:13 -06:00
|
|
|
a webserver, this will provide the WSGI interface, otherwise, we're going
|
|
|
|
to start a web server."""
|
|
|
|
|
2014-12-16 11:14:48 -06:00
|
|
|
import os, sys
|
2014-12-16 09:54:29 -06:00
|
|
|
|
|
|
|
# We need to include the root directory in sys.path to ensure that we can
|
|
|
|
# find everything we need when running in the standalone runtime.
|
2015-03-10 08:09:11 -05:00
|
|
|
root = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
if sys.path[0] != root:
|
|
|
|
sys.path.insert(0, root)
|
2014-12-16 09:54:29 -06:00
|
|
|
|
2014-12-16 11:14:48 -06:00
|
|
|
import config
|
2014-12-18 11:49:09 -06:00
|
|
|
from pgadmin import create_app
|
2013-10-04 11:12:10 -05:00
|
|
|
|
2015-01-26 09:20:28 -06:00
|
|
|
##########################################################################
|
|
|
|
# Sanity checks
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
# Check for local settings if running in server mode
|
|
|
|
if config.SERVER_MODE == True:
|
|
|
|
local_config = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config_local.py')
|
|
|
|
if not os.path.isfile(local_config):
|
|
|
|
print "The configuration file %s does not exist.\n" % local_config
|
|
|
|
print "Before running this application, ensure that config_local.py has been created"
|
|
|
|
print "and sets values for SECRET_KEY, SECURITY_PASSWORD_SALT and CSRF_SESSION_KEY"
|
|
|
|
print "at bare minimum. See config.py for more information and a complete list of"
|
|
|
|
print "settings. Exiting..."
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# Check if the database exists. If it does not, tell the user and exit.
|
|
|
|
if not os.path.isfile(config.SQLITE_PATH):
|
|
|
|
print "The configuration database %s does not exist.\n" % config.SQLITE_PATH
|
|
|
|
print "Please run 'python %s' to create it.\nExiting..." % os.path.join(os.path.dirname(os.path.realpath(__file__)), 'setup.py')
|
|
|
|
sys.exit(1)
|
|
|
|
|
2014-12-17 09:27:54 -06:00
|
|
|
##########################################################################
|
|
|
|
# Server starup
|
|
|
|
##########################################################################
|
|
|
|
|
2014-12-18 11:49:09 -06:00
|
|
|
# Create the app!
|
|
|
|
app = create_app()
|
|
|
|
|
2015-06-29 01:58:41 -05:00
|
|
|
#if config.DEBUG:
|
|
|
|
# app.debug = True
|
|
|
|
|
2013-10-04 11:12:10 -05:00
|
|
|
# Start the web server. The port number should have already been set by the
|
2015-06-29 01:58:41 -05:00
|
|
|
# runtime if we're running in desktop mode, otherwise we'll just use the
|
2014-12-16 06:53:09 -06:00
|
|
|
# Flask default.
|
|
|
|
if 'PGADMIN_PORT' in globals():
|
2014-12-16 11:14:48 -06:00
|
|
|
app.logger.debug('PGADMIN_PORT set in the runtime environment to %s', PGADMIN_PORT)
|
2014-12-16 06:53:09 -06:00
|
|
|
server_port = PGADMIN_PORT
|
|
|
|
else:
|
2014-12-16 11:14:48 -06:00
|
|
|
app.logger.debug('PGADMIN_PORT is not set in the runtime environment, using default of %s', config.DEFAULT_SERVER_PORT)
|
|
|
|
server_port = config.DEFAULT_SERVER_PORT
|
2014-12-16 06:53:09 -06:00
|
|
|
|
2014-12-18 11:49:09 -06:00
|
|
|
try:
|
2015-02-12 04:28:15 -06:00
|
|
|
app.run(port=server_port)
|
2014-12-18 11:49:09 -06:00
|
|
|
except IOError:
|
|
|
|
app.logger.error("Error starting the app server: %s", sys.exc_info())
|