How to use the jrnl.util.load_config function in jrnl

To help you get started, we’ve selected a few jrnl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jrnl-org / jrnl / jrnl / install.py View on Github external
def load_or_install_jrnl():
    """
    If jrnl is already installed, loads and returns a config object.
    Else, perform various prompts to install jrnl.
    """
    config_path = (
        CONFIG_FILE_PATH
        if os.path.exists(CONFIG_FILE_PATH)
        else CONFIG_FILE_PATH_FALLBACK
    )
    if os.path.exists(config_path):
        log.debug("Reading configuration from file %s", config_path)
        config = util.load_config(config_path)

        try:
            upgrade.upgrade_jrnl_if_necessary(config_path)
        except upgrade.UpgradeValidationException:
            print("Aborting upgrade.", file=sys.stderr)
            print(
                "Please tell us about this problem at the following URL:",
                file=sys.stderr,
            )
            print(
                "https://github.com/jrnl-org/jrnl/issues/new?title=UpgradeValidationException",
                file=sys.stderr,
            )
            print("Exiting.", file=sys.stderr)
            sys.exit(1)
github jrnl-org / jrnl / features / steps / core.py View on Github external
def open_journal(journal_name="default"):
    config = util.load_config(install.CONFIG_FILE_PATH)
    journal_conf = config["journals"][journal_name]
    if (
        type(journal_conf) is dict
    ):  # We can override the default config on a by-journal basis
        config.update(journal_conf)
    else:  # But also just give them a string to point to the journal file
        config["journal"] = journal_conf
    return Journal.open_journal(journal_name, config)
github jrnl-org / jrnl / jrnl / upgrade.py View on Github external
def upgrade_jrnl_if_necessary(config_path):
    with open(config_path, "r", encoding="utf-8") as f:
        config_file = f.read()
    if not config_file.strip().startswith("{"):
        return

    config = util.load_config(config_path)

    print(
        """Welcome to jrnl {}.

It looks like you've been using an older version of jrnl until now. That's
okay - jrnl will now upgrade your configuration and journal files. Afterwards
you can enjoy all of the great new features that come with jrnl 2:

- Support for storing your journal in multiple files
- Faster reading and writing for large journals
- New encryption back-end that makes installing jrnl much easier
- Tons of bug fixes

Please note that jrnl 1.x is NOT forward compatible with this version of jrnl.
If you choose to proceed, you will not be able to use your journals with
older versions of jrnl anymore.