mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 09:22:31 -06:00
create ~/.config if /tmp is readonly
This commit is contained in:
parent
b8945ae233
commit
ece08b8179
|
@ -25,26 +25,30 @@ ANYWIN = WINDOWS or sys.platform in ["msys"]
|
||||||
MACOS = platform.system() == "Darwin"
|
MACOS = platform.system() == "Darwin"
|
||||||
|
|
||||||
|
|
||||||
def get_unix_home():
|
def get_unixdir():
|
||||||
|
paths = [
|
||||||
|
(os.environ.get, "XDG_CONFIG_HOME"),
|
||||||
|
(os.path.expanduser, "~/.config"),
|
||||||
|
(unicode, "/tmp"),
|
||||||
|
]
|
||||||
|
for chk in [os.listdir, os.mkdir]:
|
||||||
|
for pf, pa in paths:
|
||||||
try:
|
try:
|
||||||
v = os.environ["XDG_CONFIG_HOME"]
|
p = pf(pa)
|
||||||
if not v:
|
if not p or p.startswith("~"):
|
||||||
raise Exception()
|
continue
|
||||||
ret = os.path.normpath(v)
|
|
||||||
os.listdir(ret)
|
p = os.path.normpath(p)
|
||||||
return ret
|
chk(p)
|
||||||
|
p = os.path.join(p, "copyparty")
|
||||||
|
if not os.path.isdir(p):
|
||||||
|
os.mkdir(p)
|
||||||
|
|
||||||
|
return p
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
try:
|
raise Exception("could not find a writable path for config")
|
||||||
v = os.path.expanduser("~/.config")
|
|
||||||
if v.startswith("~"):
|
|
||||||
raise Exception()
|
|
||||||
ret = os.path.normpath(v)
|
|
||||||
os.listdir(ret)
|
|
||||||
return ret
|
|
||||||
except:
|
|
||||||
return "/tmp"
|
|
||||||
|
|
||||||
|
|
||||||
class EnvParams(object):
|
class EnvParams(object):
|
||||||
|
@ -59,7 +63,7 @@ class EnvParams(object):
|
||||||
elif sys.platform == "darwin":
|
elif sys.platform == "darwin":
|
||||||
self.cfg = os.path.expanduser("~/Library/Preferences/copyparty")
|
self.cfg = os.path.expanduser("~/Library/Preferences/copyparty")
|
||||||
else:
|
else:
|
||||||
self.cfg = get_unix_home() + "/copyparty"
|
self.cfg = get_unixdir()
|
||||||
|
|
||||||
self.cfg = self.cfg.replace("\\", "/")
|
self.cfg = self.cfg.replace("\\", "/")
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue