summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d175a73)
raw | patch | inline | side by side (parent: d175a73)
author | aurium <aurium@users.sourceforge.net> | |
Tue, 14 Apr 2009 21:52:36 +0000 (21:52 +0000) | ||
committer | aurium <aurium@users.sourceforge.net> | |
Tue, 14 Apr 2009 21:52:36 +0000 (21:52 +0000) |
share/extensions/svg_and_media_zip_output.py | patch | blob | history | |
share/extensions/test/svg_and_media_zip_output.test.py | patch | blob | history |
diff --git a/share/extensions/svg_and_media_zip_output.py b/share/extensions/svg_and_media_zip_output.py
index 65c230672d9fe9f9983d34b0ce9657a08b60307c..67cabdf22f00b3c93932334381040ae69efd71b0 100644 (file)
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()
#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)
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)
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 4e077edd315f3462ec0653397e15c61dbb6a7b9a..42610f0af352ff7e26674ce26b4f48016e3037de 100755 (executable)
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()