Ensure that DATA_DIR dependent folders/files are automatically created inside the specified DATA_DIR if they are not specified separately in the configuration file.. #5513

pull/5580/head
Yogesh Mahajan 2022-11-28 11:32:50 +05:30 committed by GitHub
parent d636b46460
commit d3d666d773
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 9 deletions

View File

@ -46,11 +46,11 @@ The configuration files are as follows:
Windows,%CommonProgramFiles%\\pgadmin\\config_system.py Windows,%CommonProgramFiles%\\pgadmin\\config_system.py
.. note:: If the SERVER_MODE or DATA_DIR settings are changed in .. note:: If the SERVER_MODE or DATA_DIR settings are changed in
``config_distro.py``, ``config_local.py``, or ``config_system.py`` you ``config_distro.py``, ``config_local.py``, or ``config_system.py``
will most likely need to re-set the LOG_FILE, SQLITE_PATH, SESSION_DB_PATH, LOG_FILE, SQLITE_PATH, SESSION_DB_PATH, STORAGE_DIR, KERBEROS_CCACHE_DIR,
STORAGE_DIR, KERBEROS_CCACHE_DIR, and AZURE_CREDENTIAL_CACHE_DIR values and AZURE_CREDENTIAL_CACHE_DIR values will be set based on DATA_DIR unless
as well as they will have been set based on the default configuration or values are explicitly overridden for any of the variable in any of the
overridden by the runtime. above file.
The default ``config.py`` file is shown below for reference: The default ``config.py`` file is shown below for reference:

View File

@ -86,7 +86,9 @@ In order to configure the Python code, follow these steps:
file locations should be appropriate: file locations should be appropriate:
*NOTE: You must ensure the directories specified are writeable by *NOTE: You must ensure the directories specified are writeable by
the user that the web server processes will be running as, e.g. apache or www-data.* the user that the web server processes will be running as, e.g. apache or www-data.
You may specify DATA_DIR in order to create all required directories and files
under DATA_DIR folder.*
.. code-block:: python .. code-block:: python
@ -94,6 +96,8 @@ In order to configure the Python code, follow these steps:
SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db' SQLITE_PATH = '/var/lib/pgadmin4/pgadmin4.db'
SESSION_DB_PATH = '/var/lib/pgadmin4/sessions' SESSION_DB_PATH = '/var/lib/pgadmin4/sessions'
STORAGE_DIR = '/var/lib/pgadmin4/storage' STORAGE_DIR = '/var/lib/pgadmin4/storage'
AZURE_CREDENTIAL_CACHE_DIR = '/var/lib/pgadmin4/azurecredentialcache'
KERBEROS_CCACHE_DIR = '/var/lib/pgadmin4/kerberoscache'
4. Run the following command to create the configuration database: 4. Run the following command to create the configuration database:

View File

@ -835,16 +835,33 @@ AUTO_DISCOVER_SERVERS = True
########################################################################## ##########################################################################
# Local config settings # Local config settings
########################################################################## ##########################################################################
# User configs loaded from config_local, config_distro etc.
user_config_settings = {}
# Function to Extract settings from config_local, config_distro etc.
def get_variables_from_module(module_name):
module = globals().get(module_name, None)
variables = {}
if module:
variables = {key: value for key, value in module.__dict__.items()
if not (key.startswith('__') or key.startswith('_'))}
return variables
# Load distribution-specific config overrides # Load distribution-specific config overrides
try: try:
from config_distro import * import config_distro
config_distro_settings = get_variables_from_module('config_distro')
user_config_settings.update(config_distro_settings)
except ImportError: except ImportError:
pass pass
# Load local config overrides # Load local config overrides
try: try:
from config_local import * import config_local
config_local_settings = get_variables_from_module('config_local')
user_config_settings.update(config_local_settings)
except ImportError: except ImportError:
pass pass
@ -860,10 +877,29 @@ elif sys.platform.startswith('darwin'):
if os.path.exists(system_config_dir + '/config_system.py'): if os.path.exists(system_config_dir + '/config_system.py'):
try: try:
sys.path.insert(0, system_config_dir) sys.path.insert(0, system_config_dir)
from config_system import * import config_system
config_system_settings = get_variables_from_module('config_system')
user_config_settings.update(config_system_settings)
except ImportError: except ImportError:
pass pass
# Update settings for 'LOG_FILE', 'SQLITE_PATH', 'SESSION_DB_PATH',
# 'AZURE_CREDENTIAL_CACHE_DIR', 'KERBEROS_CCACHE_DIR', 'STORAGE_DIR'
# of DATA_DIR is user defined
data_dir_dependent_settings = ['LOG_FILE', 'SQLITE_PATH', 'SESSION_DB_PATH',
'AZURE_CREDENTIAL_CACHE_DIR',
'KERBEROS_CCACHE_DIR', 'STORAGE_DIR']
if 'DATA_DIR' in user_config_settings:
for setting in data_dir_dependent_settings:
if setting not in user_config_settings:
data_dir = user_config_settings['DATA_DIR']
file_dir_name = os.path.basename(locals().get(setting))
locals().update({setting: os.path.join(data_dir, file_dir_name)})
# Finally update config user configs
locals().update(user_config_settings)
# Override DEFAULT_SERVER value from environment variable. # Override DEFAULT_SERVER value from environment variable.
if 'PGADMIN_CONFIG_DEFAULT_SERVER' in os.environ: if 'PGADMIN_CONFIG_DEFAULT_SERVER' in os.environ:
DEFAULT_SERVER = os.environ['PGADMIN_CONFIG_DEFAULT_SERVER'] DEFAULT_SERVER = os.environ['PGADMIN_CONFIG_DEFAULT_SERVER']