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
|
||||
clear_log: bool = True # Clear log before every run instead of appending to
|
||||
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
|
||||
loglevel: str = "WARNING" # Minimum criticity of logs written in logfile
|
||||
logname: str = "spip2md" # Labelling of logs
|
||||
|
@ -2,7 +2,7 @@
|
||||
import logging
|
||||
from os import listdir, makedirs
|
||||
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 typing import Any, Optional
|
||||
|
||||
@ -301,6 +301,10 @@ class Document(WritableObject, NormalizedDocument):
|
||||
return super().write_all(parentdepth, parentdir, index, total)
|
||||
|
||||
|
||||
class IgnoredPatternError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class LangNotFoundError(Exception):
|
||||
pass
|
||||
|
||||
@ -524,6 +528,8 @@ class RedactionalObject(WritableObject):
|
||||
LOG.debug(err)
|
||||
except DontExportDraftError as err:
|
||||
LOG.debug(err)
|
||||
except IgnoredPatternError as err:
|
||||
LOG.debug(err)
|
||||
return output
|
||||
|
||||
# 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
|
||||
def convert(self, forced_lang: str) -> None:
|
||||
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_extra()
|
||||
if self.lang != forced_lang:
|
||||
|
@ -9,6 +9,7 @@ from spip2md.config import CFG
|
||||
from spip2md.extended_models import (
|
||||
DeepDict,
|
||||
DontExportDraftError,
|
||||
IgnoredPatternError,
|
||||
LangNotFoundError,
|
||||
Section,
|
||||
)
|
||||
@ -54,6 +55,8 @@ as database user {esc(BOLD)}{CFG.db_user}{esc()}
|
||||
ROOTLOG.debug(err) # Log the message
|
||||
except DontExportDraftError as err: # Will happen in not CFG.export_drafts
|
||||
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
|
||||
ROOTLOG.debug(f"Finished exporting {lang} root section {i}/{nb} {s._title}")
|
||||
return {"sections": buffer}
|
||||
|
Loading…
Reference in New Issue
Block a user