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

Fix method to check size of file size in dexterity (thanks @hvelarde)… #11

Open
wants to merge 2 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
9 changes: 7 additions & 2 deletions transmogrify/wordpress/blueprints/fetchattachment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from collective.transmogrifier.interfaces import ISection
from collective.transmogrifier.interfaces import ISectionBlueprint
from plone.dexterity.interfaces import IDexterityContent
from requests.exceptions import ConnectionError
from requests.exceptions import RequestException
from transmogrify.wordpress.logger import logger
Expand Down Expand Up @@ -69,8 +70,12 @@ def __iter__(self):
# content-length header could be missing if remote web
# server is misconfigured for some mime types
size = int(r.headers.get('content-length', 0))
if IDexterityContent.providedBy(obj):
objsize = obj.get_size()
else: # Archetypes
objsize = obj.size()

if size == obj.size(): # already downloaded it
if size == objsize: # already downloaded it
yield item
continue

Expand All @@ -83,7 +88,7 @@ def __iter__(self):

if r.status_code != 200: # log error and skip item
fetch_errors.append(url)
msg = u'Error {0} when fetching {1}'.format(r.status_code, url)
msg = 'Error {0} when fetching {1}'.format(r.status_code, url)
logger.warn(msg)
yield item
continue
Expand Down
8 changes: 7 additions & 1 deletion transmogrify/wordpress/blueprints/moveattachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from collective.transmogrifier.utils import defaultMatcher
from collective.transmogrifier.utils import traverse
from plone import api
from plone.dexterity.interfaces import IDexterityContent
from zope.interface import classProvides
from zope.interface import implements

Expand Down Expand Up @@ -47,7 +48,12 @@ def __iter__(self):
if obj.portal_type not in ('Image', 'File'):
continue

references = obj.getBackReferences()
if IDexterityContent.providedBy(obj):
from Products.Archetypes.interfaces import IReferenceable
adapted = IReferenceable(obj)
references = adapted.getBackReferences()
else: # Archetypes
references = obj.getBackReferences()
if len(references) != 1:
continue

Expand Down
7 changes: 3 additions & 4 deletions transmogrify/wordpress/blueprints/resolveuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from plone.app.linkintegrity.handlers import modifiedDexterity
from plone.app.textfield.value import RichTextValue
from plone.dexterity.interfaces import IDexterityContent
from Products.Archetypes.interfaces import IBaseObject
from transmogrify.wordpress.logger import logger
from transmogrify.wordpress.utils import fix_id
from urlparse import urlparse
Expand Down Expand Up @@ -74,10 +73,10 @@ def __iter__(self):

# XXX: this seems to be very expensive
# Update linkintegrity references
if IBaseObject.providedBy(obj):
modifiedArchetype(obj, event=None)
elif IDexterityContent.providedBy(obj):
if IDexterityContent.providedBy(obj):
modifiedDexterity(obj, event=None)
else: # Archetypes
modifiedArchetype(obj, event=None)

def resolve_uid(self, x):
"""Parse HTML and update with URLs pointing to Plone objects.
Expand Down
5 changes: 4 additions & 1 deletion transmogrify/wordpress/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# -*- coding: utf-8 -*-
from HTMLParser import HTMLParser
from plone.i18n.normalizer.interfaces import IIDNormalizer
from Products.CMFPlone.utils import safe_unicode
from urllib import unquote_plus
from zope.component import getUtility


class MLStripper(HTMLParser):
Expand Down Expand Up @@ -33,5 +35,6 @@ def fix_id(item_id):
"""Unquote plus and remove accents from ids."""
item_id = unquote_plus(item_id)
item_id = safe_unicode(item_id)
item_id = item_id.encode('ascii', 'ignore')
id_normalizer = getUtility(IIDNormalizer)
item_id = id_normalizer.normalize(item_id)
return item_id