Пример #1
0
    def __call__(self, batch=1000, dryrun=False):
        """ find all btree-based folder below the context, potentially
            migrate them & provide some logging and statistics doing so """
        log = self.mklog()
        log('migrating btree-based folders from %r:' % self.context)
        real = timer()  # real time
        lap = timer()  # real lap time (for intermediate commits)
        cpu = timer(clock)  # cpu time
        processed = 0

        def checkPoint():
            msg = 'intermediate commit '\
                  '(%d objects processed, last batch in %s)...'
            log(msg % (processed, next(lap)))
            trx = get()
            trx.note(u'migrated %d btree-folders' % processed)
            trx.savepoint()

        cpi = checkpointIterator(checkPoint, batch)
        for path, obj in findObjects(self.context):
            if isinstance(obj, BTreeFolder):
                if self.migrate(obj):
                    processed += 1
                    next(cpi)
            self.postprocess(obj)

        checkPoint()  # commit last batch
        if dryrun:
            get().abort()  # abort on test-run...
        msg = 'processed %d object(s) in %s (%s cpu time).'
        msg = msg % (processed, next(real), next(cpu))
        log(msg)
        logger.info(msg)
Пример #2
0
    def __call__(self, batch=1000, dryrun=False):
        """ find all btree-based folder below the context, potentially
            migrate them & provide some logging and statistics doing so """
        log = self.mklog()
        log('migrating btree-based folders from %r:' % self.context)
        real = timer()          # real time
        lap = timer()           # real lap time (for intermediate commits)
        cpu = timer(clock)      # cpu time
        processed = 0

        def checkPoint():
            msg = 'intermediate commit '\
                  '(%d objects processed, last batch in %s)...'
            log(msg % (processed, next(lap)))
            trx = get()
            trx.note(u'migrated %d btree-folders' % processed)
            trx.savepoint()
        cpi = checkpointIterator(checkPoint, batch)
        for path, obj in findObjects(self.context):
            if isinstance(obj, BTreeFolder):
                if self.migrate(obj):
                    processed += 1
                    next(cpi)
            self.postprocess(obj)

        checkPoint()                # commit last batch
        if dryrun:
            get().abort()           # abort on test-run...
        msg = 'processed %d object(s) in %s (%s cpu time).'
        msg = msg % (processed, next(real), next(cpu))
        log(msg)
        logger.info(msg)
Пример #3
0
def reverseMigrate(folder):
    """ helper to replace the given regular folder with one based on
        btrees;  the intention is to create the state that would be found
        before migration, i.e. a now btree-based folder still holding the
        data structures from a regular one;  all (regular) subfolders
        will be replaced recursively """
    for name, obj in reversed(list(findObjects(folder))):
        if isinstance(obj, NonBTreeFolder):
            parent = aq_parent(obj)
            data = obj.__dict__.copy()
            data['id'] = oid = obj.getId()
            new = OrderableFolder(oid)
            new.__dict__ = data
            setattr(parent, oid, new)
Пример #4
0
def reverseMigrate(folder):
    """ helper to replace the given regular folder with one based on
        btrees;  the intention is to create the state that would be found
        before migration, i.e. a now btree-based folder still holding the
        data structures from a regular one;  all (regular) subfolders
        will be replaced recursively """
    for name, obj in reversed(list(findObjects(folder))):
        if isinstance(obj, NonBTreeFolder):
            parent = aq_parent(obj)
            data = obj.__dict__.copy()
            data['id'] = oid = obj.getId()
            new = OrderableFolder(oid)
            new.__dict__ = data
            setattr(parent, oid, new)
Пример #5
0
    def __call__(self):
        """ Explore the site's content and place it on the right RLF
        """
        context = aq_inner(self.context)
        pl = getToolByName(context, "portal_languages")
        pu = getToolByName(context, "portal_url")
        portal = pu.getPortalObject()
        supported_langs = pl.getSupportedLanguages()

        output = []
        for path, obj in findObjects(portal):
            try:
                lang_adptr = ILanguage(obj)
            except:
                info_str = "Found object %s with no language support." % (path)
                logger.info(info_str)
                output.append(info_str)
                continue

            obj_lang = lang_adptr.get_language()
            if obj_lang not in supported_langs:
                info_str = "Found object %s with unsupported language %s." % (
                    path, obj_lang)
                logger.info(info_str)
                output.append(info_str)
            else:
                target_folder = ITranslationLocator(obj)(obj_lang)
                parent = aq_parent(obj)
                if IPloneSiteRoot.providedBy(parent) \
                   and ITranslatable.providedBy(obj) \
                   and not INavigationRoot.providedBy(obj):
                    target_folder = getattr(portal, obj_lang, None)

                if target_folder != parent:
                    cb_copy_data = parent.manage_cutObjects(obj.getId())
                    list_ids = target_folder.manage_pasteObjects(cb_copy_data)
                    new_id = list_ids[0]['new_id']
                    new_object = target_folder[new_id]
                    info_str = "Moved object %s to lang folder %s" % (
                        parent.getPhysicalPath(), obj_lang)
                    logger.info(info_str)
                    output.append(new_object.id)

        return output
Пример #6
0
    def __call__(self):
        """ Explore the site's content and place it on the right RLF
        """
        context = aq_inner(self.context)
        pl = getToolByName(context, "portal_languages")
        pu = getToolByName(context, "portal_url")
        portal = pu.getPortalObject()
        supported_langs = pl.getSupportedLanguages()

        output = []
        for path, obj in findObjects(portal):
            try:
                lang_adptr = ILanguage(obj)
            except:
                info_str = "Found object %s with no language support." % (path)
                logger.info(info_str)
                output.append(info_str)
                continue

            obj_lang = lang_adptr.get_language()
            if obj_lang not in supported_langs:
                info_str = "Found object %s with unsupported language %s." % (
                                            path, obj_lang)
                logger.info(info_str)
                output.append(info_str)
            else:
                target_folder = ITranslationLocator(obj)(obj_lang)
                parent = aq_parent(obj)
                if IPloneSiteRoot.providedBy(parent) \
                   and ITranslatable.providedBy(obj) \
                   and not INavigationRoot.providedBy(obj):
                    target_folder = getattr(portal, obj_lang, None)

                if target_folder != parent:
                    cb_copy_data = parent.manage_cutObjects(obj.getId())
                    list_ids = target_folder.manage_pasteObjects(cb_copy_data)
                    new_id = list_ids[0]['new_id']
                    new_object = target_folder[new_id]
                    info_str = "Moved object %s to lang folder %s" % (
                                            parent.getPhysicalPath(), obj_lang)
                    logger.info(info_str)
                    output.append(new_object.id)

        return output
Пример #7
0
 def testFindObjects(self):
     found = list(findObjects(self.portal))
     # the starting point itself is returned
     self.assertEqual(found[0], ('', self.portal))
     # but the rest should be the same...
     self.assertEqual(self.ids(found[1:]), self.good)
Пример #8
0
 def testFindObjects(self):
     found = list(findObjects(self.portal))
     # the starting point itself is returned
     self.assertEqual(found[0], ('', self.portal))
     # but the rest should be the same...
     self.assertEqual(self.ids(found[1:]), self.good)
Пример #9
0
 def stealLocks(self, seccio):
     for path, obj in findObjects(seccio):
         lockable = ILockable(obj)
         if lockable.locked():
             lockable.unlock()
             self.logger.error("Unlocking object %s." % obj)
Пример #10
0
 def stealLocks(self, seccio):
     for path, obj in findObjects(seccio):
         lockable = ILockable(obj)
         if lockable.locked():
             lockable.unlock()
             self.logger.error("Unlocking object %s." % obj)