|
17 | 17 | CLI commands are implemented in the ui.commands module.
|
18 | 18 | """
|
19 | 19 |
|
20 |
| - |
21 | 20 | import errno
|
22 | 21 | import optparse
|
23 | 22 | import os.path
|
|
31 | 30 |
|
32 | 31 | import confuse
|
33 | 32 | from rich_tables.utils import diff, make_console
|
| 33 | +from rich.logging import RichHandler |
| 34 | +from rich.traceback import install |
34 | 35 |
|
35 | 36 | from beets import config, library, logging, plugins, util
|
36 | 37 | from beets.autotag import mb
|
|
50 | 51 | else:
|
51 | 52 | colorama.init()
|
52 | 53 |
|
53 |
| - |
54 | 54 | log = logging.getLogger("beets")
|
| 55 | + |
55 | 56 | if not log.handlers:
|
56 |
| - log.addHandler(logging.StreamHandler()) |
| 57 | + handler = RichHandler( |
| 58 | + show_path=False, |
| 59 | + show_level=True, |
| 60 | + omit_repeated_times=False, |
| 61 | + rich_tracebacks=True, |
| 62 | + tracebacks_show_locals=True, |
| 63 | + tracebacks_width=console.width, |
| 64 | + tracebacks_extra_lines=1, |
| 65 | + keywords=["Sending event", "import"], |
| 66 | + markup=True, |
| 67 | + ) |
| 68 | + handler.setFormatter( |
| 69 | + logging.Formatter( |
| 70 | + "[b grey42]{name:<20}[/] {message}", datefmt="%T", style="{" |
| 71 | + ) |
| 72 | + ) |
| 73 | + log.addHandler(handler) |
| 74 | + |
57 | 75 | log.propagate = False # Don't propagate to root handler.
|
58 | 76 |
|
| 77 | +install(console=console, show_locals=True) |
| 78 | + |
59 | 79 |
|
60 | 80 | PF_KEY_QUERIES = {
|
61 | 81 | "comp": "comp:true",
|
@@ -122,14 +142,14 @@ def print_(*strings, **kwargs):
|
122 | 142 | (it defaults to a newline).
|
123 | 143 | """
|
124 | 144 | if not strings:
|
125 |
| - strings = [''] |
| 145 | + strings = [""] |
126 | 146 |
|
127 | 147 | try:
|
128 | 148 | for string in strings:
|
129 | 149 | if isinstance(string, str):
|
130 | 150 | console.print(string)
|
131 | 151 | else:
|
132 |
| - console.print(string, end='\n') |
| 152 | + console.print(string, end="\n") |
133 | 153 | except:
|
134 | 154 | console.print_exception(show_locals=True)
|
135 | 155 |
|
@@ -311,7 +331,7 @@ def input_options(
|
311 | 331 |
|
312 | 332 | # Wrap the query text.
|
313 | 333 | # Start prompt with U+279C: Heavy Round-Tipped Rightwards Arrow
|
314 |
| - prompt = colorize("action", "\u279C ") |
| 334 | + prompt = colorize("action", "\u279c ") |
315 | 335 | line_length = 0
|
316 | 336 | for i, (part, length) in enumerate(
|
317 | 337 | zip(prompt_parts, prompt_part_lengths)
|
@@ -380,7 +400,7 @@ def input_yn(prompt, require=False):
|
380 | 400 | "yes" unless `require` is `True`, in which case there is no default.
|
381 | 401 | """
|
382 | 402 | # Start prompt with U+279C: Heavy Round-Tipped Rightwards Arrow
|
383 |
| - yesno = colorize("action", "\u279C ") + colorize( |
| 403 | + yesno = colorize("action", "\u279c ") + colorize( |
384 | 404 | "action_description", "Enter Y or N:"
|
385 | 405 | )
|
386 | 406 | sel = input_options(("y", "n"), require, prompt, yesno)
|
@@ -884,8 +904,8 @@ def _field_diff(field, old, old_fmt, new, new_fmt):
|
884 | 904 | return None
|
885 | 905 |
|
886 | 906 | # Get formatted values for output.
|
887 |
| - oldval = old_fmt.get(field, u'') |
888 |
| - newval = new_fmt.get(field, u'') |
| 907 | + oldval = old_fmt.get(field, "") |
| 908 | + newval = new_fmt.get(field, "") |
889 | 909 |
|
890 | 910 | return diff(str(oldval), str(newval))
|
891 | 911 |
|
@@ -1188,9 +1208,7 @@ def __init__(self, *args, **kwargs):
|
1188 | 1208 | """
|
1189 | 1209 | # A more helpful default usage.
|
1190 | 1210 | if "usage" not in kwargs:
|
1191 |
| - kwargs[ |
1192 |
| - "usage" |
1193 |
| - ] = """ |
| 1211 | + kwargs["usage"] = """ |
1194 | 1212 | %prog COMMAND [ARGS...]
|
1195 | 1213 | %prog help COMMAND"""
|
1196 | 1214 | kwargs["add_help_option"] = False
|
@@ -1560,8 +1578,8 @@ def main(args=None):
|
1560 | 1578 | raise
|
1561 | 1579 | except UserError as exc:
|
1562 | 1580 | message = exc.args[0] if exc.args else None
|
1563 |
| - if 'No matching' in message: |
1564 |
| - log.error(u'error: {0}', message) |
| 1581 | + if "No matching" in message: |
| 1582 | + log.error("error: {0}", message) |
1565 | 1583 | else:
|
1566 | 1584 | console.print_exception(extra_lines=4, show_locals=True)
|
1567 | 1585 | sys.exit(1)
|
|
0 commit comments