2014-12-16 15:54:29 +00:00
|
|
|
##########################################################################
|
|
|
|
|
#
|
|
|
|
|
# pgAdmin 4 - PostgreSQL Tools
|
|
|
|
|
#
|
2016-01-18 14:48:14 +00:00
|
|
|
# Copyright (C) 2013 - 2016, The pgAdmin Development Team
|
2014-12-16 15:54:29 +00:00
|
|
|
# This software is released under the PostgreSQL Licence
|
|
|
|
|
#
|
|
|
|
|
##########################################################################
|
|
|
|
|
|
2015-06-29 12:28:41 +05:30
|
|
|
"""This is the main application entry point for pgAdmin 4. If running on
|
2015-01-21 12:00:13 +00:00
|
|
|
a webserver, this will provide the WSGI interface, otherwise, we're going
|
|
|
|
|
to start a web server."""
|
|
|
|
|
|
2015-06-30 11:21:55 +05:30
|
|
|
import os
|
|
|
|
|
import sys
|
2014-12-16 15:54:29 +00: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 13:09:11 +00:00
|
|
|
root = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
if sys.path[0] != root:
|
|
|
|
|
sys.path.insert(0, root)
|
2014-12-16 15:54:29 +00:00
|
|
|
|
2014-12-16 17:14:48 +00:00
|
|
|
import config
|
2014-12-18 17:49:09 +00:00
|
|
|
from pgadmin import create_app
|
2013-10-04 17:12:10 +01:00
|
|
|
|
2016-06-24 12:50:52 +01:00
|
|
|
# Get the config database schema version. We store this in pgadmin.model
|
|
|
|
|
# as it turns out that putting it in the config files isn't a great idea
|
|
|
|
|
from pgadmin.model import SCHEMA_VERSION
|
|
|
|
|
config.SETTINGS_SCHEMA_VERSION = SCHEMA_VERSION
|
|
|
|
|
|
2015-01-26 15:20:28 +00:00
|
|
|
##########################################################################
|
|
|
|
|
# Sanity checks
|
|
|
|
|
##########################################################################
|
|
|
|
|
|
|
|
|
|
# Check for local settings if running in server mode
|
2015-06-30 11:21:55 +05:30
|
|
|
if config.SERVER_MODE is True:
|
|
|
|
|
local_config = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
|
|
|
|
'config_local.py')
|
2015-01-26 15:20:28 +00:00
|
|
|
if not os.path.isfile(local_config):
|
2015-11-06 10:23:19 +00:00
|
|
|
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...")
|
2015-01-26 15:20:28 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
2016-05-26 13:00:27 +01:00
|
|
|
# Check if the database exists. If it does not, create it.
|
2015-01-26 15:20:28 +00:00
|
|
|
if not os.path.isfile(config.SQLITE_PATH):
|
2016-05-26 13:00:27 +01:00
|
|
|
setupfile = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
2016-06-14 12:00:06 +01:00
|
|
|
'setup.py')
|
|
|
|
|
exec (open(setupfile).read())
|
2015-01-26 15:20:28 +00:00
|
|
|
|
2014-12-17 15:27:54 +00:00
|
|
|
##########################################################################
|
|
|
|
|
# Server starup
|
|
|
|
|
##########################################################################
|
|
|
|
|
|
2014-12-18 17:49:09 +00:00
|
|
|
# Create the app!
|
|
|
|
|
app = create_app()
|
|
|
|
|
|
2015-06-29 13:41:56 +05:30
|
|
|
if config.DEBUG:
|
|
|
|
|
app.debug = True
|
2015-10-20 12:33:18 +05:30
|
|
|
else:
|
|
|
|
|
app.debug = False
|
2015-06-29 12:28:41 +05:30
|
|
|
|
2013-10-04 17:12:10 +01:00
|
|
|
# Start the web server. The port number should have already been set by the
|
2015-06-29 12:28:41 +05:30
|
|
|
# runtime if we're running in desktop mode, otherwise we'll just use the
|
2014-12-16 12:53:09 +00:00
|
|
|
# Flask default.
|
2016-06-17 10:03:32 +01:00
|
|
|
PGADMIN_RUNTIME = False
|
2014-12-16 12:53:09 +00:00
|
|
|
if 'PGADMIN_PORT' in globals():
|
2016-06-17 10:03:32 +01:00
|
|
|
app.logger.debug('Running under the desktop runtime, port: %s',
|
2015-06-30 11:21:55 +05:30
|
|
|
globals()['PGADMIN_PORT'])
|
|
|
|
|
server_port = int(globals()['PGADMIN_PORT'])
|
2016-06-17 10:03:32 +01:00
|
|
|
PGADMIN_RUNTIME = True
|
2014-12-16 12:53:09 +00:00
|
|
|
else:
|
2015-06-30 11:21:55 +05:30
|
|
|
app.logger.debug(
|
2016-06-17 10:03:32 +01:00
|
|
|
'Not running under the desktop runtime, port: %s',
|
2015-06-30 11:21:55 +05:30
|
|
|
config.DEFAULT_SERVER_PORT)
|
2014-12-16 17:14:48 +00:00
|
|
|
server_port = config.DEFAULT_SERVER_PORT
|
2014-12-16 12:53:09 +00:00
|
|
|
|
2016-06-21 15:12:20 +05:30
|
|
|
# Let the application save the status about the runtime for using it later.
|
|
|
|
|
app.PGADMIN_RUNTIME = PGADMIN_RUNTIME
|
|
|
|
|
|
2016-08-18 13:43:00 +01:00
|
|
|
# Output a startup message if we're not under the runtime and startup.
|
|
|
|
|
# If we're under WSGI, we don't need to worry about this
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
if not PGADMIN_RUNTIME:
|
2016-08-23 12:41:41 +01:00
|
|
|
print("Starting %s. Please navigate to http://%s:%d in your browser." %
|
|
|
|
|
(config.APP_NAME, config.DEFAULT_SERVER, server_port))
|
2016-08-18 13:43:00 +01:00
|
|
|
sys.stdout.flush()
|
2016-06-14 12:00:06 +01:00
|
|
|
|
2016-08-18 13:43:00 +01:00
|
|
|
try:
|
|
|
|
|
app.run(
|
|
|
|
|
host=config.DEFAULT_SERVER,
|
|
|
|
|
port=server_port,
|
|
|
|
|
use_reloader=((not PGADMIN_RUNTIME) and app.debug),
|
|
|
|
|
threaded=config.THREADED_MODE
|
|
|
|
|
)
|
|
|
|
|
except IOError:
|
|
|
|
|
app.logger.error("Error starting the app server: %s", sys.exc_info())
|