jrnl.output.deprecated_cmd()   A
last analyzed

Complexity

Conditions 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 11
nop 4
dl 0
loc 17
rs 9.85
c 0
b 0
f 0
1
import logging
2
3
4
def deprecated_cmd(old_cmd, new_cmd, callback=None, **kwargs):
5
    import sys
6
    import textwrap
7
8
    from .color import RESET_COLOR
9
    from .color import WARNING_COLOR
10
11
    warning_msg = f"""
12
    The command {old_cmd} is deprecated and will be removed from jrnl soon.
13
    Please use {new_cmd} instead.
14
    """
15
    warning_msg = textwrap.dedent(warning_msg)
16
    logging.warning(warning_msg)
17
    print(f"{WARNING_COLOR}{warning_msg}{RESET_COLOR}", file=sys.stderr)
18
19
    if callback is not None:
20
        callback(**kwargs)
21
22
23
def list_journals(config):
24
    from . import install
25
26
    """List the journals specified in the configuration file"""
27
    result = f"Journals defined in {install.CONFIG_FILE_PATH}\n"
28
    ml = min(max(len(k) for k in config["journals"]), 20)
29
    for journal, cfg in config["journals"].items():
30
        result += " * {:{}} -> {}\n".format(
31
            journal, ml, cfg["journal"] if isinstance(cfg, dict) else cfg
32
        )
33
    return result
34