Skip to content

Commit

Permalink
Update code to follow Plone styleguide
Browse files Browse the repository at this point in the history
  • Loading branch information
gforcada committed Oct 30, 2016
1 parent ce1285f commit 1a20d2a
Show file tree
Hide file tree
Showing 44 changed files with 586 additions and 417 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Expand Up @@ -20,6 +20,8 @@ Bug fixes:
- More flexible test of getIcon.
[jensens]

- Update code to follow Plone styleguide.
[gforcada]

1.6.4 (2016-08-12)
------------------
Expand Down
1 change: 1 addition & 0 deletions setup.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
from setuptools import find_packages
from setuptools import setup

import os


Expand Down
13 changes: 8 additions & 5 deletions src/plone/app/blob/__init__.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from plone.app.blob.config import packageName, permissions
from plone.app.blob.config import packageName
from plone.app.blob.config import permissions


def initialize(context):
Expand All @@ -20,19 +21,21 @@ def initialize(context):
content_types, constructors, ftis = atapi.process_types(
atapi.listTypes(packageName), packageName)
for atype, constructor in zip(content_types, constructors):
utils.ContentInit("%s: %s" % (packageName, atype.portal_type),
utils.ContentInit(
'{0}: {1}'.format(packageName, atype.portal_type),
content_types=(atype, ),
permission=permissions[atype.portal_type],
extra_constructors=(constructor, ),
).initialize(context)
).initialize(context)

replacement_types = (
('File', content.addATBlobFile),
('Image', content.addATBlobImage),
)
for name, constructor in replacement_types:
utils.ContentInit("%s: %s" % (packageName, name),
utils.ContentInit(
'{0}: {1}'.format(packageName, name),
content_types=(content.ATBlob, ),
permission=atct.permissions.get(name),
extra_constructors=(constructor, ),
).initialize(context)
).initialize(context)
9 changes: 4 additions & 5 deletions src/plone/app/blob/adapters/atfile.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from Products.ATContentTypes.interface import IATFile
from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.adapters.ofsfile import BlobbableOFSFile
from plone.app.blob.interfaces import IBlobbable
from Products.ATContentTypes.interface import IATFile
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
5 changes: 2 additions & 3 deletions src/plone/app/blob/adapters/atimage.py
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from zope.component import adapts

from Products.ATContentTypes.interface import IATImage
from plone.app.blob.adapters.atfile import BlobbableATFile
from Products.ATContentTypes.interface import IATImage
from zope.component import adapts


class BlobbableATImage(BlobbableATFile):
Expand Down
8 changes: 4 additions & 4 deletions src/plone/app/blob/adapters/blobwrapper.py
@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from plone.app.blob.interfaces import IBlobbable, IBlobWrapper
from plone.app.blob.field import ReuseBlob
from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.interfaces import IBlobWrapper
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
5 changes: 2 additions & 3 deletions src/plone/app/blob/adapters/file.py
@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.utils import guessMimetype
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
16 changes: 7 additions & 9 deletions src/plone/app/blob/adapters/fileupload.py
@@ -1,16 +1,14 @@
# -*- coding: utf-8 -*-
from os.path import isfile
from shutil import copyfileobj
from os import name as os_name

from zope.interface import implementer
from zope.component import adapts
from ZODB.blob import Blob

from os.path import isfile
from plone.app.blob.field import ReuseBlob
from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.interfaces import IFileUpload
from plone.app.blob.utils import guessMimetype
from plone.app.blob.field import ReuseBlob
from shutil import copyfileobj
from ZODB.blob import Blob
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand All @@ -36,7 +34,7 @@ def feed(self, blob):
copyfileobj(self.context, blobfile)
blobfile.close()
elif filename is not None:
assert isfile(filename), 'invalid file for blob: %s' % filename
assert isfile(filename), 'invalid file for blob: {0}'.format(filename) # noqa
blob.consumeFile(filename)
else: # the cgi module only creates a tempfile for 1000+ bytes
self.context.seek(0) # just to be sure we copy everything...
Expand Down
6 changes: 3 additions & 3 deletions src/plone/app/blob/adapters/ofsfile.py
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.interfaces import IOFSFile
from zope.component import adapts

from plone.app.blob.interfaces import IBlobbable, IOFSFile
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
8 changes: 3 additions & 5 deletions src/plone/app/blob/adapters/pdata.py
@@ -1,12 +1,10 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from OFS.Image import Pdata
from StringIO import StringIO

from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.utils import guessMimetype
from StringIO import StringIO
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
8 changes: 3 additions & 5 deletions src/plone/app/blob/adapters/stringio.py
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from StringIO import StringIO

from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.utils import guessMimetype
from StringIO import StringIO
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
5 changes: 2 additions & 3 deletions src/plone/app/blob/adapters/webdav.py
@@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.interfaces import IWebDavUpload
from plone.app.blob.utils import guessMimetype
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
8 changes: 3 additions & 5 deletions src/plone/app/blob/adapters/xmlrpc.py
@@ -1,11 +1,9 @@
# -*- coding: utf-8 -*-
from zope.interface import implementer
from zope.component import adapts

from xmlrpclib import Binary

from plone.app.blob.interfaces import IBlobbable
from plone.app.blob.utils import guessMimetype
from xmlrpclib import Binary
from zope.component import adapts
from zope.interface import implementer


@implementer(IBlobbable)
Expand Down
30 changes: 15 additions & 15 deletions src/plone/app/blob/browser/maintenance.py
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from logging import getLogger
from time import time, strftime
from transaction import commit
from Acquisition import aq_inner
from Products.Five.browser import BrowserView
from Products.CMFCore.utils import getToolByName

from logging import getLogger
from plone.app.blob.interfaces import IATBlob
from plone.app.blob.markings import markAs
from Products.CMFCore.utils import getToolByName
from Products.Five.browser import BrowserView
from time import strftime
from time import time
from transaction import commit


def timer(func=time):
Expand All @@ -17,7 +17,7 @@ def gen(last=func()):
while True:
elapsed = func() - last
last = func()
yield '%.3fs' % elapsed
yield '{0:.4}s'.format(elapsed)
return gen()


Expand Down Expand Up @@ -53,8 +53,8 @@ def resetSubtypes(self, batch=1000):
processed = 0

def checkPoint():
log('intermediate commit (%d items processed, '
'last batch in %s)...\n' % (processed, lap.next()))
log('intermediate commit ({0} items processed, '
'last batch in {1})...\n'.format(processed, lap.next()))
commit()
cpi = checkpointIterator(checkPoint, batch)
context = aq_inner(self.context)
Expand All @@ -64,11 +64,11 @@ def checkPoint():
subtype = brain.portal_type
markAs(obj, subtype)
obj.reindexObject(idxs=['object_provides'])
log('set blob sub-type for %r to "%s"\n' % (obj, subtype))
log('set blob sub-type for {0} to "{1}"\n'.format(obj, subtype))
processed += 1
cpi.next()
commit()
msg = 'processed %d items in %s.' % (processed, real.next())
msg = 'processed {0} items in {1}.'.format(processed, real.next())
log(msg)
getLogger('plone.app.blob.maintenance').info(msg)

Expand All @@ -81,19 +81,19 @@ def updateTypeIndex(self, batch=1000):
processed = 0

def checkPoint():
log('intermediate commit (%d items processed, '
'last batch in %s)...\n' % (processed, lap.next()))
log('intermediate commit ({0} items processed, '
'last batch in {1})...\n'.format(processed, lap.next()))
commit()
cpi = checkpointIterator(checkPoint, batch)
context = aq_inner(self.context)
catalog = getToolByName(context, 'portal_catalog')
for brain in catalog(object_provides=IATBlob.__identifier__):
obj = brain.getObject()
obj.reindexObject(idxs=['Type'])
log('updated %r\n' % obj)
log('updated {0}\n'.format(obj))
processed += 1
cpi.next()
commit()
msg = 'processed %d items in %s.' % (processed, real.next())
msg = 'processed {0} items in {1}.'.format(processed, real.next())
log(msg)
getLogger('plone.app.blob.maintenance').info(msg)
31 changes: 18 additions & 13 deletions src/plone/app/blob/browser/migration.py
@@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from plone.app.blob.migrations import getATBlobFilesMigrationWalker
from plone.app.blob.migrations import getATBlobImagesMigrationWalker
from plone.app.blob.migrations import getATFilesMigrationWalker
from plone.app.blob.migrations import haveContentMigrations
from plone.app.blob.migrations import migrateATBlobFiles
from plone.app.blob.migrations import migrateATBlobImages
from plone.app.blob.migrations import migrateATFiles
from Products.CMFCore.utils import getToolByName
from Products.CMFPlone import PloneMessageFactory as _
from Products.Five import BrowserView
from Products.statusmessages.interfaces import IStatusMessage

from plone.app.blob.migrations import haveContentMigrations
from plone.app.blob.migrations import migrateATFiles
from plone.app.blob.migrations import getATFilesMigrationWalker
from plone.app.blob.migrations import migrateATBlobFiles
from plone.app.blob.migrations import getATBlobFilesMigrationWalker
from plone.app.blob.migrations import migrateATBlobImages
from plone.app.blob.migrations import getATBlobImagesMigrationWalker


class BlobMigrationView(BrowserView):

Expand All @@ -29,13 +28,19 @@ def __call__(self):
ttool = getToolByName(context, 'portal_types')
fti = ttool.get(walker.dst_portal_type)
if fti and fti.product != 'plone.app.blob':
url = '%s/prefs_install_products_form' % portal_url
msg = _(u'Please install `plone.app.blob` to be able to migrate to blobs.')
url = '{0}/prefs_install_products_form'.format(portal_url)
msg = _(
u'Please install `plone.app.blob` to be able to migrate to '
u'blobs.'
)
IStatusMessage(request).addStatusMessage(msg, type='warning')
options['notinstalled'] = 42
options['installer'] = url
elif not haveContentMigrations:
msg = _(u'Please install contentmigrations to be able to migrate to blobs.')
msg = _(
u'Please install contentmigrations to be able to migrate to '
u'blobs.'
)
IStatusMessage(request).addStatusMessage(msg, type='warning')
options['nomigrations'] = 42
elif clicked('migrate'):
Expand All @@ -44,8 +49,8 @@ def __call__(self):
lines = output.split('\n')
count = len([l for l in lines if l.startswith('Migrating')])
msg = _(u'blob_migration_info',
default=u'Blob migration performed for ${count} item(s).',
mapping={'count': count})
default=u'Blob migration performed for ${count} item(s).',
mapping={'count': count})
IStatusMessage(request).addStatusMessage(msg, type='info')
options['count'] = count
options['output'] = output
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/blob/browser/size.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from Acquisition import aq_inner
from Products.Five import BrowserView
from Products.CMFCore.utils import getToolByName
from Products.Five import BrowserView


def bytesize(size):
Expand Down

0 comments on commit 1a20d2a

Please sign in to comment.