From 4a551e2fb31dc125ce0e9e7298a2642b67a2f29c Mon Sep 17 00:00:00 2001 From: Juergen Weigert Date: Wed, 10 Apr 2024 01:29:29 +0200 Subject: [PATCH] Ported the appimage patch to pathlib. Much nicer code and windows compatible. --- tools/inkscape_extension/visicut_export.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/inkscape_extension/visicut_export.py b/tools/inkscape_extension/visicut_export.py index f414f68c..97de806f 100755 --- a/tools/inkscape_extension/visicut_export.py +++ b/tools/inkscape_extension/visicut_export.py @@ -33,6 +33,7 @@ import random import string import socket +from pathlib import Path try: from os import fsencode @@ -334,13 +335,12 @@ def get_original_filename(filename): # We detect this by checking for an AppRun file, in one of the parent folders of our INKSCAPEBIN. # If so, replace INKSCAPEBIN with AppRun, as this is the only safe way to call inkscape. # (a direct call mixes libraries from the host system with the appimage, may or may not work.) -dir = os.path.dirname(INKSCAPEBIN) -while dir != '/': - apprun_path = os.path.join(dir, "AppRun") - if os.path.exists(apprun_path): - INKSCAPEBIN = apprun_path +for parent in Path(INKSCAPEBIN).parents: + apprun = parent / "AppRun" + if apprun.is_file() and os.access(apprun, os.X_OK): + INKSCAPEBIN = apprun break - dir = os.path.dirname(dir) + tmpdir = tempfile.mkdtemp(prefix='temp-visicut-') dest_filename = os.path.join(tmpdir, get_original_filename(filename))