nophead / Mendel90

A RepRap Mendel variant using sheets for the frame instead of rods
http://hydraraptor.blogspot.com/2011/12/mendel90.html
262 stars 247 forks source link

Inkscape CLI with Ubuntu 12.04 LTS #24

Closed createthis closed 11 years ago

createthis commented 11 years ago

Hey, I noticed that inkscape was opening the GUI and not doing PDF conversions, so I did some digging. I'm running Inkscape 0.48.3.1 r9886 (Mar 29 2012) and Python 2.7.3.

Apparently adding the -z option tells inkscape to not open a GUI, so I added that. But the big thing I noticed was that Python was ignoring the CLI arguments altogether. I tested this by running the CLI string:

inkscape -f mendel/sheets/frame_base.svg -A mendel/sheets/frame_base.pdf -z

.. manually on the command line. That would work fine, but when Python executed the same thing, the GUI would open and nothing would happen.

This behavior was caused by the shell = True argument to Popen. The documentation states:

The shell argument (which defaults to False) specifies whether to use the shell as the program to execute. If shell is True, it is recommended to pass args as a string rather than as a sequence.

Changing it to shell = False made inkscape work as expected.

Here is my diff:

diff --git a/InkCL.py b/InkCL.py
index 4db94da..a1042dd 100644
--- a/InkCL.py
+++ b/InkCL.py
@@ -8,7 +8,7 @@ def run(*args):
     for arg in args:
         print arg,
     print
-    run = subprocess.Popen(["inkscape"] + list(args), shell = True, stdout = subprocess.PIPE, stderr = subprocess.
+    run = subprocess.Popen(["inkscape"] + list(args) + list(' -z'), shell = False, stdout = subprocess.PIPE, stder
     out,err=[e.splitlines() for e in run.communicate()]
     return run.returncode, out, err
'''

Hopefully that's useful to someone.
fschulze commented 11 years ago

It should be + ['-z'], the current + list(' -z') actually appends [' ', '-', 'z'] to the argument list.

nophead commented 11 years ago

That is what it is currently. I didn't take the patch literally.