summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d6a1c75)
raw | patch | inline | side by side (parent: d6a1c75)
| author | acspike <acspike@users.sourceforge.net> | |
| Thu, 21 Feb 2008 04:16:31 +0000 (04:16 +0000) | ||
| committer | acspike <acspike@users.sourceforge.net> | |
| Thu, 21 Feb 2008 04:16:31 +0000 (04:16 +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 b404caf4df71d265b302e618eacde90a488f1555..ccb1363c96b524431625d27fceee47d5bb661bca 100644 (file)
creates a zip archive containing all images and the document
Copyright (C) 2005 Pim Snel, pim@lingewoud.com
+Copyright (C) 2008 Aaron Spike, aaron@ekips.org
this is the first Python script ever created
its based on embedimage.py
docbase = ttmp_orig.get(inkex.addNS('docbase',u'sodipodi'),'')
docname = ttmp_orig.get(inkex.addNS('docname',u'sodipodi'))
- inkex.debug((docbase,docname))
-
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 + '/'+ 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('//image',inkex.NSS):
+ for node in self.document.xpath('//svg:image',inkex.NSS):
self.collectAndZipImages(node, tmp_dir, docname, z)
##copy tmpdoc to tempdir
z.write(dst_file.encode("latin-1"),docstripped.encode("latin-1")+'.svg')
z.close()
- out = open(tmp_dir + '/'+ docname + '.zip','r')
+ out = open(tmp_dir + os.path.sep + docname + '.zip','r')
sys.stdout.write(out.read())
out.close()
def collectAndZipImages(self, node, tmp_dir, docname, z):
xlink = node.get(inkex.addNS('href',u'xlink'))
- if (xlink.value[:4]!='data'):
+ if (xlink[:4]!='data'):
absref=node.get(inkex.addNS('absref',u'sodipodi'))
-
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)):
- shutil.copy(tmp_dir + '/' + absref,tmp_dir)
- z.write(tmp_dir + '/' + absref.encode("latin-1"),os.path.basename(absref).encode("latin-1"))
+ elif (os.path.isfile(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"))
+ else:
+ inkex.debug('Could not locate file: %s' % absref)
node.set(inkex.addNS('href',u'xlink'),os.path.basename(absref))
node.set(inkex.addNS('absref',u'sodipodi'),os.path.basename(absref))