From c0ac02bbd03542202451717ebfc9992cc1197f12 Mon Sep 17 00:00:00 2001 From: maartenkling Date: Mon, 27 Aug 2012 13:55:46 +0200 Subject: [PATCH 1/3] make available to import to dexterityblob types to! --- .../blueprint/jsonmigrator/blueprint.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/collective/blueprint/jsonmigrator/blueprint.py b/collective/blueprint/jsonmigrator/blueprint.py index 19fe7fc..320b432 100644 --- a/collective/blueprint/jsonmigrator/blueprint.py +++ b/collective/blueprint/jsonmigrator/blueprint.py @@ -23,6 +23,16 @@ from Products.Archetypes.interfaces import IBaseObject from AccessControl.interfaces import IRoleManager +from plone.dexterity.utils import iterSchemata +from zope.schema import getFieldsInOrder + +try: + from plone.dexterity.interfaces import IDexterityContent + dexterity_available = True +except: + dexterity_available = False + + DATAFIELD = '_datafield_' STATISTICSFIELD = '_statistics_field_prefix_' @@ -512,6 +522,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue + # AT if IBaseObject.providedBy(obj): for key in item.keys(): if not key.startswith(self.datafield_prefix): @@ -527,4 +538,34 @@ def __iter__(self): if len(value) != len(field.get(obj)): field.set(obj, value) + # dexterity + if dexterity_available and IDexterityContent.providedBy(obj): + for key in item.keys(): + if not key.startswith(self.datafield_prefix): + continue + if not os.path.exists(item[key]): + continue + + fieldname = key[len(self.datafield_prefix):] + f = open(item[key]) + value = f.read() + f.close() + + filename = item['id'].decode('utf-8') + contenttype = '' + + #get all fields for this obj + for schemata in iterSchemata(obj): + for name, field in getFieldsInOrder(schemata): + if field.__name__ == fieldname: + # create a blob instance + instance = field._type( + data=value, + filename=filename, + contentType=contenttype, + ) + # set it + field.set(field.interface(obj), instance) + continue + yield item From 82573454c63b26e54806a39a60f72f9a9f82af3e Mon Sep 17 00:00:00 2001 From: maartenkling Date: Thu, 13 Sep 2012 13:29:51 +0200 Subject: [PATCH 2/3] for dexterity to --- collective/blueprint/jsonmigrator/blueprint.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/collective/blueprint/jsonmigrator/blueprint.py b/collective/blueprint/jsonmigrator/blueprint.py index 320b432..4cddaf9 100644 --- a/collective/blueprint/jsonmigrator/blueprint.py +++ b/collective/blueprint/jsonmigrator/blueprint.py @@ -211,7 +211,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): obj.setFormat(item[mimetypekey]) yield item @@ -257,7 +257,7 @@ def __iter__(self): if obj is None or not getattr(obj, 'workflow_history', False): yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): item_tmp = item # get back datetime stamp and set the workflow history @@ -313,7 +313,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): if getattr(aq_base(obj), '_delProperty', False): for prop in item[propertieskey]: if getattr(aq_base(obj), prop[0], None) is not None: @@ -372,7 +372,7 @@ def __iter__(self): if obj is None: # path doesn't exist yield item; continue - if IBaseObject.providedBy(obj): + if IBaseObject.providedBy(obj) or (dexterity_available and IDexterityContent.providedBy(obj)): if item[ownerkey][0] and item[ownerkey][1]: try: @@ -390,7 +390,6 @@ def __iter__(self): obj._owner = item[ownerkey][1] except Exception, e: raise Exception('ERROR: %s SETTING __OWNERSHIP TO %s' % (str(e), item[pathkey])) - yield item From 14c7f509352a5938f4b60a141958005c16cdf756 Mon Sep 17 00:00:00 2001 From: maartenkling Date: Wed, 24 Jul 2013 15:41:31 +0200 Subject: [PATCH 3/3] always cast to int --- collective/blueprint/jsonmigrator/blueprint.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collective/blueprint/jsonmigrator/blueprint.py b/collective/blueprint/jsonmigrator/blueprint.py index 4cddaf9..0667109 100644 --- a/collective/blueprint/jsonmigrator/blueprint.py +++ b/collective/blueprint/jsonmigrator/blueprint.py @@ -121,7 +121,7 @@ class Statistics(object): def __init__(self, transmogrifier, name, options, previous): self.stats = {'START_TIME': int(time.time()), 'TIME_LAST_STEP': 0, - 'STEP': options.get('log-step', 25), + 'STEP': int(options.get('log-step', 25)), 'OBJ_COUNT': 0, 'EXISTED': 0, 'ADDED': 0,