run_command.py revision a34e754dfd715b6f6338a2a4586da47e8fb3580c
import os
import sys
import tempfile
"""
Module for running SVG-generating commands in Inkscape extensions
Copyright (C) 2008 Stephen Silver
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
"""
# Run a command that generates an SVG file from an input file.
# On success, outputs the contents of the SVG file to stdout, and exits
# with a return code of 0.
# On failure, outputs an error message to stderr, and exits with a return
# code of 1.
msg = None
# In order to get a return code from the process, we use subprocess.Popen
# if it's available (Python 2.4 onwards) and otherwise use popen2.Popen3
# (Unix only). As the Inkscape package for Windows includes Python 2.5,
# this should cover all supported platforms.
try:
try:
except ImportError:
try:
p.wait()
except ImportError:
# shouldn't happen...
msg = "Neither subprocess.Popen nor popen2.Popen3 is available"
# If successful, copy the SVG file to stdout.
if msg is None:
import msvcrt
try:
f.close()
# Clean up.
try:
except Exception:
pass
# Ouput error message (if any) and exit.
if msg is not None:
else:
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99