core: add tmp_dir for global access to a tmp dir

This commit is contained in:
Sean Breckenridge 2021-05-16 15:23:52 -07:00
parent b64a11cc69
commit d7476dc4c5

View file

@ -42,6 +42,14 @@ class Config(user_config):
NOTE: you shouldn't use this attribute in HPI modules directly, use Config.get_cache_dir()/cachew.cache_dir() instead
'''
tmp_dir: Optional[PathIsh] = None
'''
Path to a temporary directory.
This can be used temporarily while extracting zipfiles etc...
- if None , uses default determined by tempfile.gettempdir + 'HPI'
- otherwise , use the specified directory as the base temporary directory
'''
enabled_modules : Optional[Sequence[str]] = None
'''
list of regexes/globs
@ -62,7 +70,21 @@ class Config(user_config):
from .cachew import _appdirs_cache_dir
return _appdirs_cache_dir()
else:
return Path(cdir)
return Path(cdir).expanduser()
def get_tmp_dir(self) -> Path:
tdir: Optional[PathIsh] = self.tmp_dir
tpath: Path
# use tempfile if unset
if tdir is None:
import tempfile
tpath = Path(tempfile.gettempdir()) / 'HPI'
else:
tpath = Path(tdir)
tpath = tpath.expanduser()
if not tpath.exists():
tpath.mkdir(parents=True)
return tpath
def _is_module_active(self, module: str) -> Optional[bool]:
# None means the config doesn't specify anything