From b629d18df651219302cb2a62f8fccc5ff7e01184 Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 11 May 2024 18:34:41 +0000 Subject: [PATCH] print helpful warning if unix env is inhospitable thx kipu you're the best --- copyparty/__main__.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index fc524ece..21cba5bb 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -173,8 +173,10 @@ def init_E(EE: EnvParams) -> None: (os.environ.get, "TMP"), (unicode, "/tmp"), ] + errs = [] for chk in [os.listdir, os.mkdir]: - for pf, pa in paths: + for npath, (pf, pa) in enumerate(paths): + p = "" try: p = pf(pa) # print(chk.__name__, p, pa) @@ -187,9 +189,20 @@ def init_E(EE: EnvParams) -> None: if not os.path.isdir(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 - except: - pass + except Exception as ex: + 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")