def patchedTypesInfo(self): """A TALES friendly summary of content types with storage changed to FSS""" out = [] count = -1 for type_class, fields_to_storages in patchedTypesRegistry.items(): count += 1 feature = {'klass': str(type_class)} feature['fields'] = [{'fieldname': fn, 'storage': str(st.__class__)} for fn, st in fields_to_storages.items()] feature['row_css_class'] = ('even', 'odd')[count % 2] out.append(feature) return out
def patchedTypesInfo(self): """A TALES friendly summary of content types with storage changed to FSS""" out = [] count = -1 for type_class, fields_to_storages in patchedTypesRegistry.items(): count += 1 feature = {'klass': str(type_class)} feature['fields'] = [{ 'fieldname': fn, 'storage': str(st.__class__) } for fn, st in fields_to_storages.items()] feature['row_css_class'] = ('even', 'odd')[count % 2] out.append(feature) return out
def migrateToFSS(self): """Do migrations to FSS """ catalog = self.portal.portal_catalog mimetypes_registry = self.portal.mimetypes_registry self.log("Starting migration to FSS") # Looping on relevant content types / fields for content_class, patched_fields in patchedTypesRegistry.items(): meta_type = content_class.meta_type self.log("Migrating %s content types", meta_type) brains = catalog.searchResults(meta_type=meta_type) # Looping on items for brain in brains: brain_path = brain.getPath() try: item = brain.getObject() except Exception, e: LOG_WARNING("Catalog mismatch on %s", brain_path, exc_info=True) continue if item is None: LOG_WARNING("Catalog mismatch on %s", brain_path) continue item_changed = False self.log("Will (try to) migrate fields of %s", brain_path) # Looping on fields for fieldname, former_storage in patched_fields.items(): try: value = former_storage.get(fieldname, item) except AttributeError, e: # Optional empty value -> no migration required continue field = item.getField(fieldname) # Trying to get the mime type try: if hasattr(value, 'content_type'): mimetype = value.content_type else: mimetype = field.getContentType(item) except AttributeError, e: self.log("Can't guess content type of '%s', set to '%s'", brain_path, UNKNOWN_MIMETYPE) mimetype = UNKNOWN_MIMETYPE filename = getattr(value, 'filename', None) or item.getId() if filename and (mimetype == UNKNOWN_MIMETYPE): mti = mimetypes_registry.lookupExtension(filename) if mti and (len(mti.mimetypes) > 0): mimetype = mti.mimetypes[0] if isinstance(value, File): unwrapped_value = value.data else: unwrapped_value = str(value) try: # Making a BaseUnit may fail when AT stupidly tries to # guess the text encoding of a binary file!! data = BaseUnit( fieldname, unwrapped_value, instance=item, filename=filename, mimetype=mimetype, ) except Exception, e: LOG_ERROR("Migrating %s failed on field %s trying to create its BaseUnit", brain_path, fieldname, exc_info=True) continue
def migrateToFSS(self): """Do migrations to FSS """ catalog = self.portal.portal_catalog mimetypes_registry = self.portal.mimetypes_registry self.log("Starting migration to FSS") # Looping on relevant content types / fields for content_class, patched_fields in patchedTypesRegistry.items(): meta_type = content_class.meta_type self.log("Migrating %s content types", meta_type) brains = catalog.searchResults(meta_type=meta_type) # Looping on items for brain in brains: brain_path = brain.getPath() try: item = brain.getObject() except Exception, e: LOG_WARNING("Catalog mismatch on %s", brain_path, exc_info=True) continue if item is None: LOG_WARNING("Catalog mismatch on %s", brain_path) continue item_changed = False self.log("Will (try to) migrate fields of %s", brain_path) # Looping on fields for fieldname, former_storage in patched_fields.items(): try: value = former_storage.get(fieldname, item) except AttributeError, e: # Optional empty value -> no migration required continue field = item.getField(fieldname) # Trying to get the mime type try: if hasattr(value, 'content_type'): mimetype = value.content_type else: mimetype = field.getContentType(item) except AttributeError, e: self.log( "Can't guess content type of '%s', set to '%s'", brain_path, UNKNOWN_MIMETYPE) mimetype = UNKNOWN_MIMETYPE filename = getattr(value, 'filename', None) or item.getId() if filename and (mimetype == UNKNOWN_MIMETYPE): mti = mimetypes_registry.lookupExtension(filename) if mti and (len(mti.mimetypes) > 0): mimetype = mti.mimetypes[0] if isinstance(value, File): unwrapped_value = value.data else: unwrapped_value = str(value) try: # Making a BaseUnit may fail when AT stupidly tries to # guess the text encoding of a binary file!! data = BaseUnit( fieldname, unwrapped_value, instance=item, filename=filename, mimetype=mimetype, ) except Exception, e: LOG_ERROR( "Migrating %s failed on field %s trying to create its BaseUnit", brain_path, fieldname, exc_info=True) continue