A lot of improvements

This commit is contained in:
Benoît Sierro
2021-06-02 12:01:26 +02:00
parent 9fdf9ed525
commit 49513eff66
12 changed files with 328 additions and 443 deletions

29
src/scgenerator/env.py Normal file
View File

@@ -0,0 +1,29 @@
import os
from pathlib import Path
from typing import Dict, List, Literal, Optional
from .const import ENVIRON_KEY_BASE, PBAR_POLICY, TMP_FOLDER_KEY_BASE
def data_folder(task_id: int) -> Optional[Path]:
idstr = str(int(task_id))
tmp = os.getenv(TMP_FOLDER_KEY_BASE + idstr)
return tmp
def all_environ() -> Dict[str, str]:
"""returns a dictionary of all environment variables set by any instance of scgenerator"""
d = dict(filter(lambda el: el[0].startswith(ENVIRON_KEY_BASE), os.environ.items()))
return d
def pbar_policy() -> List[Literal["print", "file"]]:
policy = os.getenv(PBAR_POLICY)
if policy == "print" or policy is None:
return ["print"]
elif policy == "file":
return ["file"]
elif policy == "both":
return ["file", "print"]
else:
return []