From 96e731b63dfe3eb1cd9b3c2d396be2825b34ed47 Mon Sep 17 00:00:00 2001 From: acspike Date: Sun, 10 Feb 2008 20:33:01 +0000 Subject: [PATCH] Partial fix This extension is currently broken and as it stands will be removed from 0.46 I'm committing this partial fix which updates the syntax for lxml anyway Additional fixes will probably be required because as it stands this script crashes inkscape for me --- share/extensions/svg_and_media_zip_output.py | 61 ++++++++------------ 1 file changed, 23 insertions(+), 38 deletions(-) diff --git a/share/extensions/svg_and_media_zip_output.py b/share/extensions/svg_and_media_zip_output.py index 93bf2ebad..b404caf4d 100644 --- a/share/extensions/svg_and_media_zip_output.py +++ b/share/extensions/svg_and_media_zip_output.py @@ -44,79 +44,64 @@ class MyEffect(inkex.Effect): def __init__(self): inkex.Effect.__init__(self) - self.documentDst=None - - def parseTmp(self,file=None): - """Parse document in specified file or on stdin""" - reader = inkex.xml.dom.ext.reader.Sax2.Reader() - try: - try: - stream = open(file,'r') - except: - stream = open(self.args[-1],'r') - except: - stream = sys.stdin - self.documentDst = reader.fromStream(stream) - stream.close() - def output(self): pass def effect(self): + ttmp_orig = self.document.getroot() - #get needed info from orig document - ctx_orig = inkex.xml.xpath.Context.Context(self.document,processorNss=inkex.NSS) + docbase = ttmp_orig.get(inkex.addNS('docbase',u'sodipodi'),'') + docname = ttmp_orig.get(inkex.addNS('docname',u'sodipodi')) - ttmp_orig = inkex.xml.xpath.Evaluate('/svg',self.document, context=ctx_orig) - - docbase = ttmp_orig[0].attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docbase') - docname = ttmp_orig[0].attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'docname') + inkex.debug((docbase,docname)) orig_tmpfile = sys.argv[1] - # create destination zip in same directory as the document - z = zipfile.ZipFile(docbase.value + '/'+ docname.value + '.zip', 'w') - #create os temp dir tmp_dir = tempfile.mkdtemp() + + # create destination zip in same directory as the document + z = zipfile.ZipFile(tmp_dir + '/'+ docname + '.zip', 'w') #fixme replace whatever extention - docstripped = docname.value.replace('.zip', '') + docstripped = docname.replace('.zip', '') #read tmpdoc and copy all images to temp dir - for node in inkex.xml.xpath.Evaluate('//image',self.document, context=ctx_orig): + for node in self.document.xpath('//image',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') - inkex.xml.dom.ext.Print(self.document,stream) + self.document.write(stream) stream.close() z.write(dst_file.encode("latin-1"),docstripped.encode("latin-1")+'.svg') z.close() - shutil.move(docbase.value + '/'+ docname.value + '.zip',docbase.value + '/'+ docname.value) + out = open(tmp_dir + '/'+ docname + '.zip','r') + sys.stdout.write(out.read()) + out.close() shutil.rmtree(tmp_dir) def collectAndZipImages(self, node, tmp_dir, docname, z): - xlink = node.attributes.getNamedItemNS(inkex.NSS[u'xlink'],'href') + xlink = node.get(inkex.addNS('href',u'xlink')) if (xlink.value[:4]!='data'): - absref=node.attributes.getNamedItemNS(inkex.NSS[u'sodipodi'],'absref') + absref=node.get(inkex.addNS('absref',u'sodipodi')) - if (os.path.isfile(absref.value)): - shutil.copy(absref.value,tmp_dir) - z.write(absref.value.encode("latin-1"),os.path.basename(absref.value).encode("latin-1")) + if (os.path.isfile(absref)): + shutil.copy(absref,tmp_dir) + z.write(absref.encode("latin-1"),os.path.basename(absref).encode("latin-1")) - elif (os.path.isfile(tmp_dir + '/' + absref.value)): - shutil.copy(tmp_dir + '/' + absref.value,tmp_dir) - z.write(tmp_dir + '/' + absref.value.encode("latin-1"),os.path.basename(absref.value).encode("latin-1")) + elif (os.path.isfile(tmp_dir + '/' + absref)): + shutil.copy(tmp_dir + '/' + absref,tmp_dir) + z.write(tmp_dir + '/' + absref.encode("latin-1"),os.path.basename(absref).encode("latin-1")) - xlink.value = os.path.basename(absref.value) - absref.value = os.path.basename(absref.value) + node.set(inkex.addNS('href',u'xlink'),os.path.basename(absref)) + node.set(inkex.addNS('absref',u'sodipodi'),os.path.basename(absref)) e = MyEffect() -- 2.30.2