Anyone? On Thu, Jul 20, 2017 at 5:03 PM, Dave Page <dp...@pgadmin.org> wrote:
> All, > > Attached is a patch that aims to allow us to have a standardised config > that will work out of the box for both web and desktop modes. It does this > by doing two things: > > 1) The runtime sets SERVER_MODE in the Python environment before starting > the app. If this value is set, then it overrides the default value of > SERVER_MODE in the config. > > 2) The config file then offers default values for the various file > locations for both server and desktop mode, setting them appropriately > based on the derived SERVER_MODE value. > > The only downsides I can see from this are: > > - You cannot run in server mode in the runtime without manually > reconfiguring SERVER_MODE and likely a bunch of paths in config_local.py > > - If you want to override SERVER_MODE, you'll probably also need to > redefine the various paths in config_local.py. > > I don't see either being something 99.9% of users would need though. > > Can anyone see if the patch breaks anything, or if I missed any side > effects? > > Is it likely to break things during upgrades? I suspect so... so maybe > this should prompt v2.0? > > I'd appreciate multiple reviews of this, as it could break things. Note > that I haven't yet updated the docs. > > -- > Dave Page > Blog: http://pgsnake.blogspot.com > Twitter: @pgsnake > > EnterpriseDB UK: http://www.enterprisedb.com > The Enterprise PostgreSQL Company > -- Dave Page Blog: http://pgsnake.blogspot.com Twitter: @pgsnake EnterpriseDB UK: http://www.enterprisedb.com The Enterprise PostgreSQL Company
diff --git a/runtime/Server.cpp b/runtime/Server.cpp index 40fc414c..8fd2cadb 100644 --- a/runtime/Server.cpp +++ b/runtime/Server.cpp @@ -272,9 +272,10 @@ void Server::run() return; } - // Set the port number + // Set the port number and key, and force SERVER_MODE off. PyRun_SimpleString(QString("PGADMIN_PORT = %1").arg(m_port).toLatin1()); PyRun_SimpleString(QString("PGADMIN_KEY = '%1'").arg(m_key).toLatin1()); + PyRun_SimpleString(QString("SERVER_MODE = False").toLatin1()); // Run the app! QByteArray m_appfile_utf8 = m_appfile.toUtf8(); diff --git a/web/config.py b/web/config.py index f4609e4e..32df08d5 100644 --- a/web/config.py +++ b/web/config.py @@ -11,9 +11,15 @@ # ########################################################################## +import logging import os import sys +if sys.version_info[0] >= 3: + import builtins +else: + import __builtin__ as builtins + # 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. @@ -93,46 +99,6 @@ MODULE_BLACKLIST = ['test'] NODE_BLACKLIST = [] -# Data directory for storage of config settings etc. This shouldn't normally -# need to be changed - it's here as various other settings depend on it. -if IS_WIN: - # Use the short path on windows - DATA_DIR = os.path.realpath( - os.path.join(fs_short_path(env('APPDATA')), u"pgAdmin") - ) -else: - DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) - - -########################################################################## -# Log settings -########################################################################## - -# Debug mode? -DEBUG = False - - -import logging - -# Application log level - one of: -# CRITICAL 50 -# ERROR 40 -# WARNING 30 -# SQL 25 -# INFO 20 -# DEBUG 10 -# NOTSET 0 -CONSOLE_LOG_LEVEL = logging.WARNING -FILE_LOG_LEVEL = logging.WARNING - -# Log format. -CONSOLE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' -FILE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' - -# Log file name -LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') - - ########################################################################## # Server settings ########################################################################## @@ -142,7 +108,19 @@ LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') # default login. # # DO NOT DISABLE SERVER MODE IF RUNNING ON A WEBSERVER!! -SERVER_MODE = True +# +# We only set SERVER_MODE if it's not already set. That's to allow the +# runtime to force it to False. +# +# NOTE: If you change the value of SERVER_MODE in an included config file, +# you may also need to redefine any values below that are derived +# from it, notably various paths such as LOG_FILE and anything +# using DATA_DIR. + +if builtins.SERVER_MODE is None: + SERVER_MODE = True +else: + SERVER_MODE = builtins.SERVER_MODE # User ID (email address) to use for the default user in desktop mode. # The default should be fine here, as it's not exposed in the app. @@ -177,6 +155,52 @@ SECURITY_PASSWORD_HASH = 'pbkdf2_sha512' # has no effect on <= Python 2.7. MINIFY_PAGE = True +# Data directory for storage of config settings etc. This shouldn't normally +# need to be changed - it's here as various other settings depend on it. +# On Windows, we always store data in %APPDATA%\pgAdmin. On other platforms, +# if we're in server mode we use /var/lib/pgadmin, otherwise ~/.pgadmin +if IS_WIN: + # Use the short path on windows + DATA_DIR = os.path.realpath( + os.path.join(fs_short_path(env('APPDATA')), u"pgAdmin") + ) +else: + if SERVER_MODE: + DATA_DIR = '/var/lib/pgadmin' + else: + DATA_DIR = os.path.realpath(os.path.expanduser(u'~/.pgadmin/')) + + +########################################################################## +# Log settings +########################################################################## + +# Debug mode? +DEBUG = False + +# Application log level - one of: +# CRITICAL 50 +# ERROR 40 +# WARNING 30 +# SQL 25 +# INFO 20 +# DEBUG 10 +# NOTSET 0 +CONSOLE_LOG_LEVEL = logging.WARNING +FILE_LOG_LEVEL = logging.WARNING + +# Log format. +CONSOLE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' +FILE_LOG_FORMAT = '%(asctime)s: %(levelname)s\t%(name)s:\t%(message)s' + +# Log file name. This goes in the data directory, except on non-Windows +# platforms in server mode. +if SERVER_MODE and not IS_WIN: + LOG_FILE = '/var/log/pgadmin/pgadmin4.log' +else: + LOG_FILE = os.path.join(DATA_DIR, 'pgadmin4.log') + + ########################################################################## # Server Connection Driver Settings ########################################################################## diff --git a/web/pgAdmin4.py b/web/pgAdmin4.py index 1db49584..230ce9ff 100644 --- a/web/pgAdmin4.py +++ b/web/pgAdmin4.py @@ -14,12 +14,23 @@ to start a web server.""" import os import sys +if sys.version_info[0] >= 3: + import builtins +else: + import __builtin__ as builtins + # 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. root = os.path.dirname(os.path.realpath(__file__)) if sys.path[0] != root: sys.path.insert(0, root) +# Grab the SERVER_MODE if it's been set by the runtime +if 'SERVER_MODE' in globals(): + builtins.SERVER_MODE = globals()['SERVER_MODE'] +else: + builtins.SERVER_MODE = None + import config from pgadmin import create_app from pgadmin.utils import u, fs_encoding, file_quote