Пример #1
0
 def setup_class(self):
     self.conv_in = conv_in()
     self.conv_out = conv_out()
Пример #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='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'] = '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(("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()
        reg = default_registry
        refs_conv = reg.get(type_moin_document, type_moin_document, items='refs')
        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 == '':
                namespace = '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)
            iri = Iri(scheme='wiki', authority='', path='/' + item_name)
            dom.set(moin_page.page_href, str(iri))
            refs_conv(dom)
            meta[ITEMLINKS] = refs_conv.get_links()
            meta[ITEMTRANSCLUSIONS] = refs_conv.get_transclusions()
            meta[EXTERNALLINKS] = refs_conv.get_external_links()
            size, hash_name, hash_digest = hash_hexdigest(out)
            out = BytesIO(out)
            meta[hash_name] = hash_digest
            meta[SIZE] = size
            meta[PARENTID] = meta[REVID]
            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!")
Пример #3
0
    def run(self, data_dir=None, markup_out=None):
        flaskg.add_lineno_attr = False
        flaskg.item_name2id = {}
        userid_old2new = {}
        indexer = app.storage
        backend = indexer.backend  # backend without indexing
        global custom_namespaces
        custom_namespaces = namespaces()

        print("\nConverting Users...\n")
        user_dir = os.path.join(data_dir, 'user')
        if os.path.isdir(user_dir):
            for rev in UserBackend(user_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 and Attachments...\n")
        for rev in PageBackend(data_dir,
                               deleted_mode=DELETED_MODE_KILL,
                               default_markup='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'] = 'users'
                    break

            if USERID in rev.meta:
                try:
                    rev.meta[USERID] = userid_old2new[rev.meta[USERID]]
                except KeyError:
                    # user profile lost, but userid referred by revision
                    print("Missing userid {0!r}, editor of {1} revision {2}".
                          format(rev.meta[USERID], rev.meta[NAME][0],
                                 rev.meta[REVID]))
                    del rev.meta[USERID]
            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 last revision of Moin 1.9 items to Moin 2.0")
        self.conv_in = conv_in()
        self.markup_out = markup_out
        conv_out = importlib.import_module("moin.converters." +
                                           self.markup_out + "_out")
        self.conv_out = conv_out.Converter()
        reg = default_registry
        refs_conv = reg.get(type_moin_document,
                            type_moin_document,
                            items='refs')
        for item_name, (revno, namespace) in sorted(last_moin19_rev.items()):
            try:
                print(
                    '    Processing item "{0}", namespace "{1}", revision "{2}"'
                    .format(item_name, namespace, revno))
            except UnicodeEncodeError:
                print(
                    '    Processing item "{0}", namespace "{1}", revision "{2}"'
                    .format(item_name.encode('ascii', errors='replace'),
                            namespace, revno))
            if namespace == '':
                namespace = 'default'
            meta, data = backend.retrieve(namespace, revno)
            data_in = data.read().decode(CHARSET19)
            dom = self.conv_in(data_in, CONTENTTYPE_MOINWIKI)

            # migrate macros that need update from 1.9 to 2.0
            migrate_macros(dom)  # in-place conversion

            out = self.conv_out(dom)
            out = out.encode(CHARSET19)
            iri = Iri(scheme='wiki', authority='', path='/' + item_name)
            dom.set(moin_page.page_href, str(iri))
            refs_conv(dom)
            meta[ITEMLINKS] = refs_conv.get_links()
            meta[ITEMTRANSCLUSIONS] = refs_conv.get_transclusions()
            meta[EXTERNALLINKS] = refs_conv.get_external_links()
            size, hash_name, hash_digest = hash_hexdigest(out)
            out = BytesIO(out)
            meta[hash_name] = hash_digest
            meta[SIZE] = size
            meta[PARENTID] = meta[REVID]
            meta[REVID] = make_uuid()
            meta[REV_NUMBER] = meta[REV_NUMBER] + 1
            # bumping modified time makes global and item history views more useful
            meta[MTIME] = meta[MTIME] + 1
            meta[
                COMMENT] = 'Converted moin 1.9 markup to ' + self.markup_out + ' markup'
            meta[CONTENTTYPE] = CONTENTTYPE_MARKUP_OUT[self.markup_out]
            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!")