Skip to content

Commit

Permalink
feat: apply new strategy to determine the home dir path;
Browse files Browse the repository at this point in the history
  • Loading branch information
WenjieDu committed Jan 7, 2024
1 parent 4417737 commit c387ebe
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions tsdb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,29 @@
tsdb_config_path = os.path.join(os.path.dirname(__file__), "config.ini")
config.read(tsdb_config_path)

old_cached_dataset_dir = os.path.join(os.path.expanduser("~"), ".tsdb_cached_datasets")
CACHED_DATASET_DIR = os.path.join(
os.path.expanduser("~"), config.get("path", "data_home")
)
data_home_path = os.path.abspath(config.get("path", "data_home"))
old_cached_dataset_dir = os.path.abspath("~/.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 "
f"tsdb.migrate(old='~/.tsdb_cached_datasets', new={CACHED_DATASET_DIR})"
"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.abspath("~/.tsdb")
CACHED_DATASET_DIR = default_path
logger.warning(
f"‼️ The preset data_home path '{data_home_path}' doesn't exist. "
f"Using the default path '{default_path}'."
)


_DATABASE = {
Expand Down

0 comments on commit c387ebe

Please sign in to comment.