begin message outputs one only string + output tree in debug log
This commit is contained in:
parent
da112ca68e
commit
3ab58288f7
@ -208,28 +208,26 @@ class WritableObject(SpipInterface):
|
|||||||
return stylized
|
return stylized
|
||||||
|
|
||||||
# Print the message telling what is going to be done
|
# Print the message telling what is going to be done
|
||||||
def begin_message(self, index: int, limit: int, step: int = 100) -> list[str]:
|
def begin_message(self, index: int, limit: int, step: int = 100) -> str:
|
||||||
output: list[str] = []
|
|
||||||
# Output the remaining number of objects to export every step object
|
# Output the remaining number of objects to export every step object
|
||||||
if index % step == 0 and limit > 0:
|
if index % step == 0 and limit > 0:
|
||||||
output.append(f"Exporting {limit-index}")
|
counter: str = f"Exporting {limit-index} level {self._depth}"
|
||||||
output[-1] += f" level {self._depth}"
|
|
||||||
s: str = "s" if limit - index > 1 else ""
|
s: str = "s" if limit - index > 1 else ""
|
||||||
if hasattr(self, "lang"):
|
if hasattr(self, "lang"):
|
||||||
output[-1] += f" {self.lang}"
|
counter += f" {self.lang}"
|
||||||
output[-1] += f" {type(self).__name__}{s}"
|
counter += f" {type(self).__name__}{s}"
|
||||||
# Print the output as the program goes
|
# Print the output as the program goes
|
||||||
self.style_print(output[-1])
|
self.style_print(counter)
|
||||||
# Output the counter & title of the object being exported
|
# Output the counter & title of the object being exported
|
||||||
output.append(f"{index + 1}. ")
|
msg: str = f"{index + 1}. "
|
||||||
if len(self._title) == 0:
|
if len(self._title) == 0:
|
||||||
output[-1] += "EMPTY NAME"
|
msg += "EMPTY NAME"
|
||||||
else:
|
else:
|
||||||
output[-1] += self._title
|
msg += self._title
|
||||||
# Print the output as the program goes
|
# Print the output as the program goes
|
||||||
# LOG.debug(f"Begin exporting {type(self).__name__} {output[-1]}")
|
# LOG.debug(f"Begin exporting {type(self).__name__} {output[-1]}")
|
||||||
self.style_print(output[-1], end="")
|
self.style_print(msg, end="")
|
||||||
return output
|
return msg
|
||||||
|
|
||||||
# Write object to output destination
|
# Write object to output destination
|
||||||
def write(self) -> str:
|
def write(self) -> str:
|
||||||
@ -252,17 +250,15 @@ class WritableObject(SpipInterface):
|
|||||||
# Perform all the write steps of this object
|
# Perform all the write steps of this object
|
||||||
def write_all(
|
def write_all(
|
||||||
self, parentdepth: int, parentdir: str, index: int, total: int
|
self, parentdepth: int, parentdir: str, index: int, total: int
|
||||||
) -> RecursiveList:
|
) -> str:
|
||||||
LOG.debug(f"Writing {type(self).__name__} `{self._title}`")
|
LOG.debug(f"Writing {type(self).__name__} `{self._title}`")
|
||||||
output: RecursiveList = []
|
|
||||||
self._depth = parentdepth + 1
|
self._depth = parentdepth + 1
|
||||||
self._parentdir = parentdir
|
self._parentdir = parentdir
|
||||||
for m in self.begin_message(index, total):
|
output: str = self.begin_message(index, total)
|
||||||
output.append(m)
|
|
||||||
try:
|
try:
|
||||||
output[-1] += self.end_message(self.write())
|
output += self.end_message(self.write())
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
output[-1] += self.end_message(err)
|
output += self.end_message(err)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
@ -299,7 +295,7 @@ class Document(WritableObject, NormalizedDocument):
|
|||||||
# Perform all the write steps of this object
|
# Perform all the write steps of this object
|
||||||
def write_all(
|
def write_all(
|
||||||
self, parentdepth: int, parentdir: str, index: int, total: int
|
self, parentdepth: int, parentdir: str, index: int, total: int
|
||||||
) -> RecursiveList:
|
) -> str:
|
||||||
self.convert() # Apply post-init conversions
|
self.convert() # Apply post-init conversions
|
||||||
return super().write_all(parentdepth, parentdir, index, total)
|
return super().write_all(parentdepth, parentdir, index, total)
|
||||||
|
|
||||||
@ -628,9 +624,10 @@ class Article(RedactionalObject, NormalizedArticle):
|
|||||||
self, forced_lang: str, parentdepth: int, parentdir: str, index: int, total: int
|
self, forced_lang: str, parentdepth: int, parentdir: str, index: int, total: int
|
||||||
) -> RecursiveList:
|
) -> RecursiveList:
|
||||||
self.convert(forced_lang)
|
self.convert(forced_lang)
|
||||||
output: RecursiveList = super().write_all(parentdepth, parentdir, index, total)
|
return [
|
||||||
output.append(self.write_documents())
|
super().write_all(parentdepth, parentdir, index, total),
|
||||||
return output
|
self.write_documents(),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class Section(RedactionalObject, NormalizedSection):
|
class Section(RedactionalObject, NormalizedSection):
|
||||||
@ -693,6 +690,7 @@ class Section(RedactionalObject, NormalizedSection):
|
|||||||
self, forced_lang: str, parentdepth: int, parentdir: str, index: int, total: int
|
self, forced_lang: str, parentdepth: int, parentdir: str, index: int, total: int
|
||||||
) -> RecursiveList:
|
) -> RecursiveList:
|
||||||
self.convert(forced_lang)
|
self.convert(forced_lang)
|
||||||
output: RecursiveList = super().write_all(parentdepth, parentdir, index, total)
|
return [
|
||||||
output.append(self.write_children(forced_lang))
|
super().write_all(parentdepth, parentdir, index, total),
|
||||||
return output
|
self.write_children(forced_lang),
|
||||||
|
]
|
||||||
|
@ -16,6 +16,7 @@ from spip2md.style import BOLD, esc
|
|||||||
|
|
||||||
# Define loggers for this file
|
# Define loggers for this file
|
||||||
ROOTLOG = logging.getLogger(CFG.logname + ".root")
|
ROOTLOG = logging.getLogger(CFG.logname + ".root")
|
||||||
|
TREELOG = logging.getLogger(CFG.logname + ".tree")
|
||||||
# Initialize the database with settings from CFG
|
# Initialize the database with settings from CFG
|
||||||
DB.init(CFG.db, host=CFG.db_host, user=CFG.db_user, password=CFG.db_pass)
|
DB.init(CFG.db, host=CFG.db_host, user=CFG.db_user, password=CFG.db_pass)
|
||||||
|
|
||||||
@ -72,6 +73,7 @@ def summarize(
|
|||||||
leaves += 1
|
leaves += 1
|
||||||
# End message only if it’s the root one
|
# End message only if it’s the root one
|
||||||
if depth == -1:
|
if depth == -1:
|
||||||
|
TREELOG.debug(tree)
|
||||||
print(
|
print(
|
||||||
f"""\
|
f"""\
|
||||||
Exported a total of {esc(BOLD)}{leaves}{esc()} files, \
|
Exported a total of {esc(BOLD)}{leaves}{esc()} files, \
|
||||||
|
Loading…
Reference in New Issue
Block a user