-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
152 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,43 +5,6 @@ | |
# Created by Wenjie Du <[email protected]> | ||
# License: BSD-3-Clause | ||
|
||
import os | ||
from configparser import ConfigParser | ||
|
||
from .utils.logging import logger | ||
|
||
config = ConfigParser() | ||
tsdb_config_path = os.path.join(os.path.dirname(__file__), "config.ini") | ||
config.read(tsdb_config_path) | ||
|
||
# read from the config file | ||
data_home_path = config.get("path", "data_home") | ||
# replace '~' with the absolute path if existing in the path | ||
data_home_path = data_home_path.replace("~", os.path.expanduser("~")) | ||
old_cached_dataset_dir = os.path.join(os.path.expanduser("~"), ".tsdb_cached_datasets") | ||
|
||
if os.path.exists(old_cached_dataset_dir): | ||
# use the old path and warn the user | ||
logger.warning( | ||
"‼️ Detected the home dir of the old version TSDB. " | ||
"Since v0.3, TSDB has changed the default cache dir to '~/.tsdb'. " | ||
"You can migrate downloaded datasets by invoking the new function " | ||
"tsdb.migrate(old='~/.tsdb_cached_datasets', new='~/.tsdb')" | ||
) | ||
CACHED_DATASET_DIR = old_cached_dataset_dir | ||
elif os.path.exists(data_home_path): | ||
# use the path directly, may be in a portable disk | ||
CACHED_DATASET_DIR = data_home_path | ||
else: | ||
# use the default path | ||
default_path = os.path.join(os.path.expanduser("~"), ".tsdb") | ||
CACHED_DATASET_DIR = default_path | ||
if os.path.abspath(data_home_path) != os.path.abspath(default_path): | ||
logger.warning( | ||
f"‼️ The preset data_home path '{data_home_path}' doesn't exist. " | ||
f"Using the default path '{default_path}'." | ||
) | ||
|
||
|
||
_DATABASE = { | ||
# http://www.physionet.org/challenge/2012 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
Config functions for TSDB. | ||
""" | ||
|
||
# Created by Wenjie Du <[email protected]> | ||
# License: BSD-3-Clause | ||
|
||
import os | ||
from configparser import ConfigParser | ||
|
||
from .logging import logger | ||
|
||
TSDB_BASE_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) | ||
TSDB_CONFIG_FILE = os.path.join(TSDB_BASE_PATH, "config.ini") | ||
|
||
|
||
def read_configs(): | ||
config_parser = ConfigParser() | ||
config_parser.read(TSDB_CONFIG_FILE) | ||
return config_parser | ||
|
||
|
||
def write_configs(config_parser, key_value_set): | ||
for section, key in key_value_set.items(): | ||
value = key_value_set[section][key] | ||
config_parser.set(section, key, value) | ||
|
||
with open(TSDB_CONFIG_FILE, "w") as f: | ||
config_parser.write(f) | ||
|
||
logger.info("Wrote new configs to config.ini successfully.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters