From ee45ec1ffd5d8a9e3de8baec2dc033103bdfe8bf Mon Sep 17 00:00:00 2001 From: Daniel Schwarz Date: Thu, 13 Jun 2024 20:27:31 -0400 Subject: [PATCH] Added 'toot diag' command that outputs useful diagnostic info --- .flake8 | 2 +- toot/cli/__init__.py | 1 + toot/cli/diag.py | 14 ++++++++++++++ toot/output.py | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 toot/cli/diag.py diff --git a/.flake8 b/.flake8 index ac93b71..8d01264 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] -exclude=build,tests,tmp,venv,toot/tui/scroll.py +exclude=build,tests,tmp,venv,_env,toot/tui/scroll.py ignore=E128,W503,W504 max-line-length=120 diff --git a/toot/cli/__init__.py b/toot/cli/__init__.py index a4698ff..f525841 100644 --- a/toot/cli/__init__.py +++ b/toot/cli/__init__.py @@ -173,6 +173,7 @@ def cli(ctx: click.Context, max_width: int, color: bool, debug: bool, as_user: s from toot.cli import accounts # noqa from toot.cli import auth # noqa +from toot.cli import diag # noqa from toot.cli import lists # noqa from toot.cli import post # noqa from toot.cli import read # noqa diff --git a/toot/cli/diag.py b/toot/cli/diag.py new file mode 100644 index 0000000..39ff73f --- /dev/null +++ b/toot/cli/diag.py @@ -0,0 +1,14 @@ +from toot.output import print_diags +from toot.cli import ( + cli, + pass_context, + Context, +) + + +@cli.command() +@pass_context +def diag(ctx: Context): + """Display useful information for diagnosing problems""" + + print_diags() diff --git a/toot/output.py b/toot/output.py index e9b0812..74fc70c 100644 --- a/toot/output.py +++ b/toot/output.py @@ -314,6 +314,41 @@ def format_account_name(account: Account) -> str: return acct +def print_diags(): + from importlib.metadata import version + + click.echo(f'{green(f"Diagnostic Information")}') + from datetime import datetime, timezone + + now = datetime.now(timezone.utc) + click.echo(f'{green("Current Date/Time:")} {now.strftime("%Y-%m-%d %H:%M:%S %Z")}') + + import platform + click.echo(f'{green(f"Platform:")} {platform.platform()}') + +# Uncomment this when we move to minimum Python version 3.10 +# try: +# name = platform.freedesktop_os_release()['PRETTY_NAME'] +# click.echo(f'{green(f"Distro:")} {name}') +# except: # noqa +# pass + + click.echo(f'{green(f"Python version:")} {platform.python_version()}') + click.echo(green("Dependency versions:")) + + deps = ['beautifulsoup4', 'click', 'requests', 'tomlkit', 'urwid', 'wcwidth', + 'pillow', 'term-image', 'urwidgets', 'flake8', 'pytest', 'setuptools', + 'vermin', 'typing-extensions'] + + for dep in deps: + try: + ver = version(dep) + except: # noqa + ver = yellow("not installed") + + click.echo(f"\t{dep}: {ver}") + + # Shorthand functions for coloring output def blue(text: t.Any) -> str: