ftw.zipexport


Nameftw.zipexport JSON
Version 1.6.5 PyPI version JSON
download
home_pagehttps://github.com/4teamwork/ftw.zipexport
SummaryZip export for Plone
upload_time2023-09-08 07:29:33
maintainerLukas Knoepfel
docs_urlNone
author4teamwork AG
requires_python
licenseGPL2
keywords ftw zip export
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Overview
========

``ftw.zipexport`` provides a generic solution to export data from plone
in a zip archive.

A user can export data with the "Export as Zip" action in document listings.

Install
=======


Compatibility
-------------

For zipping files with a total size of over 4Gb python 2.7.4 is required.

Step-by-Step
------------

- Add ``ftw.zipexport`` to your buildout configuration

::

    [instance]
    eggs =
        ftw.zipexport

- Run buildout

- Install ``ftw.zipexport`` in portal_setup

Implementation
==============

In a first step we have to collect all data to zip.
Use the IZipRepresentation interface for this task.

The get_files function returns a list of tuples. The tuples consist of two values.
First a relative path under which the file should show up in the zip.
Second the data as eather a file or a stream.

.. code:: python

	class IZipRepresentation(Interface):

	    def get_files(path_prefix='', recursive=True, toplevel=True):

By default we support basic data-types like folder and files.
More complex data-types require an own adapter for IZipRepresentation.

Feel free to extend one of the predefined adapters:
`Predefined representations <https://github.com/4teamwork/ftw.zipexport/tree/master/ftw/zipexport/representations>`_

The data generated by our IZipRepresentation then gets delivered to the ZipGeneration helper class.

.. code:: python

	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

Here is the sample code of the described steps:

.. code:: python

	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()


The download is handled in a standard BrowserView which plainly reads from the temp file.
For details check out the code:
`zipexportview.py <https://github.com/4teamwork/ftw.zipexport/blob/master/ftw/zipexport/zipexportview.py>`_.

Current supported data-types
----------------------------

* IFolderish
* IFileContent
* IDexterityItem with IPrimaryFieldInfo

Path Normalization
------------------

Paths are automatically using Plone's ``IFileNameNormalizer``.
If you want to use a custom normalization, you  can pass it to the ``ZipGenerator``:

.. code:: python

    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:
        ...

Pass ``None`` to disable normalization completely:

.. code:: python

    from ftw.zipexport.generation import ZipGenerator

    with ZipGenerator(path_normalizer=None) as zipgenerator:
        ...




Nice to have
============

* Multithreading

Links
=====

- Github: https://github.com/4teamwork/ftw.zipexport
- Issues: https://github.com/4teamwork/ftw.zipexport/issues
- Continuous integration: https://jenkins.4teamwork.ch/view/All/search/?q=ftw.zipexport

Copyright
=========

This package is copyright by `4teamwork <http://www.4teamwork.ch/>`_.

``ftw.zipexport`` is licensed under GNU General Public License, version 2.

Changelog
=========


1.6.5 (2023-09-08)
------------------

- Exporting selected folders will now preserve the folder structure on the top level. [elioschmutz]


1.6.4 (2019-09-19)
------------------

- Fix doubled subfolders when a folder with umlaut in the title contains empty subfolders. [phgross]


1.6.3 (2018-04-17)
------------------

- Allow IFolderish to specify a custom title via a property. [Rotonen]
- Drop support for Plone 4.2. [mbaechtold]


1.6.2 (2017-11-29)
------------------

- Remove wrong allowed check on context for zip selected view. [phgross]

1.6.1 (2017-09-06)
------------------

- Fix encoding bug when zip filename contains umlauts. [phgross]


1.6.0 (2017-08-17)
------------------

- Include empty folders by default and add possibility to deactivate this behavior. [elioschmutz]


1.5.0 (2016-12-15)
------------------

- Drop official support for Python 2.6 [jone]


1.4.0 (2016-12-12)
------------------

- Add events for the ZIP exports
  [Rotonen]


1.3.1 (2016-02-09)
------------------

- Do not fail when exporting AT folders with titles containing umlauts
  [fRiSi]

- Fall back to object.id in case filename is not set.
  [fRiSi]


1.3.0 (2015-05-05)
------------------

- Normalize all paths added to the ZIP file.
  [jone]

- Handle path encoding in ZIP.
  [jone]

- Added check if fs has enough space to create the zip file.
  [lknoepfel]


1.2.2 (2015-03-25)
------------------

- Fixed a bug in the file export which occurred if the file to be exported
  did not have a blob but an OFS file.
  [mbaechtold]


1.2.1 (2014-06-05)
------------------

- Fixed metadata version in default profile.
  [lknoepfel]


1.2.0 (2014-05-26)
------------------

- Added option to select multiple interfaces on which the export is available.
  [lknoepfel]

- Added error message when the content is too big to zip.
  This happens when the ZIP64 isn't available and the content is bigger than 4GB.
  [lknoepfel]

- Corrected error message when no zip-exportable content is selected.
  [lknoepfel]

- Deny zipexport on unallowed content.
  [lknoepfel]

- Include default AT image files.
  [jone]

- Added French translation by I. Anthenien.
  [lknoepfel]


1.1.1 (2013-11-21)
------------------

- Added handling for files with same filename.
  [lknoepfel]
- Added a separate profile to install an additional zip-export document action.
  [deif]

1.1.0 (2013-10-14)
------------------

- Added export limitation.
  [lknoepfel]
- Fix encoding problem with nested folders containing umlauts in the title.
  [jone]


1.0.0 (2013-09-13)
------------------

- Initial Development
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/4teamwork/ftw.zipexport",
    "name": "ftw.zipexport",
    "maintainer": "Lukas Knoepfel",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "ftw zip export",
    "author": "4teamwork AG",
    "author_email": "mailto:info@4teamwork.ch",
    "download_url": "https://files.pythonhosted.org/packages/89/e2/7ecad1a51156febe7c004ce990a2d1e7080b0c0d4a56d5752bb5209916aa/ftw.zipexport-1.6.5.tar.gz",
    "platform": null,
    "description": "Overview\n========\n\n``ftw.zipexport`` provides a generic solution to export data from plone\nin a zip archive.\n\nA user can export data with the \"Export as Zip\" action in document listings.\n\nInstall\n=======\n\n\nCompatibility\n-------------\n\nFor zipping files with a total size of over 4Gb python 2.7.4 is required.\n\nStep-by-Step\n------------\n\n- Add ``ftw.zipexport`` to your buildout configuration\n\n::\n\n    [instance]\n    eggs =\n        ftw.zipexport\n\n- Run buildout\n\n- Install ``ftw.zipexport`` in portal_setup\n\nImplementation\n==============\n\nIn a first step we have to collect all data to zip.\nUse the IZipRepresentation interface for this task.\n\nThe get_files function returns a list of tuples. The tuples consist of two values.\nFirst a relative path under which the file should show up in the zip.\nSecond the data as eather a file or a stream.\n\n.. code:: python\n\n\tclass IZipRepresentation(Interface):\n\n\t    def get_files(path_prefix='', recursive=True, toplevel=True):\n\nBy default we support basic data-types like folder and files.\nMore complex data-types require an own adapter for IZipRepresentation.\n\nFeel free to extend one of the predefined adapters:\n`Predefined representations <https://github.com/4teamwork/ftw.zipexport/tree/master/ftw/zipexport/representations>`_\n\nThe data generated by our IZipRepresentation then gets delivered to the ZipGeneration helper class.\n\n.. code:: python\n\n\tclass ZipGenerator(object):\n\t\tdef add_file(file_path, file_pointer):\n\t\t\tZipps the file and adds it to the archive.\n\t\t\tIf large or many files are selected this function might take some time to execute.\n\n\t\tdef generate():\n\t\t\treturns a temp file holding the generated zip\n\nHere is the sample code of the described steps:\n\n.. code:: python\n\n\tfrom zope.component import getMultiAdapter\n\tfrom ftw.zipexport.generation import ZipGenerator\n\tfrom ftw.zipexport.interfaces import IZipRepresentation\n\n\tziprepresentation = getMultiAdapter((self.folder, self.request), interface=IZipRepresentation)\n\twith ZipGenerator() as zipgenerator:\n\t\tfor file_path, file_pointer in ziprepresentation.get_files():\n\t\t\tzipgenerator.add_file(file_path, file_pointer)\n\t\tgenerated_zip_pointer = zipgenerator.generate()\n\n\nThe download is handled in a standard BrowserView which plainly reads from the temp file.\nFor details check out the code:\n`zipexportview.py <https://github.com/4teamwork/ftw.zipexport/blob/master/ftw/zipexport/zipexportview.py>`_.\n\nCurrent supported data-types\n----------------------------\n\n* IFolderish\n* IFileContent\n* IDexterityItem with IPrimaryFieldInfo\n\nPath Normalization\n------------------\n\nPaths are automatically using Plone's ``IFileNameNormalizer``.\nIf you want to use a custom normalization, you  can pass it to the ``ZipGenerator``:\n\n.. code:: python\n\n    from ftw.zipexport.generation import ZipGenerator\n    from Products.CMFPlone.utils import safe_unicode\n    import re\n\n    def normalize_path(path):\n        path = safe_unicode(path).replace(u'\\\\', u'/')\n        return re.sub(ur'[^\\w\\-.\\/]', u'', path)\n\n    with ZipGenerator(path_normalizer=normalize_path) as zipgenerator:\n        ...\n\nPass ``None`` to disable normalization completely:\n\n.. code:: python\n\n    from ftw.zipexport.generation import ZipGenerator\n\n    with ZipGenerator(path_normalizer=None) as zipgenerator:\n        ...\n\n\n\n\nNice to have\n============\n\n* Multithreading\n\nLinks\n=====\n\n- Github: https://github.com/4teamwork/ftw.zipexport\n- Issues: https://github.com/4teamwork/ftw.zipexport/issues\n- Continuous integration: https://jenkins.4teamwork.ch/view/All/search/?q=ftw.zipexport\n\nCopyright\n=========\n\nThis package is copyright by `4teamwork <http://www.4teamwork.ch/>`_.\n\n``ftw.zipexport`` is licensed under GNU General Public License, version 2.\n\nChangelog\n=========\n\n\n1.6.5 (2023-09-08)\n------------------\n\n- Exporting selected folders will now preserve the folder structure on the top level. [elioschmutz]\n\n\n1.6.4 (2019-09-19)\n------------------\n\n- Fix doubled subfolders when a folder with umlaut in the title contains empty subfolders. [phgross]\n\n\n1.6.3 (2018-04-17)\n------------------\n\n- Allow IFolderish to specify a custom title via a property. [Rotonen]\n- Drop support for Plone 4.2. [mbaechtold]\n\n\n1.6.2 (2017-11-29)\n------------------\n\n- Remove wrong allowed check on context for zip selected view. [phgross]\n\n1.6.1 (2017-09-06)\n------------------\n\n- Fix encoding bug when zip filename contains umlauts. [phgross]\n\n\n1.6.0 (2017-08-17)\n------------------\n\n- Include empty folders by default and add possibility to deactivate this behavior. [elioschmutz]\n\n\n1.5.0 (2016-12-15)\n------------------\n\n- Drop official support for Python 2.6 [jone]\n\n\n1.4.0 (2016-12-12)\n------------------\n\n- Add events for the ZIP exports\n  [Rotonen]\n\n\n1.3.1 (2016-02-09)\n------------------\n\n- Do not fail when exporting AT folders with titles containing umlauts\n  [fRiSi]\n\n- Fall back to object.id in case filename is not set.\n  [fRiSi]\n\n\n1.3.0 (2015-05-05)\n------------------\n\n- Normalize all paths added to the ZIP file.\n  [jone]\n\n- Handle path encoding in ZIP.\n  [jone]\n\n- Added check if fs has enough space to create the zip file.\n  [lknoepfel]\n\n\n1.2.2 (2015-03-25)\n------------------\n\n- Fixed a bug in the file export which occurred if the file to be exported\n  did not have a blob but an OFS file.\n  [mbaechtold]\n\n\n1.2.1 (2014-06-05)\n------------------\n\n- Fixed metadata version in default profile.\n  [lknoepfel]\n\n\n1.2.0 (2014-05-26)\n------------------\n\n- Added option to select multiple interfaces on which the export is available.\n  [lknoepfel]\n\n- Added error message when the content is too big to zip.\n  This happens when the ZIP64 isn't available and the content is bigger than 4GB.\n  [lknoepfel]\n\n- Corrected error message when no zip-exportable content is selected.\n  [lknoepfel]\n\n- Deny zipexport on unallowed content.\n  [lknoepfel]\n\n- Include default AT image files.\n  [jone]\n\n- Added French translation by I. Anthenien.\n  [lknoepfel]\n\n\n1.1.1 (2013-11-21)\n------------------\n\n- Added handling for files with same filename.\n  [lknoepfel]\n- Added a separate profile to install an additional zip-export document action.\n  [deif]\n\n1.1.0 (2013-10-14)\n------------------\n\n- Added export limitation.\n  [lknoepfel]\n- Fix encoding problem with nested folders containing umlauts in the title.\n  [jone]\n\n\n1.0.0 (2013-09-13)\n------------------\n\n- Initial Development",
    "bugtrack_url": null,
    "license": "GPL2",
    "summary": "Zip export for Plone",
    "version": "1.6.5",
    "project_urls": {
        "Homepage": "https://github.com/4teamwork/ftw.zipexport"
    },
    "split_keywords": [
        "ftw",
        "zip",
        "export"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "89e27ecad1a51156febe7c004ce990a2d1e7080b0c0d4a56d5752bb5209916aa",
                "md5": "35971b10344e1440e8d1778517953a65",
                "sha256": "5ed9c612b6165bfc34fbcf69c061385b4350bd19cd9f36cf92f40c21193c55f9"
            },
            "downloads": -1,
            "filename": "ftw.zipexport-1.6.5.tar.gz",
            "has_sig": false,
            "md5_digest": "35971b10344e1440e8d1778517953a65",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 30980,
            "upload_time": "2023-09-08T07:29:33",
            "upload_time_iso_8601": "2023-09-08T07:29:33.673681Z",
            "url": "https://files.pythonhosted.org/packages/89/e2/7ecad1a51156febe7c004ce990a2d1e7080b0c0d4a56d5752bb5209916aa/ftw.zipexport-1.6.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-08 07:29:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "4teamwork",
    "github_project": "ftw.zipexport",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "ftw.zipexport"
}
        
Elapsed time: 0.11506s