Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

70730 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions ims/zip/browser/templates/zipper.pt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
<p>
This feature will create a compressed zip file of all content within this folder and its sub-folders.
</p>
<div class="alert alert-warning">
<strong>Windows Path Size Limit</strong>
Windows has a maximum total path size limit of 256 characters. The maximum path size in this zip file is
${view/path_size} characters. The total path size will be this number <i>plus</i> the length of the folder
path to which you extract the files. Consider renaming the short name of folders and files if the total
path size needs to be shorter.
</div>
<p>
This process may be slow for large folders, and will fail for very large folders. Please contact
<a href="mailto:${view/technical_support_address}">
Expand Down
29 changes: 18 additions & 11 deletions ims/zip/browser/zipper.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,24 @@ def small_zip(self):
def size_estimate(self):
return '%.2f MB' % (_get_size(self) / 1024.0 / 1024)

@property
def base_path(self):
return '/'.join(self.context.getPhysicalPath()) + '/' # the path in the ZCatalog

class Zipper(BrowserView):
""" Zips content to a temp file """
def path_size(self):
_max = max([len(b.getPath()) for b in self.contents])
return _max - len(self.base_path)

@property
def contents(self):
""" returns catalog brains """
cat = plone.api.portal.get_tool('portal_catalog')
ptypes = cat.uniqueValuesFor('portal_type')
return cat(path=self.base_path, object_provides=IZippable.__identifier__, portal_type=ptypes)

def technical_support_address(self):
return plone.api.portal.get_registry_record('ims.zip.interfaces.IZipSettings.technical_support_address') or \
plone.api.portal.get_registry_record('plone.email_from_address')

class Zipper(ZipPrompt):
""" Zips content to a temp file """

def __call__(self):
try:
Expand All @@ -73,16 +84,12 @@ def do_zip(self):
# force this, whether it was passed in the request or not
self.request['zip64'] = 1

base_path = '/'.join(self.context.getPhysicalPath()) + '/' # the path in the ZCatalog
cat = plone.api.portal.get_tool('portal_catalog')
ptypes = cat.uniqueValuesFor('portal_type')
content = cat(path=base_path, object_provides=IZippable.__identifier__, portal_type=ptypes)
if not self.request.get('zip64'):
self.request.response.setHeader('Content-Type', 'application/zip')
self.request.response.setHeader('Content-disposition', 'attachment;filename=%s.zip' % self.context.getId())
return zipfiles(content, base_path)
return zipfiles(self.contents, self.base_path)
else:
fstream = zipfiles(content, base_path, zip64=True)
fstream = zipfiles(self.contents, self.base_path, zip64=True)
obj_id = f'{self.context.getId()}.zip'
container = plone.api.portal.get()
if obj_id not in container:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "ims.zip"
version = "6.0"
version = "6.1"
requires-python = ">=3.8"
description = "z3c form widgets"
classifiers = [
Expand Down Expand Up @@ -41,4 +41,4 @@ omit = ["venv", "*/test*", "*upgrades.py"]
include = ["ims"]

[tool.flake8]
max-line-length = 120
max-line-length = 120