aboutsummaryrefslogtreecommitdiff
path: root/wqflask/utility/tools.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2023-06-15 14:40:37 +0300
committerFrederick Muriuki Muriithi2023-06-20 13:36:50 +0300
commitaa4d213692cb27a903fe1593e2dd3387e638b350 (patch)
treef41cfdf7e369cae767af5534cfc02c9998b9e4a2 /wqflask/utility/tools.py
parenta56d857dc1f6dbc25819a4af116139a2f3e14a68 (diff)
downloadgenenetwork2-aa4d213692cb27a903fe1593e2dd3387e638b350.tar.gz
Configs: Introduce Blueprints. Refactor configs in webqtlConfig.
* Introduce flask Blueprints to help with decoupling the various modules from the `wqflask/__init__.py` module * Refactor settings: Create a function `base.webqtlConfig.init_app(...)` to handle setting up the configurations on the app correctly. Call this function at app creation time. * Move configuration utility functions from `utility.tools` module to `utility.configuration` module. * Use the `get_setting(...)` function to retrieve configuration settings from the application.
Diffstat (limited to 'wqflask/utility/tools.py')
-rw-r--r--wqflask/utility/tools.py93
1 files changed, 10 insertions, 83 deletions
diff --git a/wqflask/utility/tools.py b/wqflask/utility/tools.py
index 5b3e9413..894bef76 100644
--- a/wqflask/utility/tools.py
+++ b/wqflask/utility/tools.py
@@ -7,6 +7,16 @@ import json
from wqflask import app
+from .configuration import (
+ mk_dir,
+ valid_bin,
+ valid_file,
+ valid_path,
+ assert_bin,
+ assert_dir,
+ assert_file,
+ assert_writable_dir)
+
# Use the standard logger here to avoid a circular dependency
import logging
logger = logging.getLogger(__name__)
@@ -86,24 +96,6 @@ def get_setting_int(id):
return v
-def valid_bin(bin):
- if os.path.islink(bin) or valid_file(bin):
- return bin
- return None
-
-
-def valid_file(fn):
- if os.path.isfile(fn):
- return fn
- return None
-
-
-def valid_path(dir):
- if os.path.isdir(dir):
- return dir
- return None
-
-
def js_path(module=None):
"""
Find the JS module in the two paths
@@ -146,42 +138,6 @@ def flat_files(subdir=None):
return assert_dir(base)
-def assert_bin(fn):
- if not valid_bin(fn):
- raise Exception("ERROR: can not find binary " + fn)
- return fn
-
-
-def assert_dir(the_dir):
- if not valid_path(the_dir):
- raise FileNotFoundError(f"ERROR: can not find directory '{the_dir}'")
- return the_dir
-
-
-def assert_writable_dir(dir):
- try:
- fn = dir + "/test.txt"
- fh = open(fn, 'w')
- fh.write("I am writing this text to the file\n")
- fh.close()
- os.remove(fn)
- except IOError:
- raise Exception('Unable to write test.txt to directory ' + dir)
- return dir
-
-
-def assert_file(fn):
- if not valid_file(fn):
- raise FileNotFoundError(f"Unable to find file '{fn}'")
- return fn
-
-
-def mk_dir(dir):
- if not valid_path(dir):
- os.makedirs(dir)
- return assert_dir(dir)
-
-
def locate(name, subdir=None):
"""
Locate a static flat file in the GENENETWORK_FILES environment.
@@ -230,35 +186,6 @@ def tempdir():
return valid_path(get_setting("TMPDIR", "/tmp"))
-BLUE = '\033[94m'
-GREEN = '\033[92m'
-BOLD = '\033[1m'
-ENDC = '\033[0m'
-
-
-def show_settings():
- from utility.tools import LOG_LEVEL
-
- print(("Set global log level to " + BLUE + LOG_LEVEL + ENDC),
- file=sys.stderr)
- log_level = getattr(logging, LOG_LEVEL.upper())
- logging.basicConfig(level=log_level)
-
- logger.info(OVERRIDES)
- logger.info(BLUE + "Mr. Mojo Risin 2" + ENDC)
- keylist = list(app.config.keys())
- print("runserver.py: ****** Webserver configuration - k,v pairs from app.config ******",
- file=sys.stderr)
- keylist.sort()
- for k in keylist:
- try:
- print(("%s: %s%s%s%s" % (k, BLUE, BOLD, get_setting(k), ENDC)),
- file=sys.stderr)
- except:
- print(("%s: %s%s%s%s" % (k, GREEN, BOLD, app.config[k], ENDC)),
- file=sys.stderr)
-
-
# Cached values
GN_VERSION = get_setting('GN_VERSION')
HOME = get_setting('HOME')