Convert OpenDrawDoc to use zipfile
svn: r1240
This commit is contained in:
parent
487cf61840
commit
a1484e8e48
@ -21,6 +21,8 @@
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
import string
|
import string
|
||||||
|
import zipfile
|
||||||
|
|
||||||
import Plugins
|
import Plugins
|
||||||
from intl import gettext as _
|
from intl import gettext as _
|
||||||
|
|
||||||
@ -53,13 +55,8 @@ class OpenDrawDoc(DrawDoc):
|
|||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
tempfile.tempdir = "/tmp"
|
tempfile.tempdir = "/tmp"
|
||||||
self.tempdir = tempfile.mktemp()
|
self.content_xml = tempfile.mktemp()
|
||||||
os.mkdir(self.tempdir,0700)
|
self.f = open(self.content_xml,"wb")
|
||||||
os.mkdir(self.tempdir + os.sep + "Pictures")
|
|
||||||
os.mkdir(self.tempdir + os.sep + "META-INF")
|
|
||||||
|
|
||||||
fname = self.tempdir + os.sep + "content.xml"
|
|
||||||
self.f = open(fname,"wb")
|
|
||||||
|
|
||||||
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
self.f.write('<office:document-content ')
|
self.f.write('<office:document-content ')
|
||||||
@ -131,25 +128,25 @@ class OpenDrawDoc(DrawDoc):
|
|||||||
|
|
||||||
def _write_zip(self):
|
def _write_zip(self):
|
||||||
|
|
||||||
if os.path.isfile(self.filename):
|
file = zipfile.ZipFile(self.filename,"w",zipfile.ZIP_DEFLATED)
|
||||||
os.unlink(self.filename)
|
file.write(self.manifest_xml,"META-INF/manifest.xml")
|
||||||
|
file.write(self.content_xml,"content.xml")
|
||||||
|
file.write(self.meta_xml,"meta.xml")
|
||||||
|
file.write(self.styles_xml,"styles.xml")
|
||||||
|
|
||||||
os.system("cd " + self.tempdir + "; " + const.zipcmd + " " \
|
# for image in self.photo_list:
|
||||||
+ self.filename + " .")
|
# base = os.path.basename(image[0])
|
||||||
|
# file.write(image[0],"Pictures/%s" % base)
|
||||||
|
file.close()
|
||||||
|
|
||||||
os.unlink(self.tempdir + os.sep + "META-INF" + os.sep + "manifest.xml")
|
os.unlink(self.manifest_xml)
|
||||||
os.unlink(self.tempdir + os.sep + "content.xml")
|
os.unlink(self.content_xml)
|
||||||
os.unlink(self.tempdir + os.sep + "meta.xml")
|
os.unlink(self.meta_xml)
|
||||||
os.unlink(self.tempdir + os.sep + "styles.xml")
|
os.unlink(self.styles_xml)
|
||||||
# for image in self.image_list:
|
|
||||||
# os.unlink(self.tempdir + os.sep + "Pictures" + os.sep + image)
|
|
||||||
os.rmdir(self.tempdir + os.sep + "Pictures")
|
|
||||||
os.rmdir(self.tempdir + os.sep + "META-INF")
|
|
||||||
os.rmdir(self.tempdir)
|
|
||||||
|
|
||||||
def _write_styles_file(self):
|
def _write_styles_file(self):
|
||||||
file = self.tempdir + os.sep + "styles.xml"
|
self.styles_xml = tempfile.mktemp()
|
||||||
self.f = open(file,"wb")
|
self.f = open(self.styles_xml,"wb")
|
||||||
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
self.f.write('<office:document-styles ')
|
self.f.write('<office:document-styles ')
|
||||||
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
|
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
|
||||||
@ -339,8 +336,8 @@ class OpenDrawDoc(DrawDoc):
|
|||||||
self.f.write(text)
|
self.f.write(text)
|
||||||
|
|
||||||
def _write_manifest(self):
|
def _write_manifest(self):
|
||||||
file = self.tempdir + os.sep + "META-INF" + os.sep + "manifest.xml"
|
self.manifest_xml = tempfile.mktemp()
|
||||||
self.f = open(file,"wb")
|
self.f = open(self.manifest_xml,"wb")
|
||||||
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
self.f.write('<manifest:manifest ')
|
self.f.write('<manifest:manifest ')
|
||||||
self.f.write('xmlns:manifest="http://openoffice.org/2001/manifest">')
|
self.f.write('xmlns:manifest="http://openoffice.org/2001/manifest">')
|
||||||
@ -361,9 +358,9 @@ class OpenDrawDoc(DrawDoc):
|
|||||||
self.f.close()
|
self.f.close()
|
||||||
|
|
||||||
def _write_meta_file(self):
|
def _write_meta_file(self):
|
||||||
file = self.tempdir + os.sep + "meta.xml"
|
|
||||||
name = self.name
|
name = self.name
|
||||||
self.f = open(file,"wb")
|
self.meta_xml = tempfile.mktemp()
|
||||||
|
self.f = open(self.meta_xml,"wb")
|
||||||
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
self.f.write('<?xml version="1.0" encoding="UTF-8"?>\n')
|
||||||
self.f.write('<office:document-meta ')
|
self.f.write('<office:document-meta ')
|
||||||
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
|
self.f.write('xmlns:office="http://openoffice.org/2000/office" ')
|
||||||
|
@ -117,7 +117,8 @@ class AncestorChart:
|
|||||||
try:
|
try:
|
||||||
self.doc.close()
|
self.doc.close()
|
||||||
except:
|
except:
|
||||||
print _("Document write failure")
|
import DisplayTrace
|
||||||
|
DisplayTrace.DisplayTrace()
|
||||||
|
|
||||||
#--------------------------------------------------------------------
|
#--------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user