Skip to content

Commit

Permalink
allow skare3_tools config in the HOME directory (#110)
Browse files Browse the repository at this point in the history
add the skare3_tools config in the HOME directory if the other options are not available
  • Loading branch information
javierggt authored Mar 29, 2024
1 parent a0a8338 commit 3a4abdc
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions skare3_tools/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
- specified by the SKARE3_TOOLS_DATA environmental variable,
- or in the directory $SKA/data/skare3/skare3_data
- or:
- Linux/Mac OS: ~/.skare3
- windows: %LOCALAPPDATA%\\skare3
The default looks like this:
Expand Down Expand Up @@ -103,11 +107,25 @@


def _app_data_dir_():
ska_data_dir = os.path.join(os.environ["SKA"], "data", "skare3", "skare3_data")
home_dir = os.path.expanduser("~")
if "SKARE3_TOOLS_DATA" in os.environ:
app_data_dir = os.environ["SKARE3_TOOLS_DATA"]
elif os.path.exists(ska_data_dir):
elif (
"SKA" in os.environ
and (
ska_data_dir := os.path.join(
os.environ["SKA"], "data", "skare3", "skare3_data"
)
)
and os.path.exists(ska_data_dir)
):
app_data_dir = ska_data_dir
elif local_app_data_dir := os.getenv("LOCALAPPDATA"):
# this is the windows location
app_data_dir = os.path.join(local_app_data_dir, "skare3")
elif os.path.exists(home_dir) and os.access(home_dir, os.W_OK):
# can use this in linux and Mac OS
app_data_dir = os.path.join(home_dir, ".skare3")
else:
app_data_dir = None
return app_data_dir
Expand Down

0 comments on commit 3a4abdc

Please sign in to comment.