Example #1
0
 def setup_class(self):
     self.conv_in = conv_in()
     self.conv_out = conv_out()
Example #2
0
    def run(self, data_dir=None):
        flaskg.add_lineno_attr = False
        flaskg.item_name2id = {}
        userid_old2new = {}
        indexer = app.storage
        backend = indexer.backend  # backend without indexing

        print "\nConverting Users...\n"
        for rev in UserBackend(os.path.join(
                data_dir, 'user')):  # assumes user/ below data_dir
            global user_names
            user_names.append(rev.meta['name'][0])
            userid_old2new[rev.uid] = rev.meta[
                'itemid']  # map old userid to new userid
            backend.store(rev.meta, rev.data)

        print "\nConverting Pages/Attachments...\n"
        for rev in PageBackend(data_dir,
                               deleted_mode=DELETED_MODE_KILL,
                               default_markup=u'wiki'):
            for user_name in user_names:
                if rev.meta['name'][0] == user_name or rev.meta['name'][
                        0].startswith(user_name + '/'):
                    rev.meta['namespace'] = u'users'
                    break
            backend.store(rev.meta, rev.data)
            # item_name to itemid xref required for migrating user subscriptions
            flaskg.item_name2id[rev.meta['name'][0]] = rev.meta['itemid']

        print "\nConverting Revision Editors...\n"
        for mountpoint, revid in backend:
            meta, data = backend.retrieve(mountpoint, revid)
            if USERID in meta:
                try:
                    meta[USERID] = userid_old2new[meta[USERID]]
                except KeyError:
                    # user profile lost, but userid referred by revision
                    print(u"Missing userid {0!r}, editor of {1} revision {2}".
                          format(meta[USERID], meta[NAME][0],
                                 revid)).encode('utf-8')
                    del meta[USERID]
                backend.store(meta, data)
            elif meta.get(CONTENTTYPE) == CONTENTTYPE_USER:
                meta.pop(UID_OLD, None)  # not needed any more
                backend.store(meta, data)

        print "\nConverting last revision of Moin 1.9 items to Moin 2.0"
        self.conv_in = conv_in()
        self.conv_out = conv_out()
        for item_name, (revno, namespace) in sorted(last_moin19_rev.items()):
            print '    Processing item "{0}", namespace "{1}", revision "{2}"'.format(
                item_name, namespace, revno)
            if namespace == u'':
                namespace = u'default'
            meta, data = backend.retrieve(namespace, revno)
            data_in = ''.join(data.readlines())
            dom = self.conv_in(data_in,
                               'text/x.moin.wiki;format=1.9;charset=utf-8')
            out = self.conv_out(dom)
            out = out.encode(CHARSET)
            size, hash_name, hash_digest = hash_hexdigest(out)
            out = StringIO(out)
            meta[hash_name] = hash_digest
            meta[SIZE] = size
            meta[REVID] = make_uuid()
            meta[REV_NUMBER] = meta[REV_NUMBER] + 1
            meta[MTIME] = int(time.time())
            meta[COMMENT] = 'Convert moin 1.9 markup to 2.0'
            meta[CONTENTTYPE] = 'text/x.moin.wiki;charset=utf-8'
            del meta['dataid']
            out.seek(0)
            backend.store(meta, out)

        print "\nRebuilding the index..."
        indexer.close()
        indexer.destroy()
        indexer.create()
        indexer.rebuild()
        indexer.open()

        print "Finished conversion!"