mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-20 04:58:32 +02:00
first cut at wrapper method to export journals
This commit is contained in:
parent
6e3574c529
commit
2642cdef22
1 changed files with 24 additions and 3 deletions
27
jrnl/jrnl.py
27
jrnl/jrnl.py
|
@ -6,7 +6,7 @@ import sys
|
||||||
|
|
||||||
from . import install
|
from . import install
|
||||||
from . import plugins
|
from . import plugins
|
||||||
from .Journal import open_journal
|
from .Journal import Journal, open_journal
|
||||||
from .color import ERROR_COLOR
|
from .color import ERROR_COLOR
|
||||||
from .color import RESET_COLOR
|
from .color import RESET_COLOR
|
||||||
from .config import get_journal_name
|
from .config import get_journal_name
|
||||||
|
@ -323,10 +323,31 @@ def _display_search_results(args, journal, **kwargs):
|
||||||
print(plugins.get_exporter("tags").export(journal))
|
print(plugins.get_exporter("tags").export(journal))
|
||||||
|
|
||||||
elif args.export:
|
elif args.export:
|
||||||
exporter = plugins.get_exporter(args.export)
|
_export_journal(args, journal)
|
||||||
print(exporter.export(journal, args.filename))
|
|
||||||
elif kwargs["config"].get("display_format"):
|
elif kwargs["config"].get("display_format"):
|
||||||
exporter = plugins.get_exporter(kwargs["config"]["display_format"])
|
exporter = plugins.get_exporter(kwargs["config"]["display_format"])
|
||||||
print(exporter.export(journal, args.filename))
|
print(exporter.export(journal, args.filename))
|
||||||
else:
|
else:
|
||||||
print(journal.pprint())
|
print(journal.pprint())
|
||||||
|
|
||||||
|
|
||||||
|
from argparse import Namespace
|
||||||
|
|
||||||
|
|
||||||
|
def _export_journal(args: Namespace, journal: Journal):
|
||||||
|
"""Export journal using supplied export format
|
||||||
|
Export formats "short" and "pretty" are shorthands for pre-configured
|
||||||
|
jrnl behavior, hence those export formats bypass the export plugins.
|
||||||
|
|
||||||
|
:param args: parsed arguments
|
||||||
|
:type args: Namespace
|
||||||
|
:param journal: journal under use
|
||||||
|
:type journal: Journal
|
||||||
|
"""
|
||||||
|
if args.export == "pretty":
|
||||||
|
print(journal.pprint(short=False))
|
||||||
|
elif args.export == "short":
|
||||||
|
print(journal.pprint(short=True))
|
||||||
|
else:
|
||||||
|
exporter = plugins.get_exporter(args.export)
|
||||||
|
print(exporter.export(journal, args.filename))
|
||||||
|
|
Loading…
Add table
Reference in a new issue