slight changes, huge debug output trying to find why some conversions are not applied to some fields
This commit is contained in:
parent
2ba94d03a8
commit
dd370eb175
@ -52,7 +52,7 @@ def main(*argv):
|
|||||||
if len(argv) == 0:
|
if len(argv) == 0:
|
||||||
argv = sys.argv
|
argv = sys.argv
|
||||||
|
|
||||||
# TODO Define max nb of sections to export based on first CLI argument
|
# TODO Define max nb of sections/articles to export based on first CLI argument
|
||||||
# if len(argv) >= 2:
|
# if len(argv) >= 2:
|
||||||
# sections_export = int(argv[1])
|
# sections_export = int(argv[1])
|
||||||
# else:
|
# else:
|
||||||
|
@ -26,7 +26,7 @@ class Configuration:
|
|||||||
prepend_h1: bool = True
|
prepend_h1: bool = True
|
||||||
export_filetype: str = "md"
|
export_filetype: str = "md"
|
||||||
logfile: str = "spip2md.log"
|
logfile: str = "spip2md.log"
|
||||||
loglevel: str = "INFO"
|
loglevel: str = "WARNING"
|
||||||
# max_articles_export: int = 1000 # TODO reimplement with recursion
|
# max_articles_export: int = 1000 # TODO reimplement with recursion
|
||||||
# max_sections_export: int = 500 # TODO reimplement with recursion
|
# max_sections_export: int = 500 # TODO reimplement with recursion
|
||||||
|
|
||||||
|
@ -82,6 +82,7 @@ class SpipWritable:
|
|||||||
return char
|
return char
|
||||||
|
|
||||||
if text is not None and len(text) > 0:
|
if text is not None and len(text) > 0:
|
||||||
|
print(f"Converting {text[:40]} from {self.titre}")
|
||||||
# Convert SPIP syntax to Markdown
|
# Convert SPIP syntax to Markdown
|
||||||
for spip, markdown in SPIP_MARKDOWN:
|
for spip, markdown in SPIP_MARKDOWN:
|
||||||
text = spip.sub(markdown, text)
|
text = spip.sub(markdown, text)
|
||||||
@ -106,13 +107,16 @@ class SpipWritable:
|
|||||||
)
|
)
|
||||||
lastend = match.end()
|
lastend = match.end()
|
||||||
else:
|
else:
|
||||||
|
print("Empty or null text")
|
||||||
return ""
|
return ""
|
||||||
return text
|
return text
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.titre = self.convert(self.titre)
|
print(f"Convert titre from {self.titre}")
|
||||||
self.descriptif = self.convert(self.descriptif)
|
self.titre: str = self.convert(self.titre)
|
||||||
|
print(f"Convert descriptif from {self.titre}")
|
||||||
|
self.descriptif: str = self.convert(self.descriptif)
|
||||||
|
|
||||||
def filename(self, date: bool = False) -> str:
|
def filename(self, date: bool = False) -> str:
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
@ -161,7 +165,7 @@ class SpipWritable:
|
|||||||
# Output information about file that was just exported
|
# Output information about file that was just exported
|
||||||
def end_message(self, message: str | Exception) -> str:
|
def end_message(self, message: str | Exception) -> str:
|
||||||
output: str = " -> "
|
output: str = " -> "
|
||||||
if message is Exception:
|
if type(message) is not str:
|
||||||
output += "ERROR "
|
output += "ERROR "
|
||||||
# Print the output as the program goes
|
# Print the output as the program goes
|
||||||
self.style_print(output + str(message), indent=False)
|
self.style_print(output + str(message), indent=False)
|
||||||
@ -212,7 +216,7 @@ class SpipObject(SpipWritable):
|
|||||||
def convert(self, text: Optional[str], clean_html: bool = True) -> str:
|
def convert(self, text: Optional[str], clean_html: bool = True) -> str:
|
||||||
def found_replace(path_link: str, doc: Any, text: str, match: Match) -> str:
|
def found_replace(path_link: str, doc: Any, text: str, match: Match) -> str:
|
||||||
repl: str = path_link.format(doc.titre, doc.filename())
|
repl: str = path_link.format(doc.titre, doc.filename())
|
||||||
logging.info(f"Translating link to {repl}")
|
print(f"Translating link to {repl}")
|
||||||
return text.replace(match.group(), repl)
|
return text.replace(match.group(), repl)
|
||||||
|
|
||||||
def not_found_warn(path_link: str, text: str, match: Match) -> str:
|
def not_found_warn(path_link: str, text: str, match: Match) -> str:
|
||||||
@ -221,6 +225,7 @@ class SpipObject(SpipWritable):
|
|||||||
|
|
||||||
if text is not None and len(text) > 0:
|
if text is not None and len(text) > 0:
|
||||||
for id_link, path_link in DOCUMENT_LINK:
|
for id_link, path_link in DOCUMENT_LINK:
|
||||||
|
print(f"Looking for links like {id_link}")
|
||||||
for match in id_link.finditer(text):
|
for match in id_link.finditer(text):
|
||||||
logging.info(f"Found document link {match.group()} in {self.titre}")
|
logging.info(f"Found document link {match.group()} in {self.titre}")
|
||||||
try:
|
try:
|
||||||
@ -231,6 +236,7 @@ class SpipObject(SpipWritable):
|
|||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
text = not_found_warn(path_link, text, match)
|
text = not_found_warn(path_link, text, match)
|
||||||
for id_link, path_link in ARTICLE_LINK:
|
for id_link, path_link in ARTICLE_LINK:
|
||||||
|
print(f"Looking for links like {id_link}")
|
||||||
for match in id_link.finditer(text):
|
for match in id_link.finditer(text):
|
||||||
logging.info(f"Found article link {match.group()} in {self.titre}")
|
logging.info(f"Found article link {match.group()} in {self.titre}")
|
||||||
try:
|
try:
|
||||||
@ -239,6 +245,7 @@ class SpipObject(SpipWritable):
|
|||||||
except DoesNotExist:
|
except DoesNotExist:
|
||||||
text = not_found_warn(path_link, text, match)
|
text = not_found_warn(path_link, text, match)
|
||||||
for id_link, path_link in SECTION_LINK:
|
for id_link, path_link in SECTION_LINK:
|
||||||
|
print(f"Looking for links like {id_link}")
|
||||||
for match in id_link.finditer(text):
|
for match in id_link.finditer(text):
|
||||||
logging.info(f"Found section link {match.group()} in {self.titre}")
|
logging.info(f"Found section link {match.group()} in {self.titre}")
|
||||||
try:
|
try:
|
||||||
@ -255,7 +262,9 @@ class SpipObject(SpipWritable):
|
|||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
# Common fields that need conversions
|
# Common fields that need conversions
|
||||||
self.texte = self.convert(self.texte)
|
print(f"Convert texte from {self.titre}")
|
||||||
|
self.texte: str = self.convert(self.texte)
|
||||||
|
print(f"Convert extra from {self.titre}")
|
||||||
self.extra: str = self.convert(self.extra)
|
self.extra: str = self.convert(self.extra)
|
||||||
self.statut: str = "false" if self.statut == "publie" else "true"
|
self.statut: str = "false" if self.statut == "publie" else "true"
|
||||||
self.langue_choisie: str = "false" if self.langue_choisie == "oui" else "true"
|
self.langue_choisie: str = "false" if self.langue_choisie == "oui" else "true"
|
||||||
|
Loading…
Reference in New Issue
Block a user