Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RACK UI use default config file which can be optionally overridden #965

Merged
merged 4 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ cli/.project
/Turnstile-Example/Turnstile-IngestionPackage/CounterApplicationImplementation/*.o
/Turnstile-Example/turnstile-ingestion-package.zip
rack-ui/cache/
rack-ui/config/config.yml
rack-ui/config/config-override.yml
rack-ui/.project
EntityResolution/.project
EntityResolution/Resolutions/Summary.csv
Expand Down
1 change: 0 additions & 1 deletion rack-box/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ echo "rackui ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/rackui
mkdir /etc/rackui
chown rackui.rackui /etc/rackui
envsubst < rackui.service > /etc/systemd/system/rackui.service
cp config/config.sample.yml config/config.yml
systemctl enable rackui

# Initialize SemTK environment variables
Expand Down
5 changes: 5 additions & 0 deletions rack-ui/config/config-default.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# RACK UI default configuration
# Note: if config/config-override.yml is present, each of its entries will override the corresponding entry below

# text to display as warning banner on load page (if empty string, no banner will appear)
load-warning: ''
3 changes: 0 additions & 3 deletions rack-ui/config/config.sample.yml

This file was deleted.

16 changes: 16 additions & 0 deletions rack-ui/pages/helper.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

""" Helper functions """

import yaml
import tempfile
import traceback
import dash
Expand All @@ -13,6 +14,21 @@

# configuration
SPARQLGRAPH_BASE_URL = "http://localhost:8080"
CONFIG_FILE_DEFAULT = "config/config-default.yml"
CONFIG_FILE_OVERRIDE = "config/config-override.yml"

def get_config(key) -> str:
""" Load default config, override it with custom config if present """
# TODO read config once, store for subsequent use
with open(CONFIG_FILE_DEFAULT) as f:
config_obj = yaml.safe_load(f)
try:
with open(CONFIG_FILE_OVERRIDE) as f:
config_custom = yaml.safe_load(f)
config_obj.update(config_custom) # override
except FileNotFoundError:
pass
return config_obj.get(key)

def get_temp_dir() -> str:
""" Get a temp dir """
Expand Down
4 changes: 1 addition & 3 deletions rack-ui/pages/load.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
""" Content for the "load data" page """

import yaml
import time
import io
import base64
Expand All @@ -21,8 +20,7 @@

# get text for warning banner
def get_warning_banner_str() -> str:
config_obj = yaml.safe_load(open("config/config.yml"))
return config_obj.get('load-warning')
return get_config('load-warning')

# display strings
CLEAR_BEFORE_LOADING_STR = "Clear before loading"
Expand Down