How to use the jrnl.util 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
path_query = f"Path to your journal file (leave blank for {JOURNAL_FILE_PATH}): "
    journal_path = input(path_query).strip() or JOURNAL_FILE_PATH
    default_config["journals"][DEFAULT_JOURNAL_KEY] = os.path.expanduser(
        os.path.expandvars(journal_path)
    )

    path = os.path.split(default_config["journals"][DEFAULT_JOURNAL_KEY])[
        0
    ]  # If the folder doesn't exist, create it
    try:
        os.makedirs(path)
    except OSError:
        pass

    # Encrypt it?
    encrypt = util.yesno(
        "Do you want to encrypt your journal? You can always change this later",
        default=False,
    )
    if encrypt:
        default_config["encrypt"] = True
        print("Journal will be encrypted.", file=sys.stderr)

    save_config(default_config)
    return default_config
github jrnl-org / jrnl / jrnl / Journal.py View on Github external
                                lambda match: util.colorize(match.group(0)),
                                pp)
github jrnl-org / jrnl / jrnl / Journal.py View on Github external
                    lambda match: util.colorize(match.group(0)),
                    pp
github jrnl-org / jrnl / features / environment.py View on Github external
def before_scenario(context, scenario):
    """Before each scenario, backup all config and journal test data."""
    context.messages = StringIO()
    jrnl.util.STDERR = context.messages
    jrnl.util.TEST = True

    # Clean up in case something went wrong
    for folder in ("configs", "journals"):
        working_dir = os.path.join("features", folder)
        if os.path.exists(working_dir):
            shutil.rmtree(working_dir)


    for folder in ("configs", "journals"):
        original = os.path.join("features", "data", folder)
        working_dir = os.path.join("features", folder)
        if not os.path.exists(working_dir):
            os.mkdir(working_dir)
        for filename in os.listdir(original):
            source = os.path.join(original, filename)
github jrnl-org / jrnl / jrnl / upgrade.py View on Github external
file=sys.stderr,
        )
        backup(path, binary=True)
        old_journal = Journal.open_journal(
            journal_name, util.scope_config(config, journal_name), legacy=True
        )
        all_journals.append(EncryptedJournal.from_journal(old_journal))

    for journal_name, path in plain_journals.items():
        print(
            f"\nUpgrading plain text '{journal_name}' journal stored in {path}...",
            file=sys.stderr,
        )
        backup(path)
        old_journal = Journal.open_journal(
            journal_name, util.scope_config(config, journal_name), legacy=True
        )
        all_journals.append(Journal.PlainJournal.from_journal(old_journal))

    # loop through lists to validate
    failed_journals = [j for j in all_journals if not j.validate_parsing()]

    if len(failed_journals) > 0:
        print(
            "\nThe following journal{} failed to upgrade:\n{}".format(
                "s" if len(failed_journals) > 1 else "",
                "\n".join(j.name for j in failed_journals),
            ),
            file=sys.stderr,
        )

        raise UpgradeValidationException