From 205268d6c5d673c9cfeb51fad7ea194975db1132 Mon Sep 17 00:00:00 2001 From: Ankur Sinha (Ankur Sinha Gmail) Date: Feb 02 2022 11:10:12 +0000 Subject: feat: add patch to log to XDG_DATA_DIR --- diff --git a/0001-feat-use-XDG_DATA_HOME-for-logging-file-on-Linux.patch b/0001-feat-use-XDG_DATA_HOME-for-logging-file-on-Linux.patch new file mode 100644 index 0000000..66ef80a --- /dev/null +++ b/0001-feat-use-XDG_DATA_HOME-for-logging-file-on-Linux.patch @@ -0,0 +1,54 @@ +From 4805d3f2158d94337c11c4e7970795a46bfdbe65 Mon Sep 17 00:00:00 2001 +From: "Ankur Sinha (Ankur Sinha Gmail)" +Date: Mon, 11 Oct 2021 16:34:33 +0100 +Subject: [PATCH] feat: use XDG_DATA_HOME for logging file on Linux + +On system installations, one cannot write to +`/usr/lib/pythonX.Y/site-packages` unless one always runs `pyplane` as +root (which is not suggested). On Linux, the `XDG_DATA_HOME` directory +should be used for user-specific data files, so the logging file is best +placed here. + +As the XDG base directory specification says, if `XDG_DATA_HOME` is not +defined, `$HOME/.local/share` should be used. + +References: +https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html +--- + pyplane/core/Logging.py | 14 +++++++++++++- + 1 file changed, 13 insertions(+), 1 deletion(-) + +diff --git a/pyplane/core/Logging.py b/pyplane/core/Logging.py +index c8a5fc8..8bc2fab 100644 +--- a/pyplane/core/Logging.py ++++ b/pyplane/core/Logging.py +@@ -23,13 +23,25 @@ Module implementing logging capabilities + import time + import os + import sys ++import platform + from PyQt5 import QtCore, QtWidgets, QtGui + + __author__ = 'Klemens Fritzsche' + + basedir = os.path.dirname(os.path.dirname(sys.modules.get(__name__).__file__)) +-defaultLogFileName = os.path.join(basedir, 'config','logmessages.txt') + ++if platform.system() == "Linux": ++ try: ++ datadir = os.environ["XDG_DATA_HOME"] + "/pyplane/" ++ except KeyError: ++ datadir = os.environ["HOME"] + "/.local/share/pyplane/" ++ try: ++ os.makedirs(datadir) ++ except FileExistsError: ++ pass ++ defaultLogFileName = os.path.join(datadir, 'logmessages.txt') ++else: ++ defaultLogFileName = os.path.join(basedir, 'config','logmessages.txt') + + class Logger(object): + """ +-- +2.33.0 + diff --git a/pyplane.spec b/pyplane.spec index 8447114..dd442cd 100644 --- a/pyplane.spec +++ b/pyplane.spec @@ -21,8 +21,13 @@ Source0: %{forgesource} Source1: pyplane.metainfo.xml Source2: pyplane.desktop +# Write logging file to XDG_DATA_HOME instead of /usr/lib/pythonX.Y/site-packages/ +# https://github.com/TUD-RST/pyplane/pull/10 +Patch0: 0001-feat-use-XDG_DATA_HOME-for-logging-file-on-Linux.patch + BuildArch: noarch +BuildRequires: git-core BuildRequires: python3-devel BuildRequires: libappstream-glib BuildRequires: desktop-file-utils @@ -41,7 +46,7 @@ Recommends: texlive-dvipng %description %_description %prep -%forgesetup +%forgeautosetup -S git %generate_buildrequires # the install requirements seem to be required for tests, so include them