diff options
author | Arun Isaac | 2022-09-23 15:04:56 +0530 |
---|---|---|
committer | Arun Isaac | 2022-09-26 13:39:45 +0530 |
commit | fc01a05fe571730dd2cead071717dd5dfaf7a81e (patch) | |
tree | e06b242c0b12e10b371cbe9d73d2cfe9b2ddc72d /wqflask | |
parent | be6ae152a19e91df27dfe3830040e5a7774e4c9f (diff) | |
download | genenetwork2-fc01a05fe571730dd2cead071717dd5dfaf7a81e.tar.gz |
Generalize sql_uri function to get any setting.
* wqflask/wqflask/database.py (sql_uri): Generalize to get_setting.
(database_connection): Call get_setting instead of sql_uri.
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/database.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py index b48f60ad..505f4bd2 100644 --- a/wqflask/wqflask/database.py +++ b/wqflask/wqflask/database.py @@ -23,13 +23,13 @@ def read_from_pyfile(pyfile: str, setting: str) -> Any: return module.__dict__.get(setting) -def sql_uri() -> str: - """Read the SQL_URI from the environment or settings file.""" +def get_setting(setting: str) -> str: + """Read setting from the environment or settings file.""" return os.environ.get( - "SQL_URI", read_from_pyfile( + setting, read_from_pyfile( os.environ.get( "GN2_SETTINGS", os.path.abspath("../etc/default_settings.py")), - "SQL_URI")) + setting)) def parse_db_url(sql_uri: str) -> Tuple: @@ -51,7 +51,7 @@ def database_connection() -> Iterator[Connection]: rolled back. """ - host, user, passwd, db_name, port = parse_db_url(sql_uri()) + host, user, passwd, db_name, port = parse_db_url(get_setting("SQL_URI")) connection = MySQLdb.connect( db=db_name, user=user, passwd=passwd or '', host=host, port=(port or 3306), autocommit=False # Required for roll-backs |