def odf_new_container(path_or_file): """Return an odf_container instance based on the given template. """ if path_or_file in ODF_TYPES: path_or_file = _get_abspath(ODF_TYPES[path_or_file]) template_container = odf_get_container(path_or_file) # Return a copy of the template container clone = template_container.clone() # Change type from template to regular mimetype = clone.get_part('mimetype').replace('-template', '') clone.set_part('mimetype', mimetype) # Update the manifest manifest = odf_manifest(ODF_MANIFEST, clone) manifest.set_media_type('/', mimetype) clone.set_part(ODF_MANIFEST, manifest.serialize()) return clone
def get_xmlpart(self, part_name): if part_name not in ODF_PARTS and part_name != 'manifest': raise ValueError, '"%s" is not an XML part' % part_name parts = self.__xmlparts part = parts.get(part_name) if part is None: container = self.container if part_name == 'content': part = odf_content(part_name, container) elif part_name == 'meta': part = odf_meta(part_name, container) elif part_name == 'styles': part = odf_styles(part_name, container) elif part_name == 'manifest': part = odf_manifest(part_name, container) else: part = odf_xmlpart(part_name, container) parts[part_name] = part return part