add option to ignore certain objects
This commit is contained in:
parent
3564a56870
commit
a8ebb2cd24
@ -31,6 +31,7 @@ class Configuration:
|
|||||||
unknown_char_replacement: str = "??" # Replaces unknown characters
|
unknown_char_replacement: str = "??" # Replaces unknown characters
|
||||||
clear_log: bool = True # Clear log before every run instead of appending to
|
clear_log: bool = True # Clear log before every run instead of appending to
|
||||||
clear_output: bool = True # Remove eventual output dir before running
|
clear_output: bool = True # Remove eventual output dir before running
|
||||||
|
ignore_pattern: list[str] = [] # Ignore objects of which title match
|
||||||
logfile: str = "log-spip2md.log" # File where logs will be written, relative to wd
|
logfile: str = "log-spip2md.log" # File where logs will be written, relative to wd
|
||||||
loglevel: str = "WARNING" # Minimum criticity of logs written in logfile
|
loglevel: str = "WARNING" # Minimum criticity of logs written in logfile
|
||||||
logname: str = "spip2md" # Labelling of logs
|
logname: str = "spip2md" # Labelling of logs
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from os import listdir, makedirs
|
from os import listdir, makedirs
|
||||||
from os.path import basename, isfile, splitext
|
from os.path import basename, isfile, splitext
|
||||||
from re import Match, Pattern, finditer, match, search
|
from re import I, Match, Pattern, finditer, match, search
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from typing import Any, Optional
|
from typing import Any, Optional
|
||||||
|
|
||||||
@ -301,6 +301,10 @@ class Document(WritableObject, NormalizedDocument):
|
|||||||
return super().write_all(parentdepth, parentdir, index, total)
|
return super().write_all(parentdepth, parentdir, index, total)
|
||||||
|
|
||||||
|
|
||||||
|
class IgnoredPatternError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LangNotFoundError(Exception):
|
class LangNotFoundError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -524,6 +528,8 @@ class RedactionalObject(WritableObject):
|
|||||||
LOG.debug(err)
|
LOG.debug(err)
|
||||||
except DontExportDraftError as err:
|
except DontExportDraftError as err:
|
||||||
LOG.debug(err)
|
LOG.debug(err)
|
||||||
|
except IgnoredPatternError as err:
|
||||||
|
LOG.debug(err)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
# Write object to output destination
|
# Write object to output destination
|
||||||
@ -559,6 +565,12 @@ class RedactionalObject(WritableObject):
|
|||||||
# 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, forced_lang: str) -> None:
|
def convert(self, forced_lang: str) -> None:
|
||||||
self.convert_title(forced_lang)
|
self.convert_title(forced_lang)
|
||||||
|
for p in CFG.ignore_pattern:
|
||||||
|
m = match(p, self._title, I)
|
||||||
|
if m is not None:
|
||||||
|
raise IgnoredPatternError(
|
||||||
|
f"{self._title} is matching with ignore pattern {p}, ignoring"
|
||||||
|
)
|
||||||
self.convert_text(forced_lang)
|
self.convert_text(forced_lang)
|
||||||
self.convert_extra()
|
self.convert_extra()
|
||||||
if self.lang != forced_lang:
|
if self.lang != forced_lang:
|
||||||
|
@ -9,6 +9,7 @@ from spip2md.config import CFG
|
|||||||
from spip2md.extended_models import (
|
from spip2md.extended_models import (
|
||||||
DeepDict,
|
DeepDict,
|
||||||
DontExportDraftError,
|
DontExportDraftError,
|
||||||
|
IgnoredPatternError,
|
||||||
LangNotFoundError,
|
LangNotFoundError,
|
||||||
Section,
|
Section,
|
||||||
)
|
)
|
||||||
@ -54,6 +55,8 @@ as database user {esc(BOLD)}{CFG.db_user}{esc()}
|
|||||||
ROOTLOG.debug(err) # Log the message
|
ROOTLOG.debug(err) # Log the message
|
||||||
except DontExportDraftError as err: # Will happen in not CFG.export_drafts
|
except DontExportDraftError as err: # Will happen in not CFG.export_drafts
|
||||||
ROOTLOG.debug(err) # Log the message
|
ROOTLOG.debug(err) # Log the message
|
||||||
|
except IgnoredPatternError as err:
|
||||||
|
ROOTLOG.debug(err) # Log the message
|
||||||
print() # Break line between level 0 sections in output
|
print() # Break line between level 0 sections in output
|
||||||
ROOTLOG.debug(f"Finished exporting {lang} root section {i}/{nb} {s._title}")
|
ROOTLOG.debug(f"Finished exporting {lang} root section {i}/{nb} {s._title}")
|
||||||
return {"sections": buffer}
|
return {"sections": buffer}
|
||||||
|
Loading…
Reference in New Issue
Block a user