Code

Partial fix for bug #386664.
[inkscape.git] / share / extensions / svg_and_media_zip_output.py
index 88c294245283617390c7bf12dd0b64114f8407b1..6aaf3b2262ec42fdae0e693f10af7852779fbe29 100644 (file)
@@ -56,24 +56,23 @@ class SVG_and_Media_ZIP_Output(inkex.Effect):
     def clear_tmp(self):
         shutil.rmtree(self.tmp_dir)
 
-
     def effect(self):
         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]
-
         #create os temp dir
         self.tmp_dir = tempfile.mkdtemp()
 
-        # create destination zip in same directory as the document
-        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', '')
+        docstripped = docstripped.replace('.svg', '')
+        docstripped = docstripped.replace('.svgz', '')
+        
+        # create destination zip in same directory as the document
+        self.zip_file = os.path.join(self.tmp_dir, docstripped) + '.zip'
+        z = zipfile.ZipFile(self.zip_file, 'w')
 
         #read tmpdoc and copy all images to temp dir
         for node in self.document.xpath('//svg:image', namespaces=inkex.NSS):
@@ -87,14 +86,14 @@ class SVG_and_Media_ZIP_Output(inkex.Effect):
 
         stream.close()
 
-        z.write(dst_file.encode("latin-1"),docstripped.encode("latin-1")+'.svg') 
-        z.close()
+        z.write(dst_file,docstripped.encode("utf_8")+'.svg')
 
+        z.close()
 
     def collectAndZipImages(self, node, docname, z):
         xlink = node.get(inkex.addNS('href',u'xlink'))
         if (xlink[:4]!='data'):
-            absref=node.get(inkex.addNS('absref','sodipodi'))
+            absref=node.get(inkex.addNS('absref',u'sodipodi'))
             url=urlparse.urlparse(xlink)
             href=urllib.unquote(url.path)
             if os.name == 'nt' and href[0] == '/':
@@ -104,12 +103,12 @@ class SVG_and_Media_ZIP_Output(inkex.Effect):
 
             if (os.path.isfile(absref)):
                 shutil.copy(absref, self.tmp_dir)
-                z.write(absref.encode("latin-1"),os.path.basename(absref).encode("latin-1"))
-            elif (os.path.isfile(self.tmp_dir + os.path.sep + absref)):
+                z.write(absref, os.path.basename(absref).encode("utf_8"))
+            elif (os.path.isfile(os.path.join(self.tmp_dir, absref))):
                 #TODO: please explain why this clause is necessary
-                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"))
+                shutil.copy(os.path.join(self.tmp_dir, absref), self.tmp_dir)
+                z.write(os.path.join(self.tmp_dir, absref),
+                        os.path.basename(absref).encode("utf_8"))
             else:
                 inkex.errormsg(_('Could not locate file: %s') % absref)