Skip to content

Commit

Permalink
Merge pull request #1586 from UlrichB22/missing_macro
Browse files Browse the repository at this point in the history
import19: check for unknown macros
  • Loading branch information
RogerHaase authored Feb 3, 2024
2 parents a02dadc + 6ae6848 commit 678b04d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/moin/cli/migration/moin19/import19.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def migr_logging(msg_id, log_msg):
logging.debug(log_msg)


def migr_statistics():
def migr_statistics(unknown_macros):
logging.info("Migration statistics:")
logging.info("Users: {0:6d}".format(migr_stat['users']))
logging.info("Items: {0:6d}".format(migr_stat['items']))
Expand All @@ -116,6 +116,9 @@ def migr_statistics():
if migr_stat[message] > 0:
logging.info("Warnings: {0:6d} - {1}".format(migr_stat[message], message))

if len(unknown_macros) > 0:
logging.info("Warnings: {0:6d} - unknown macros {1}".format(len(unknown_macros), str(unknown_macros)[1:-1]))


@cli.command('import19', help='Import content and user data from a moin 1.9 wiki')
@click.option('--data_dir', '-d', type=str, required=True,
Expand Down Expand Up @@ -233,7 +236,10 @@ def ImportMoin19(data_dir=None, markup_out=None):
indexer.open()

logging.info("Finished conversion!")
migr_statistics()
if hasattr(conv_out, 'unknown_macro_list'):
migr_statistics(unknown_macros=conv_out.unknown_macro_list)
else:
migr_statistics([])


class KillRequested(Exception):
Expand Down
10 changes: 10 additions & 0 deletions src/moin/converters/moinwiki_out.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright: 2008 MoinMoin:BastianBlank
# Copyright: 2010 MoinMoin:DmitryAndreev
# Copyright: 2024 MoinMoin:UlrichB
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.

"""
Expand All @@ -20,9 +21,13 @@
from moin.utils.iri import Iri
from moin.utils.mime import Type, type_moin_document, type_moin_wiki

from moin.macros import modules as macro_modules
from . import ElementException
from . import default_registry

from moin import log
logging = log.getLogger(__name__)


class Moinwiki:
"""
Expand Down Expand Up @@ -129,6 +134,7 @@ def __init__(self):
self.list_item_labels = ['', ]
self.list_item_label = ''
self.list_level = 0
self.unknown_macro_list = []

# 'text' - default status - <p> = '/n' and </p> = '/n'
# 'table' - text inside table - <p> = '<<BR>>' and </p> = ''
Expand Down Expand Up @@ -495,6 +501,10 @@ def open_moinpage_part(self, elem):
if len(type) == 2:
if type[0] == "x-moin/macro":
name = type[1].split('=')[1]
if name not in macro_modules:
logging.debug("Unknown macro {} found.".format(name))
if name not in self.unknown_macro_list:
self.unknown_macro_list.append(name)
eol = '\n\n' if elem.tag.name == 'part' else ''
if len(elem) and elem[0].tag.name == "arguments":
return "{0}<<{1}({2})>>{0}".format(
Expand Down

0 comments on commit 678b04d

Please sign in to comment.