print helpful warning if unix env is inhospitable

thx kipu you're the best
This commit is contained in:
ed 2024-05-11 18:34:41 +00:00
parent 566cbb6507
commit b629d18df6

View file

@ -173,8 +173,10 @@ def init_E(EE: EnvParams) -> None:
(os.environ.get, "TMP"), (os.environ.get, "TMP"),
(unicode, "/tmp"), (unicode, "/tmp"),
] ]
errs = []
for chk in [os.listdir, os.mkdir]: for chk in [os.listdir, os.mkdir]:
for pf, pa in paths: for npath, (pf, pa) in enumerate(paths):
p = ""
try: try:
p = pf(pa) p = pf(pa)
# print(chk.__name__, p, pa) # print(chk.__name__, p, pa)
@ -187,9 +189,20 @@ def init_E(EE: EnvParams) -> None:
if not os.path.isdir(p): if not os.path.isdir(p):
os.mkdir(p) os.mkdir(p)
if npath > 1:
t = "Using [%s] for config; filekeys/dirkeys will change on every restart. Consider setting XDG_CONFIG_HOME or giving the unix-user a ~/.config/"
errs.append(t % (p,))
elif errs:
errs.append("Using [%s] instead" % (p,))
if errs:
print("WARNING: " + ". ".join(errs))
return p # type: ignore return p # type: ignore
except: except Exception as ex:
pass if p and npath < 2:
t = "Unable to store config in [%s] due to %r"
errs.append(t % (p, ex))
raise Exception("could not find a writable path for config") raise Exception("could not find a writable path for config")