fix draft logic and add option to not export them
This commit is contained in:
parent
a4f5837e0c
commit
499f1eab61
@ -26,6 +26,7 @@ class Configuration:
|
|||||||
unknown_char_replacement: str = "??" # Replaces unknown characters
|
unknown_char_replacement: str = "??" # Replaces unknown characters
|
||||||
export_languages = ("fr", "en") # Languages that will be exported
|
export_languages = ("fr", "en") # Languages that will be exported
|
||||||
export_filetype: str = "md" # Extension of exported text files
|
export_filetype: str = "md" # Extension of exported text files
|
||||||
|
export_drafts: bool = True # Should we export drafts as draft:true articles
|
||||||
clear_output: bool = False # Remove eventual output dir before running
|
clear_output: bool = False # Remove eventual output dir before running
|
||||||
clear_log: bool = False # Clear log before every run instead of appending to
|
clear_log: bool = False # Clear log before every run instead of appending to
|
||||||
logfile: str = "spip2md.log" # File where logs will be written, relative to wd
|
logfile: str = "spip2md.log" # File where logs will be written, relative to wd
|
||||||
|
@ -58,8 +58,9 @@ class SpipInterface:
|
|||||||
profondeur: int
|
profondeur: int
|
||||||
# Converted fields
|
# Converted fields
|
||||||
_title: str
|
_title: str
|
||||||
_status: bool
|
_draft: bool
|
||||||
# Additional fields
|
# Additional fields
|
||||||
|
# _id: BigAutoField | int = 0 # same ID attribute name for all objects
|
||||||
_id: BigAutoField | int = 0 # same ID attribute name for all objects
|
_id: BigAutoField | int = 0 # same ID attribute name for all objects
|
||||||
# _depth: IntegerField | int # Equals `profondeur` for sections
|
# _depth: IntegerField | int # Equals `profondeur` for sections
|
||||||
_depth: int # Equals `profondeur` for sections
|
_depth: int # Equals `profondeur` for sections
|
||||||
@ -182,11 +183,13 @@ class WritableObject(SpipInterface):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
# Initialize converted fields beginning with underscore
|
# Initialize converted fields beginning with underscore
|
||||||
self._description: str = self.convert_field(self.descriptif)
|
self._description: str = self.convert_field(self.descriptif)
|
||||||
self._status = 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) -> None:
|
||||||
self._title = self.convert_field(self.titre)
|
self._title = self.convert_field(self.titre)
|
||||||
|
if not CFG.export_drafts and self._draft:
|
||||||
|
raise NoExportDraftError(f"{self.titre} is a draft, cancelling export")
|
||||||
|
|
||||||
# Print one or more line(s) in which special elements are stylized
|
# Print one or more line(s) in which special elements are stylized
|
||||||
def style_print(
|
def style_print(
|
||||||
@ -300,8 +303,12 @@ class LangNotFoundError(Exception):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class NoExportDraftError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class RedactionalObject(WritableObject):
|
class RedactionalObject(WritableObject):
|
||||||
id_trad: BigIntegerField | int
|
id_trad: BigIntegerField | BigAutoField | int
|
||||||
id_rubrique: BigIntegerField | int
|
id_rubrique: BigIntegerField | int
|
||||||
# date: DateTimeField | str
|
# date: DateTimeField | str
|
||||||
date: DateTimeField
|
date: DateTimeField
|
||||||
@ -465,7 +472,7 @@ class RedactionalObject(WritableObject):
|
|||||||
"title": self._title,
|
"title": self._title,
|
||||||
"publishDate": self.date,
|
"publishDate": self.date,
|
||||||
"lastmod": self.maj,
|
"lastmod": self.maj,
|
||||||
"draft": self._status,
|
"draft": self._draft,
|
||||||
"description": self._description,
|
"description": self._description,
|
||||||
# Debugging
|
# Debugging
|
||||||
"spip_id_secteur": self.id_secteur,
|
"spip_id_secteur": self.id_secteur,
|
||||||
@ -525,8 +532,10 @@ class RedactionalObject(WritableObject):
|
|||||||
output.append(
|
output.append(
|
||||||
obj.write_all(self._depth, self.dest_directory(), i, total)
|
obj.write_all(self._depth, self.dest_directory(), i, total)
|
||||||
)
|
)
|
||||||
except LangNotFoundError:
|
except LangNotFoundError as err:
|
||||||
pass # For now, do nothing
|
logging.debug(err)
|
||||||
|
except NoExportDraftError as err:
|
||||||
|
logging.debug(err)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user