Skip to content

Commit

Permalink
#1723: follow (mostly) the XDG Base Directory Specification
Browse files Browse the repository at this point in the history
git-svn-id: https://xpra.org/svn/Xpra/trunk@19741 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jun 27, 2018
1 parent 6ca9b2e commit c8f2a23
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/xpra/net/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ def translate_path(self, path):
path = posixpath.normpath(unquote(path))
words = path.split('/')
words = filter(None, words)
path = self.web_root or "/usr/share/xpra/www"
path = self.web_root
for p in [self.web_root]+[os.path.join(x, "xpra", "www") for x in os.environ.get("XDG_DATA_DIRS", "/usr/local/share:/usr/share").split(":")]:
if os.path.exists(p) and os.path.isdir(p):
path = p
break
for word in words:
word = os.path.splitdrive(word)[1]
word = os.path.split(word)[1]
Expand Down
10 changes: 3 additions & 7 deletions src/xpra/platform/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,9 @@ def do_get_install_prefix():
def get_system_conf_dirs():
return envaslist_or_delegate("XPRA_SYSCONF_DIRS", do_get_system_conf_dirs)
def do_get_system_conf_dirs():
prefix = get_install_prefix()
#the system wide configuration directory
if prefix == '/usr':
#default posix config location:
return ['/etc/xpra']
#hope the prefix is something like "/usr/local" or "$HOME/.local":
return [prefix + '/etc/xpra/']
#overriden in all platforms
return []


def get_user_conf_dirs(uid=None):
return envaslist_or_delegate("XPRA_USER_CONF_DIRS", do_get_user_conf_dirs, uid)
Expand Down
15 changes: 8 additions & 7 deletions src/xpra/platform/pycups_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,16 @@ def find_ppd_file(short_name, filename):
if ev and os.path.exists(ev):
log("using environment override for %s ppd file: %s", short_name, ev)
return ev
paths = ["/usr/share/cups/model", #used on Fedora and others
"/usr/share/ppd/cups-pdf", #used on Ubuntu
"/usr/share/ppd/cupsfilters",
"/usr/local/share/cups/model", #install from source with /usr/local prefix
#if your distro uses something else, please file a bug so we can add it
]
paths = []
for p in os.environ.get("XDG_DATA_DIRS", "/usr/local/share:/usr/share").split(":"):
if os.path.exists(p) and os.path.isdir(p):
paths.append(os.path.join(p, "cups", "model")) #used on Fedora and others
paths.append(os.path.join(p, "ppd", "cups-pdf")) #used on Fedora and others
paths.append(os.path.join(p, "ppd", "cupsfilters"))
log("find ppd file: paths=%s", paths)
for p in paths:
f = os.path.join(p, filename)
if os.path.exists(f):
if os.path.exists(f) and os.path.isfile(f):
return f
log("cannot find %s in %s", filename, paths)
return None
Expand Down
50 changes: 37 additions & 13 deletions src/xpra/platform/xposix/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
from xpra.util import envbool
SOUND_PYTHON3 = envbool("XPRA_SOUND_PYTHON3", False)

#removed in 2.3:
# we no longer use "~/.xpra" on posix systems to store files or sockets,
# but we still load config files from there if present
LEGACY_DOTXPRA = envbool("XPRA_LEGACY_DOTXPRA", False)


def do_get_install_prefix():
#special case for "user" installations, ie:
Expand All @@ -30,10 +35,8 @@ def do_get_install_prefix():
def do_get_resources_dir():
#is there a better/cleaner way?
from xpra.platform.paths import get_install_prefix
options = [get_install_prefix(),
sys.exec_prefix,
"/usr",
"/usr/local"]
options = [get_install_prefix(), sys.exec_prefix] + \
os.environ.get("XDG_DATA_DIRS", "/usr/local/share:/usr/share").split(":")
for x in options:
p = os.path.join(x, "share", "xpra")
if os.path.exists(p) and os.path.isdir(p):
Expand Down Expand Up @@ -75,19 +78,39 @@ def do_get_script_bin_dirs():
runtime_dir = _get_xpra_runtime_dir()
if runtime_dir:
script_bin_dirs.append(runtime_dir)
if os.geteuid()>0:
script_bin_dirs.append("~/.xpra")
if LEGACY_DOTXPRA:
if os.geteuid()>0:
script_bin_dirs.append("~/.xpra")
return script_bin_dirs


def do_get_system_conf_dirs():
dirs = ["/etc/xpra", "/usr/local/etc/xpra"]
for d in os.environ.get("XDG_CONFIG_DIRS", "/etc/xdg").split(":"):
dirs.append(os.path.join(d, "xpra"))
#hope the prefix is something like "/usr/local" or "$HOME/.local":
from xpra.platform.paths import get_install_prefix
prefix = get_install_prefix()
if prefix not in ("/usr", "/usr/local"):
if prefix.endswith(".local"):
idir= os.path.join(prefix, "xpra") #ie: ~/.local/xpra
else:
idir= os.path.join(prefix, "/etc/xpra/") #ie: /someinstallpath/etc/xpra
if idir not in dirs:
dirs.append(idir)
return dirs


def do_get_user_conf_dirs(uid):
#per-user configuration location:
#(but never use /root/.xpra)
if uid is None:
uid = os.getuid()
dirs = []
if uid>0:
return ["~/.xpra"]
return []
dirs.append("~/.xpra")
dirs += [os.path.join(os.environ.get("XDG_CONFIG_HOME", "~/.config"), "xpra")]
return dirs


def get_runtime_dir():
Expand Down Expand Up @@ -118,10 +141,11 @@ def do_get_socket_dirs():
if runtime_dir:
#private, per user: /run/user/1000/xpra
SOCKET_DIRS.append(runtime_dir)
#Debian pretends to be root during build.. check FAKEROOTKEY
#to ensure we still include "~/.xpra" in the default config
if os.geteuid()>0 or os.environ.get("FAKEROOTKEY"):
SOCKET_DIRS.append("~/.xpra") #the old default path
if LEGACY_DOTXPRA:
#Debian pretends to be root during build.. check FAKEROOTKEY
#to ensure we still include "~/.xpra" in the default config
if os.geteuid()>0 or os.environ.get("FAKEROOTKEY"):
SOCKET_DIRS.append("~/.xpra") #the old default path
#for shared sockets (the 'xpra' group should own this directory):
if os.path.exists("/run"):
SOCKET_DIRS.append("/run/xpra")
Expand All @@ -134,7 +158,7 @@ def do_get_default_log_dirs():
v = _get_xpra_runtime_dir()
if v:
log_dirs.append(v)
if os.geteuid()>0:
if LEGACY_DOTXPRA and os.geteuid()>0:
log_dirs.append("~/.xpra")
log_dirs.append("/tmp")
return log_dirs
Expand Down

0 comments on commit c8f2a23

Please sign in to comment.