-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Centralise cache directory management
- Loading branch information
Showing
3 changed files
with
45 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import os | ||
import platform | ||
|
||
CACHE_DIR_NAME = 'riitag-rpc' | ||
|
||
|
||
def get_cache_dir(): | ||
plat = platform.system() | ||
if plat == 'Windows': | ||
path = os.getenv('LOCALAPPDATA') | ||
elif plat == 'Linux': | ||
fallback = os.path.join(os.getenv('HOME'), '.cache') | ||
path = os.getenv('XDG_CACHE_HOME', fallback) | ||
elif plat == 'Darwin': | ||
fallback = os.path.join(os.getenv('HOME'), 'Library/Caches') | ||
path = os.getenv('XDG_CACHE_HOME', fallback) | ||
else: | ||
raise OSError(f'Platform unsupported: {plat}') | ||
|
||
path = os.path.join(path, CACHE_DIR_NAME) | ||
os.makedirs(path, exist_ok=True) | ||
return path | ||
|
||
|
||
def get_cache(filename): | ||
return os.path.join(get_cache_dir(), filename) |
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