core: add tmp_dir for global access to a tmp dir (#173)
* core: add tmp_dir for global access to a tmp dir
This commit is contained in:
parent
b64a11cc69
commit
e8be20dcb5
1 changed files with 22 additions and 1 deletions
|
@ -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
|
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
|
enabled_modules : Optional[Sequence[str]] = None
|
||||||
'''
|
'''
|
||||||
list of regexes/globs
|
list of regexes/globs
|
||||||
|
@ -62,7 +70,20 @@ class Config(user_config):
|
||||||
from .cachew import _appdirs_cache_dir
|
from .cachew import _appdirs_cache_dir
|
||||||
return _appdirs_cache_dir()
|
return _appdirs_cache_dir()
|
||||||
else:
|
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()
|
||||||
|
tpath.mkdir(parents=True, exist_ok=True)
|
||||||
|
return tpath
|
||||||
|
|
||||||
def _is_module_active(self, module: str) -> Optional[bool]:
|
def _is_module_active(self, module: str) -> Optional[bool]:
|
||||||
# None means the config doesn't specify anything
|
# None means the config doesn't specify anything
|
||||||
|
|
Loading…
Add table
Reference in a new issue