Init virtual tree refactor
This refactor is intended to overcome certain limitations in the current architecture, where there’s a lot of situations where we would need to "seek in the future" to get the right value. In this new refactor, the goal is to incrementally build a tree virtually representing the final repo, with multiple passes. Then, when finished, another module will walk the tree, display in terminal and write the files.
This commit is contained in:
parent
3aa4f049f8
commit
b884c33b1d
@ -125,7 +125,7 @@ class SpipWritable:
|
|||||||
for m in finditer("(" + char + ")+", text):
|
for m in finditer("(" + char + ")+", text):
|
||||||
context: str = unknown_chars_context(text[lastend:], char)
|
context: str = unknown_chars_context(text[lastend:], char)
|
||||||
LOG.warn(
|
LOG.warn(
|
||||||
f"Unknown char {char} found in {self.titre[:40]} at: {context}"
|
f"Unknown char {char} in file {self.dest_path()} at: {context}"
|
||||||
)
|
)
|
||||||
if CFG.unknown_char_replacement is not None:
|
if CFG.unknown_char_replacement is not None:
|
||||||
LOG.warn(
|
LOG.warn(
|
||||||
@ -150,8 +150,6 @@ class SpipWritable:
|
|||||||
if CFG.remove_html:
|
if CFG.remove_html:
|
||||||
# Delete remaining HTML tags in body WARNING
|
# Delete remaining HTML tags in body WARNING
|
||||||
field = self.apply_mapping(field, HTMLTAGS)
|
field = self.apply_mapping(field, HTMLTAGS)
|
||||||
# Warn about unknown chars
|
|
||||||
field = self.warn_unknown(field, UNKNOWN_ISO)
|
|
||||||
return field.strip() # Strip whitespaces around text
|
return field.strip() # Strip whitespaces around text
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
@ -161,8 +159,10 @@ class SpipWritable:
|
|||||||
self._draft = self.statut != "publie"
|
self._draft = self.statut != "publie"
|
||||||
|
|
||||||
# Apply post-init conversions and cancel the export if self not of the right lang
|
# Apply post-init conversions and cancel the export if self not of the right lang
|
||||||
def convert(self) -> None:
|
def convert(self, forced_lang: Optional[str] = None) -> None:
|
||||||
self._storage_title = self.convert_field(self.titre)
|
self._storage_title = self.convert_field(self.titre)
|
||||||
|
# Warn about unknown chars
|
||||||
|
self._storage_title = self.warn_unknown(self._storage_title, UNKNOWN_ISO)
|
||||||
if not CFG.export_drafts and self._draft:
|
if not CFG.export_drafts and self._draft:
|
||||||
raise DontExportDraftError(f"{self.titre} is a draft, cancelling export")
|
raise DontExportDraftError(f"{self.titre} is a draft, cancelling export")
|
||||||
|
|
||||||
@ -244,11 +244,13 @@ class SpipWritable:
|
|||||||
index: int,
|
index: int,
|
||||||
total: int,
|
total: int,
|
||||||
parenturl: str,
|
parenturl: str,
|
||||||
|
forced_lang: Optional[str] = None,
|
||||||
) -> str:
|
) -> str:
|
||||||
LOG.debug(f"Writing {type(self).__name__} `{self._storage_title}`")
|
|
||||||
self._depth = parentdepth + 1
|
self._depth = parentdepth + 1
|
||||||
self._storage_parentdir = storage_parentdir
|
self._storage_parentdir = storage_parentdir
|
||||||
self._parenturl = parenturl
|
self._parenturl = parenturl
|
||||||
|
self.convert(forced_lang) # Post init convertions
|
||||||
|
LOG.debug(f"Writing {type(self).__name__} `{self._storage_title}`")
|
||||||
output: str = self.begin_message(index, total)
|
output: str = self.begin_message(index, total)
|
||||||
try:
|
try:
|
||||||
output += self.end_message(self.write())
|
output += self.end_message(self.write())
|
||||||
@ -310,7 +312,7 @@ class Document(SpipWritable, SpipDocuments):
|
|||||||
forcedlang: Optional[str] = None,
|
forcedlang: Optional[str] = None,
|
||||||
parenturl: str = "",
|
parenturl: str = "",
|
||||||
) -> str:
|
) -> str:
|
||||||
self.convert() # Apply post-init conversions
|
# self.convert() # Apply post-init conversions
|
||||||
LOG.debug(
|
LOG.debug(
|
||||||
f"Document {self._storage_title} doesn’t care about forcedlang {forcedlang}"
|
f"Document {self._storage_title} doesn’t care about forcedlang {forcedlang}"
|
||||||
)
|
)
|
||||||
@ -525,6 +527,9 @@ class SpipRedactional(SpipWritable):
|
|||||||
raise IgnoredPatternError(
|
raise IgnoredPatternError(
|
||||||
f"{self._url_title} matches with ignore pattern {p}, ignoring"
|
f"{self._url_title} matches with ignore pattern {p}, ignoring"
|
||||||
)
|
)
|
||||||
|
# Warn about unknown chars
|
||||||
|
self._storage_title = self.warn_unknown(self._storage_title, UNKNOWN_ISO)
|
||||||
|
self._url_title = self.warn_unknown(self._url_title, UNKNOWN_ISO)
|
||||||
|
|
||||||
def convert_text(self, forced_lang: str) -> None:
|
def convert_text(self, forced_lang: str) -> None:
|
||||||
LOG.debug(f"Convert text of `{self._url_title}`")
|
LOG.debug(f"Convert text of `{self._url_title}`")
|
||||||
@ -544,6 +549,8 @@ class SpipRedactional(SpipWritable):
|
|||||||
self._text = self.replace_links(self._text)
|
self._text = self.replace_links(self._text)
|
||||||
LOG.debug(f"Apply conversions to {self.lang} `{self._url_title}` text")
|
LOG.debug(f"Apply conversions to {self.lang} `{self._url_title}` text")
|
||||||
self._text = self.convert_field(self._text)
|
self._text = self.convert_field(self._text)
|
||||||
|
# Warn about unknown chars
|
||||||
|
self._text = self.warn_unknown(self._text, UNKNOWN_ISO)
|
||||||
|
|
||||||
def convert_extra(self) -> None:
|
def convert_extra(self) -> None:
|
||||||
LOG.debug(f"Convert extra of `{self._url_title}`")
|
LOG.debug(f"Convert extra of `{self._url_title}`")
|
||||||
@ -562,6 +569,8 @@ class SpipRedactional(SpipWritable):
|
|||||||
self._extra = self.replace_links(self._extra)
|
self._extra = self.replace_links(self._extra)
|
||||||
LOG.debug(f"Apply conversions to {self.lang} `{self._url_title}` extra")
|
LOG.debug(f"Apply conversions to {self.lang} `{self._url_title}` extra")
|
||||||
self._extra = self.convert_field(self._extra, CFG.metadata_markup)
|
self._extra = self.convert_field(self._extra, CFG.metadata_markup)
|
||||||
|
# Warn about unknown chars
|
||||||
|
self._extra = self.warn_unknown(self._extra, UNKNOWN_ISO)
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
@ -781,7 +790,7 @@ class Article(SpipRedactional, SpipArticles):
|
|||||||
forced_lang: str,
|
forced_lang: str,
|
||||||
parenturl: str,
|
parenturl: str,
|
||||||
) -> DeepDict:
|
) -> DeepDict:
|
||||||
self.convert(forced_lang)
|
# self.convert(forced_lang)
|
||||||
return {
|
return {
|
||||||
"msg": super().write_all(
|
"msg": super().write_all(
|
||||||
parentdepth, storage_parentdir, index, total, parenturl
|
parentdepth, storage_parentdir, index, total, parenturl
|
||||||
@ -844,7 +853,7 @@ class Section(SpipRedactional, SpipRubriques):
|
|||||||
forced_lang: str,
|
forced_lang: str,
|
||||||
parenturl: str = "",
|
parenturl: str = "",
|
||||||
) -> DeepDict:
|
) -> DeepDict:
|
||||||
self.convert(forced_lang)
|
# self.convert(forced_lang)
|
||||||
return {
|
return {
|
||||||
"msg": super().write_all(
|
"msg": super().write_all(
|
||||||
parentdepth, storage_parentdir, index, total, parenturl
|
parentdepth, storage_parentdir, index, total, parenturl
|
||||||
|
Loading…
Reference in New Issue
Block a user