summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAur??lio A. Heckert <aurium@gmail.com>2009-04-14 21:52:36 +0000
committeraurium <aurium@users.sourceforge.net>2009-04-14 21:52:36 +0000
commit90a498a4c1c73e3a218186da52b48e0d139b3a76 (patch)
tree5573de43b7ab9cf9573f18916a26ee20a920ed37
parenta better set attribute for inkweb (diff)
downloadinkscape-90a498a4c1c73e3a218186da52b48e0d139b3a76.tar.gz
inkscape-90a498a4c1c73e3a218186da52b48e0d139b3a76.zip
more modularized and testable svg_and_media_zip_output extension
(bzr r7714)
-rw-r--r--share/extensions/svg_and_media_zip_output.py38
-rwxr-xr-xshare/extensions/test/svg_and_media_zip_output.test.py5
2 files changed, 24 insertions, 19 deletions
diff --git a/share/extensions/svg_and_media_zip_output.py b/share/extensions/svg_and_media_zip_output.py
index 65c230672..67cabdf22 100644
--- a/share/extensions/svg_and_media_zip_output.py
+++ b/share/extensions/svg_and_media_zip_output.py
@@ -43,12 +43,19 @@ import tempfile
import gettext
_ = gettext.gettext
-class MyEffect(inkex.Effect):
+class SVG_and_Media_ZIP_Output(inkex.Effect):
def __init__(self):
inkex.Effect.__init__(self)
def output(self):
- pass
+ out = open(self.zip_file,'r')
+ sys.stdout.write(out.read())
+ out.close()
+ self.clear_tmp()
+
+ def clear_tmp(self):
+ shutil.rmtree(self.tmp_dir)
+
def effect(self):
ttmp_orig = self.document.getroot()
@@ -59,20 +66,21 @@ class MyEffect(inkex.Effect):
#orig_tmpfile = sys.argv[1]
#create os temp dir
- tmp_dir = tempfile.mkdtemp()
+ self.tmp_dir = tempfile.mkdtemp()
# create destination zip in same directory as the document
- z = zipfile.ZipFile(tmp_dir + os.path.sep + docname + '.zip', 'w')
+ self.zip_file = self.tmp_dir + os.path.sep + docname + '.zip'
+ z = zipfile.ZipFile(self.zip_file, 'w')
#fixme replace whatever extention
docstripped = docname.replace('.zip', '')
#read tmpdoc and copy all images to temp dir
for node in self.document.xpath('//svg:image', namespaces=inkex.NSS):
- self.collectAndZipImages(node, tmp_dir, docname, z)
+ self.collectAndZipImages(node, docname, z)
##copy tmpdoc to tempdir
- dst_file = os.path.join(tmp_dir, docstripped)
+ dst_file = os.path.join(self.tmp_dir, docstripped)
stream = open(dst_file,'w')
self.document.write(stream)
@@ -82,25 +90,21 @@ class MyEffect(inkex.Effect):
z.write(dst_file.encode("latin-1"),docstripped.encode("latin-1")+'.svg')
z.close()
- out = open(tmp_dir + os.path.sep + docname + '.zip','r')
- sys.stdout.write(out.read())
- out.close()
-
- shutil.rmtree(tmp_dir)
- def collectAndZipImages(self, node, tmp_dir, docname, z):
+ def collectAndZipImages(self, node, docname, z):
xlink = node.get(inkex.addNS('href',u'xlink'))
if (xlink[:4]!='data'):
absref = node.get(inkex.addNS('absref',u'sodipodi'))
if absref is None:
absref = node.get(inkex.addNS('href',u'xlink'))
if (os.path.isfile(absref)):
- shutil.copy(absref,tmp_dir)
+ shutil.copy(absref, self.tmp_dir)
z.write(absref.encode("latin-1"),os.path.basename(absref).encode("latin-1"))
- elif (os.path.isfile(tmp_dir + os.path.sep + absref)):
+ elif (os.path.isfile(self.tmp_dir + os.path.sep + absref)):
#TODO: please explain why this clause is necessary
- shutil.copy(tmp_dir + os.path.sep + absref,tmp_dir)
- z.write(tmp_dir + os.path.sep + absref.encode("latin-1"),os.path.basename(absref).encode("latin-1"))
+ shutil.copy(self.tmp_dir + os.path.sep + absref, self.tmp_dir)
+ z.write(self.tmp_dir + os.path.sep + absref.encode("latin-1"),
+ os.path.basename(absref).encode("latin-1"))
else:
inkex.errormsg(_('Could not locate file: %s') % absref)
@@ -109,7 +113,7 @@ class MyEffect(inkex.Effect):
if __name__ == '__main__': #pragma: no cover
- e = MyEffect()
+ e = SVG_and_Media_ZIP_Output()
e.affect()
diff --git a/share/extensions/test/svg_and_media_zip_output.test.py b/share/extensions/test/svg_and_media_zip_output.test.py
index 4e077edd3..42610f0af 100755
--- a/share/extensions/test/svg_and_media_zip_output.test.py
+++ b/share/extensions/test/svg_and_media_zip_output.test.py
@@ -12,15 +12,16 @@ sys.path.append('..') # this line allows to import the extension code
import unittest
from svg_and_media_zip_output import *
-class MyEffectBasicTest(unittest.TestCase):
+class SVG_and_Media_ZIP_Output_BasicTest(unittest.TestCase):
#def setUp(self):
def test_run_without_parameters(self):
args = [ 'minimal-blank.svg' ]
- e = MyEffect()
+ e = SVG_and_Media_ZIP_Output()
e.affect( args, False )
#self.assertEqual( e.something, 'some value', 'A commentary about that.' )
+ e.clear_tmp()
if __name__ == '__main__':
unittest.main()