Left: | ||
Right: |
OLD | NEW |
---|---|
1 ############################################################################### | 1 ############################################################################### |
2 # | 2 # |
3 # Copyright (c) 2009 Cedric Krier. | 3 # Copyright (c) 2009 Cedric Krier. |
4 # Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights | 4 # Copyright (c) 2007, 2008 OpenHex SPRL. (http://openhex.com) All Rights |
5 # Reserved. | 5 # Reserved. |
6 # | 6 # |
7 # This program is free software; you can redistribute it and/or modify it under | 7 # This program is free software; you can redistribute it and/or modify it under |
8 # the terms of the GNU General Public License as published by the Free Software | 8 # the terms of the GNU General Public License as published by the Free Software |
9 # Foundation; either version 3 of the License, or (at your option) any later | 9 # Foundation; either version 3 of the License, or (at your option) any later |
10 # version. | 10 # version. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } | 78 } |
79 | 79 |
80 RELATORIO_URI = 'http://relatorio.openhex.org/' | 80 RELATORIO_URI = 'http://relatorio.openhex.org/' |
81 GENSHI_URI = 'http://genshi.edgewall.org/' | 81 GENSHI_URI = 'http://genshi.edgewall.org/' |
82 MANIFEST = 'META-INF/manifest.xml' | 82 MANIFEST = 'META-INF/manifest.xml' |
83 META = 'meta.xml' | 83 META = 'meta.xml' |
84 THUMBNAILS = 'Thumbnails' | 84 THUMBNAILS = 'Thumbnails' |
85 output_encode = genshi.output.encode | 85 output_encode = genshi.output.encode |
86 EtreeElement = lxml.etree.Element | 86 EtreeElement = lxml.etree.Element |
87 | 87 |
88 import os | |
89 from lxml import etree | |
ced
2011/08/14 10:30:31
Why not use lxml.etree imported above?
| |
90 class MyZip(zipfile.ZipFile): | |
ced
2011/08/14 10:30:31
I don't like the behavior of this class because it
| |
91 FODT = ".FODT" | |
92 ODT = ".ODT" | |
93 def __init__(self, filepath): | |
94 self.content = None | |
95 self.styles = None | |
96 self.isFODT = False | |
97 ······· | |
98 (basename, extension) = os.path.splitext(filepath) | |
99 ······· | |
100 if extension.upper() == self.FODT: | |
ced
2011/08/14 10:30:31
Could not the test be made on a test if it is a zi
| |
101 self.isFODT = True | |
102 self._parseFODT(filepath) | |
103 else: | |
104 self.isFODT = False | |
105 zipfile.ZipFile.__init__(self, filepath) | |
106 ··· | |
107 def _parseFODT(self, filepath): | |
108 parser = etree.XMLParser(remove_blank_text = True) | |
ced
2011/08/14 10:30:31
Why removing blank_text?
| |
109 root = etree.parse(filepath, parser) | |
110 ······· | |
111 meta = (root.getroot())[0] | |
ced
2011/08/14 10:30:31
Must use tag name
| |
112 settings = (root.getroot())[1] | |
113 scr = (root.getroot())[2] | |
114 ffd = (root.getroot())[3] | |
115 styl = (root.getroot())[4] | |
116 astyles = (root.getroot())[5] | |
117 mstyles = (root.getroot())[6] | |
118 bod = (root.getroot())[7] | |
119 ······· | |
120 NSMAP = (root.getroot()).nsmap | |
121 ······· | |
122 content = etree.Element('{%s}%s' % ("office","document-content"), nsmap = NSMAP) | |
123 content.append(scr) | |
124 content.append(ffd) | |
125 content.append(astyles) | |
126 content.append(bod) | |
127 self.content = etree.tostring(content, pretty_print = True) | |
128 ······· | |
129 ······· | |
130 styles = etree.Element('{%s}%s' % ("office","document-styles"), nsmap = N SMAP) | |
131 styles.append(ffd) | |
132 styles.append(styl) | |
133 styles.append(astyles) | |
134 styles.append(mstyles) | |
135 self.styles = etree.tostring(styles, pretty_print = True) | |
136 ···· | |
137 def read(self, name): | |
138 if self.isFODT: | |
139 if name == 'content.xml': | |
140 return self.content | |
141 ············ | |
142 elif name == 'styles.xml': | |
143 return self.styles | |
144 ············ | |
145 else: | |
146 pass | |
147 ········ | |
148 else: | |
149 return zipfile.ZipFile.read(self, name) | |
150 | |
88 # A note regarding OpenDocument namespaces: | 151 # A note regarding OpenDocument namespaces: |
89 # | 152 # |
90 # The current code assumes the original OpenOffice document uses default | 153 # The current code assumes the original OpenOffice document uses default |
91 # namespace prefix ("table", "xlink", "draw", ...). We derive the actual | 154 # namespace prefix ("table", "xlink", "draw", ...). We derive the actual |
92 # namespaces URIs from their prefix, instead of the other way round. This has | 155 # namespaces URIs from their prefix, instead of the other way round. This has |
93 # the advantage that if a new version of the format use different namespaces | 156 # the advantage that if a new version of the format use different namespaces |
94 # (this is not the case for ODF 1.1 but could be the case in the future since | 157 # (this is not the case for ODF 1.1 but could be the case in the future since |
95 # there is a version number in those namespaces after all), Relatorio will | 158 # there is a version number in those namespaces after all), Relatorio will |
96 # support those new formats out of the box. | 159 # support those new formats out of the box. |
97 | 160 |
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
839 self.outzip.writestr(f_info, self.inzip.read(f_info.filename)) | 902 self.outzip.writestr(f_info, self.inzip.read(f_info.filename)) |
840 self.manifest.remove_file_entry(THUMBNAILS + '/') | 903 self.manifest.remove_file_entry(THUMBNAILS + '/') |
841 if manifest_info: | 904 if manifest_info: |
842 self.outzip.writestr(f_info, str(self.manifest)) | 905 self.outzip.writestr(f_info, str(self.manifest)) |
843 self.inzip.close() | 906 self.inzip.close() |
844 self.outzip.close() | 907 self.outzip.close() |
845 | 908 |
846 return self.new_oo | 909 return self.new_oo |
847 | 910 |
848 MIMETemplateLoader.add_factory('oo.org', Template) | 911 MIMETemplateLoader.add_factory('oo.org', Template) |
OLD | NEW |