Plone的压缩导出
项目描述
概述
ftw.zipexport 提供了一种通用的解决方案,用于将Plone中的数据导出为zip存档。
用户可以在文档列表中通过“导出为Zip”操作导出数据。
安装
兼容性
对于压缩总大小超过4Gb的文件,需要python 2.7.4。
步骤-by-步骤
将ftw.zipexport添加到你的buildout配置中
[instance] eggs = ftw.zipexport
运行buildout
在portal_setup中安装ftw.zipexport
实现
首先,我们需要收集所有要压缩的数据。使用IZipRepresentation接口来完成这项任务。
get_files函数返回一个元组的列表。元组包含两个值。第一个是一个相对路径,文件将在这个路径下在zip中显示。第二个值是文件数据,要么是文件,要么是流。
class IZipRepresentation(Interface):
def get_files(path_prefix='', recursive=True, toplevel=True):
默认情况下,我们支持基本的数据类型,如文件夹和文件。更复杂的数据类型需要为IZipRepresentation提供自己的适配器。
请随意扩展预定义适配器之一:[预定义表示](https://github.com/4teamwork/ftw.zipexport/tree/master/ftw/zipexport/representations)
我们的IZipRepresentation生成数据后,将传递给ZipGeneration辅助类。
class ZipGenerator(object):
def add_file(file_path, file_pointer):
Zipps the file and adds it to the archive.
If large or many files are selected this function might take some time to execute.
def generate():
returns a temp file holding the generated zip
以下是描述步骤的示例代码
from zope.component import getMultiAdapter
from ftw.zipexport.generation import ZipGenerator
from ftw.zipexport.interfaces import IZipRepresentation
ziprepresentation = getMultiAdapter((self.folder, self.request), interface=IZipRepresentation)
with ZipGenerator() as zipgenerator:
for file_path, file_pointer in ziprepresentation.get_files():
zipgenerator.add_file(file_path, file_pointer)
generated_zip_pointer = zipgenerator.generate()
下载由标准的BrowserView处理,它简单地从临时文件中读取。有关详细信息,请参阅代码:[zipexportview.py](https://github.com/4teamwork/ftw.zipexport/blob/master/ftw/zipexport/zipexportview.py)
当前支持的数据类型
IFolderish
IFileContent
IDexterityItem with IPrimaryFieldInfo
路径归一化
路径自动使用Plone的IFileNameNormalizer。如果您想使用自定义归一化,可以将其传递给ZipGenerator
from ftw.zipexport.generation import ZipGenerator
from Products.CMFPlone.utils import safe_unicode
import re
def normalize_path(path):
path = safe_unicode(path).replace(u'\\', u'/')
return re.sub(ur'[^\w\-.\/]', u'', path)
with ZipGenerator(path_normalizer=normalize_path) as zipgenerator:
...
传递None来完全禁用归一化
from ftw.zipexport.generation import ZipGenerator
with ZipGenerator(path_normalizer=None) as zipgenerator:
...
值得拥有的特性
多线程
链接
Github: [https://github.com/4teamwork/ftw.zipexport](https://github.com/4teamwork/ftw.zipexport)
问题:[https://github.com/4teamwork/ftw.zipexport/issues](https://github.com/4teamwork/ftw.zipexport/issues)
持续集成:[https://jenkins.4teamwork.ch/view/All/search/?q=ftw.zipexport](https://jenkins.4teamwork.ch/view/All/search/?q=ftw.zipexport)
版权
本软件包版权所有4teamwork。
ftw.zipexport许可协议为GNU通用公共许可证,版本2。
变更日志
1.6.5 (2023-09-08)
现在导出选定的文件夹将保留顶级目录的结构。[elioschmutz]
1.6.4 (2019-09-19)
修复了标题包含元音字母的文件夹中包含空子文件夹时的重复子文件夹。[phgross]
1.6.3 (2018-04-17)
允许IFolderish通过属性指定自定义标题。[Rotonen]
停止支持Plone 4.2。[mbaechtold]
1.6.2 (2017-11-29)
删除了zip选择视图中上下文错误检查。[phgross]
1.6.1 (2017-09-06)
修复了zip文件名包含元音字母时的编码错误。[phgross]
1.6.0 (2017-08-17)
默认包含空文件夹,并添加了禁用此行为的可能性。[elioschmutz]
1.5.0 (2016-12-15)
停止官方支持Python 2.6 [jone]
1.4.0 (2016-12-12)
添加了ZIP导出事件 [Rotonen]
1.3.1 (2016-02-09)
当导出标题包含元音字母的AT文件夹时不会失败 [fRiSi]
如果未设置文件名,则回退到对象.id。[fRiSi]
1.3.0 (2015-05-05)
对添加到ZIP文件的所有路径进行归一化。[jone]
处理ZIP中的路径编码。[jone]
添加了检查fs是否有足够空间创建zip文件的检查。[lknoepfel]
1.2.2 (2015-03-25)
修复了在文件导出中发生的错误,如果要导出的文件没有blob而是OFS文件。[mbaechtold]
1.2.1 (2014-06-05)
修复了默认配置文件中的元数据版本。[lknoepfel]
1.2.0 (2014-05-26)
添加了选择导出可用的多个接口的选项。[lknoepfel]
当内容太大无法zip时,添加了错误消息。当ZIP64不可用且内容大于4GB时会发生这种情况。[lknoepfel]
更正了未选择zip导出内容时的错误消息。[lknoepfel]
拒绝在不受允许的内容上进行zip导出。[lknoepfel]
包含默认AT图像文件。[jone]
添加了由I. Anthenien提供的法语翻译。[lknoepfel]
1.1.1 (2013-11-21)
添加了对具有相同文件名的文件的处理。[lknoepfel]
添加了一个单独的配置文件来安装额外的zip导出文档操作。[deif]
1.1.0 (2013-10-14)
添加导出限制。[lknoepfel]
修复包含带有重音符号的标题的嵌套文件夹中的编码问题。[jone]
1.0.0 (2013-09-13)
初始开发
项目详情
ftw.zipexport-1.6.5.tar.gz 的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 5ed9c612b6165bfc34fbcf69c061385b4350bd19cd9f36cf92f40c21193c55f9 |
|
MD5 | 35971b10344e1440e8d1778517953a65 |
|
BLAKE2b-256 | 89e27ecad1a51156febe7c004ce990a2d1e7080b0c0d4a56d5752bb5209916aa |