From 978d9f464202fd4ea524879d26182d19258d46eb Mon Sep 17 00:00:00 2001 From: Vasyl Gello Date: Thu, 28 Oct 2021 12:28:26 +0300 Subject: [PATCH] Move configuration files to /etc/xpra The default-settings.txt file is a configuration file editable by user, so its place on Unix systems is in /etc. With this commit, configuration file with names defined in 'configuration_files' dict are not minified or compressed. They are moved to '/etc/xpra' directory if DEB or RPM package is built. Test: 1. Spawn container with Debian: podman run --rm -it -v $PWD:/work:rw \ docker.io/amd64/debian:sid /bin/bash 2. Inside container: export DEBIAN_FRONTEND=noninteractive && \ apt-get update && \ apt-get full-upgrade -yq && \ apt-get install -yq git python3-setuptools && \ cp -a /work /build && find /build -type d -exec chmod 0755 '{}' \; && \ cd /build && \ git checkout '*' && \ git clean -fdx && \ rm -rf /tmp/xpra-html5 && \ rm -rf /etc/xpra /usr/share/xpra/www && \ rm -rf /root/rpmbuild && \ python3 setup.py sdist && \ python3 setup.py install /tmp/xpra-html5 && \ python3 setup.py install && \ python3 setup.py deb && \ echo "Contents of dist tars:" && \ tar tvf dist/*.tar.gz && \ echo "Contents of /tmp/xpra-html5:" && \ ls -la /tmp/xpra-html5 && \ echo "Contents of /etc/xpra/html5-client /usr/share/xpra/www:" && \ ls -la /etc/xpra/html5-client /usr/share/xpra/www && \ echo "Contents of Debian packages:" && \ find dist/ -name "*.deb" -exec dpkg -c '{}' \; && \ echo "OK" || echo "FAIL" Signed-off-by: Vasyl Gello --- setup.py | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/setup.py b/setup.py index 7e19e196..db54f23d 100755 --- a/setup.py +++ b/setup.py @@ -16,6 +16,10 @@ AUTHOR = "Antoine Martin" AUTHOR_EMAIL = "antoine@xpra.org" +# Configuration files that must not be minified or compressed. +# They must be moved to /etc/xpra and symlinked to /usr/share/xpra/www if no +# custom installation directory is set +configuration_files = ["default-settings.txt"] def glob_recurse(srcdir): m = {} @@ -170,7 +174,7 @@ def load_vcs_info(): info[parts[0]] = parts[1] return info -def install_html5(install_dir="www", minifier="uglifyjs", gzip=True, brotli=True): +def install_html5(install_dir="www", minifier="uglifyjs", gzip=True, brotli=True, configuration_files=[]): if minifier not in ("", None, "copy"): print("minifying html5 client to '%s' using %s" % (install_dir, minifier)) else: @@ -310,7 +314,7 @@ def install_html5(install_dir="www", minifier="uglifyjs", gzip=True, brotli=True if fsrc!=src: os.unlink(fsrc) - if ftype not in ("png", ): + if ftype not in ("png", ) and fname not in configuration_files: if gzip: gzip_dst = "%s.gz" % dst if os.path.exists(gzip_dst): @@ -425,7 +429,21 @@ def make_deb(): shutil.rmtree("./xpra-html5") os.mkdir("./xpra-html5") shutil.copytree("./packaging/debian", "./xpra-html5/DEBIAN") - install_html5("./xpra-html5/usr/share/xpra/www/", "uglifyjs") + conf_dir = "/etc/xpra/html5-client" + real_conf_dir = os.path.join("./xpra-html5", conf_dir) + www_dir = "./xpra-html5/usr/share/xpra/www/" + install_html5(www_dir, "uglifyjs", configuration_files=configuration_files) + # Move and symlink configuration files + os.makedirs(real_conf_dir, exist_ok=True) + for filename in configuration_files: + symlink_source = os.path.join(conf_dir, filename) + real_symlink_source = os.path.join(real_conf_dir, filename) + symlink_target = os.path.join(www_dir, filename) + print("Checking existence of %s" % symlink_target) + if os.path.exists(symlink_target): + os.rename(symlink_target, real_symlink_source) + os.symlink(symlink_source, symlink_target) + # Create debian package assert Popen(["dpkg-deb", "-Zxz", "--build", "xpra-html5"]).wait()==0 assert os.path.exists("./xpra-html5.deb") shutil.rmtree("./xpra-html5") @@ -510,12 +528,24 @@ def main(args): except Exception: print("Warning: src_info is missing") minifier = "yuicompressor" if sys.platform.startswith("win") else "uglifyjs" - install_dir = os.path.join(sys.prefix, "share/xpra/www") + conf_dir = os.path.normpath(os.path.join(sys.prefix, "../etc/xpra/html5-client")) + www_dir = os.path.normpath(os.path.join(sys.prefix, "share/xpra/www")) + install_dir = www_dir if len(args)>=3: - install_dir = args[2] + install_dir = os.path.normpath(args[2]) if len(args)>=4: minifier = args[3] - install_html5(install_dir, minifier) + install_html5(install_dir, minifier, configuration_files=configuration_files) + # Move and symlink configuration files if installdir is default + if install_dir==www_dir: + os.makedirs(conf_dir, exist_ok=True) + for filename in configuration_files: + symlink_source = os.path.join(conf_dir, filename) + symlink_target = os.path.join(www_dir, filename) + print("Checking existence of %s" % symlink_target) + if os.path.exists(symlink_target): + os.rename(symlink_target, symlink_source) + os.symlink(symlink_source, symlink_target) return 0 if cmd=="deb": make_deb()