Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Visicut calling inkscape in an AppImage. #721

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions tools/inkscape_extension/visicut_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,19 @@ def is_exe(fpath):
def inkscape_version():
"""Return Inkscape version number as float, e.g. version "0.92.4" --> return: float 0.92"""
version = subprocess.check_output([INKSCAPEBIN, "--version"], stderr=DEVNULL).decode('ASCII', 'ignore')
if not version.startswith("Inkscape "):
jnweiger marked this conversation as resolved.
Show resolved Hide resolved
## When inkscape lives in an appimage, AppRun may pollute stdout with extra information.
# Go through all the lines, and find the one that starts with Inkscape
lines = version.splitlines()
for version in lines:
if version.startswith("Inkscape "):
break
assert version.startswith("Inkscape ")
match = re.match("Inkscape ([0-9]+\.[0-9]+).*", version)
assert match is not None
version_float = float(match.group(1))
return version_float



# Strip SVG to only contain selected elements, convert objects to paths, unlink clones
Expand All @@ -157,7 +164,7 @@ def inkscape_version():
# The idea is similar to http://bazaar.launchpad.net/~nikitakit/inkscape/svg2sif/view/head:/share/extensions/synfig_prepare.py#L181 , but more primitive - there is no need for more complicated preprocessing here
def stripSVG_inkscape(src, dest, elements):
version = inkscape_version()

# create temporary file for opening with inkscape.
# delete this file later so that it will disappear from the "recently opened" list.
tmpfile = tempfile.NamedTemporaryFile(delete=False, prefix='temp-visicut-', suffix='.svg')
Expand Down Expand Up @@ -199,8 +206,8 @@ def stripSVG_inkscape(src, dest, elements):
verbs += ["UnhideAllInAllLayers", "EditInvertInAllLayers", "EditDelete", "EditSelectAllInAllLayers", "EditUnlinkClone", "ObjectToPath", "FileSave"]
# --verb=action1;action2;...
command += ["--verb=" + ";".join(verbs)]


DEBUG = False
if DEBUG:
# Inkscape sometimes silently ignores wrong verbs, so we need to double-check that everything's right
Expand Down Expand Up @@ -248,7 +255,7 @@ def stripSVG_inkscape(src, dest, elements):
actions += ["export-area-page"]

command = [INKSCAPEBIN, tmpfile, "--export-overwrite", "--actions=" + ";".join(actions)]

try:
#sys.stderr.write(" ".join(command))
# run inkscape, buffer output
Expand Down Expand Up @@ -326,6 +333,17 @@ def get_original_filename(filename):
VISICUTBIN = which("VisiCut.Linux", [VISICUTDIR, "/usr/share/visicut"])
INKSCAPEBIN = which("inkscape", [INKSCAPEDIR])

## Test if this inkscape is in an appimage.
# 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 != '/':
jnweiger marked this conversation as resolved.
Show resolved Hide resolved
apprun_path = os.path.join(dir, "AppRun")
if os.path.exists(apprun_path):
INKSCAPEBIN = apprun_path
break
dir = os.path.dirname(dir)
tmpdir = tempfile.mkdtemp(prefix='temp-visicut-')
dest_filename = os.path.join(tmpdir, get_original_filename(filename))

Expand Down Expand Up @@ -384,3 +402,4 @@ def get_original_filename(filename):
sys.exit(1)

# TODO (complicated, probably WONTFIX): cleanup temporary directories -- this is really difficult because we need to make sure that visicut no longer needs the file, even for reloading!
# - maybe add the PID od the running visicut, then we can detect orphaned temp direcories.
jnweiger marked this conversation as resolved.
Show resolved Hide resolved
Loading