Skip to content

Commit 678b04d

Browse files
authored
Merge pull request #1586 from UlrichB22/missing_macro
import19: check for unknown macros
2 parents a02dadc + 6ae6848 commit 678b04d

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/moin/cli/migration/moin19/import19.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def migr_logging(msg_id, log_msg):
105105
logging.debug(log_msg)
106106

107107

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

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

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

235238
logging.info("Finished conversion!")
236-
migr_statistics()
239+
if hasattr(conv_out, 'unknown_macro_list'):
240+
migr_statistics(unknown_macros=conv_out.unknown_macro_list)
241+
else:
242+
migr_statistics([])
237243

238244

239245
class KillRequested(Exception):

src/moin/converters/moinwiki_out.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright: 2008 MoinMoin:BastianBlank
22
# Copyright: 2010 MoinMoin:DmitryAndreev
3+
# Copyright: 2024 MoinMoin:UlrichB
34
# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
45

56
"""
@@ -20,9 +21,13 @@
2021
from moin.utils.iri import Iri
2122
from moin.utils.mime import Type, type_moin_document, type_moin_wiki
2223

24+
from moin.macros import modules as macro_modules
2325
from . import ElementException
2426
from . import default_registry
2527

28+
from moin import log
29+
logging = log.getLogger(__name__)
30+
2631

2732
class Moinwiki:
2833
"""
@@ -129,6 +134,7 @@ def __init__(self):
129134
self.list_item_labels = ['', ]
130135
self.list_item_label = ''
131136
self.list_level = 0
137+
self.unknown_macro_list = []
132138

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

0 commit comments

Comments
 (0)