diff --git a/jrnl/commands.py b/jrnl/commands.py index 6017347b..22b923c6 100644 --- a/jrnl/commands.py +++ b/jrnl/commands.py @@ -28,6 +28,12 @@ def preconfig_diagnostic(_): def preconfig_version(_): from jrnl import __title__ from jrnl import __version__ + from jrnl.plugins.meta import ( + IMPORT_FORMATS, + EXPORT_FORMATS, + get_exporter, + get_importer, + ) version_str = f"""{__title__} version {__version__} @@ -37,6 +43,22 @@ This is free software, and you are welcome to redistribute it under certain conditions; for details, see: https://www.gnu.org/licenses/gpl-3.0.html""" print(version_str) + print() + print("Active Plugins:") + print(" Importers:") + for importer in IMPORT_FORMATS: + importer_class = get_importer(importer) + print( + f" {importer} : {importer_class.version} from", + f"{importer_class().class_path()}", + ) + print(" Exporters:") + for exporter in EXPORT_FORMATS: + exporter_class = get_exporter(exporter) + # print(f" {exporter} : {exporter_class.version} from {exporter_class().class_path()}") + print(f" {exporter} : ", end="") + print(f"{exporter_class.version} from ", end="") + print(f"{exporter_class().class_path()}") def postconfig_list(config, **kwargs): diff --git a/jrnl/plugins/dates_exporter.py b/jrnl/plugins/dates_exporter.py index d11e527c..8be5c19e 100644 --- a/jrnl/plugins/dates_exporter.py +++ b/jrnl/plugins/dates_exporter.py @@ -4,7 +4,7 @@ # License: https://www.gnu.org/licenses/gpl-3.0.html from collections import Counter -from .text_exporter import TextExporter +from jrnl.plugins.exporter.text_exporter import Exporter as TextExporter class DatesExporter(TextExporter): diff --git a/jrnl/plugins/exporter/text_exporter.py b/jrnl/plugins/exporter/text_exporter.py index 9ed39916..2b0795ff 100644 --- a/jrnl/plugins/exporter/text_exporter.py +++ b/jrnl/plugins/exporter/text_exporter.py @@ -7,6 +7,7 @@ import os import re import unicodedata +from jrnl import __version__ from jrnl.color import ERROR_COLOR from jrnl.color import RESET_COLOR @@ -16,6 +17,11 @@ class Exporter: names = ["text", "txt"] extension = "txt" + version = __version__ + + @classmethod + def class_path(cls): + return cls.__module__ @classmethod def export_entry(cls, entry): diff --git a/jrnl/plugins/importer/jrnl_importer.py b/jrnl/plugins/importer/jrnl_importer.py index 3fe11e32..751cabaf 100644 --- a/jrnl/plugins/importer/jrnl_importer.py +++ b/jrnl/plugins/importer/jrnl_importer.py @@ -5,11 +5,17 @@ import sys +from jrnl import __version__ class Importer: """This plugin imports entries from other jrnl files.""" names = ["jrnl"] + version = __version__ + + @classmethod + def class_path(cls): + return cls.__module__ @staticmethod def import_(journal, input=None): diff --git a/jrnl/plugins/meta.py b/jrnl/plugins/meta.py index 8108a936..2f6ba463 100644 --- a/jrnl/plugins/meta.py +++ b/jrnl/plugins/meta.py @@ -58,21 +58,35 @@ __exporter_types = { **__exporter_types_builtin, **__exporter_types_contrib, } -__importer_types = {**__importer_types_builtin, **__importer_types_contrib} +__importer_types = { + **__importer_types_builtin, + **__importer_types_contrib, +} EXPORT_FORMATS = sorted(__exporter_types.keys()) IMPORT_FORMATS = sorted(__importer_types.keys()) def get_exporter(format): - for exporter in __exporters: - if hasattr(exporter, "names") and format in exporter.names: - return exporter + # print('get_exporter') + # print(__exporter_types) + for exporter_name, exporter_class in __exporter_types.items(): + # print(exporter_class, exporter_class.Exporter.names) + if ( + hasattr(exporter_class, "Exporter") + and hasattr(exporter_class.Exporter, "names") + and format in exporter_class.Exporter.names + ): + return exporter_class.Exporter return None def get_importer(format): - for importer in __importers: - if hasattr(importer, "names") and format in importer.names: - return importer + for importer_name, importer_class in __importer_types.items(): + if ( + hasattr(importer_class, "Importer") + and hasattr(importer_class.Importer, "names") + and format in importer_class.Importer.names + ): + return importer_class.Importer return None