summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: b388b51)
raw | patch | inline | side by side (parent: b388b51)
author | aurium <aurium@users.sourceforge.net> | |
Mon, 13 Apr 2009 19:57:44 +0000 (19:57 +0000) | ||
committer | aurium <aurium@users.sourceforge.net> | |
Mon, 13 Apr 2009 19:57:44 +0000 (19:57 +0000) |
share/extensions/svg_and_media_zip_output.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 cc8f7db0e1f8f14f72554a4586310474de2e1942..65c230672d9fe9f9983d34b0ce9657a08b60307c 100644 (file)
ttmp_orig = self.document.getroot()
docname = ttmp_orig.get(inkex.addNS('docname',u'sodipodi'))
+ if docname is None: docname = self.args[-1]
- orig_tmpfile = sys.argv[1]
+ #orig_tmpfile = sys.argv[1]
#create os temp dir
tmp_dir = tempfile.mkdtemp()
-
+
# create destination zip in same directory as the document
- z = zipfile.ZipFile(tmp_dir + os.path.sep + docname + '.zip', 'w')
+ z = zipfile.ZipFile(tmp_dir + os.path.sep + docname + '.zip', '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)
##copy tmpdoc to tempdir
dst_file = os.path.join(tmp_dir, docstripped)
stream = open(dst_file,'w')
-
+
self.document.write(stream)
-
+
stream.close()
-
+
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):
xlink = node.get(inkex.addNS('href',u'xlink'))
if (xlink[:4]!='data'):
- absref=node.get(inkex.addNS('absref',u'sodipodi'))
+ 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)
z.write(absref.encode("latin-1"),os.path.basename(absref).encode("latin-1"))
node.set(inkex.addNS('href',u'xlink'),os.path.basename(absref))
node.set(inkex.addNS('absref',u'sodipodi'),os.path.basename(absref))
-
-if __name__ == '__main__':
+
+if __name__ == '__main__': #pragma: no cover
e = MyEffect()
e.affect()