1
0
mirror of https://github.com/ihabunek/toot.git synced 2024-11-03 04:17:21 -05:00

Added 'toot diag' command that outputs useful diagnostic info

This commit is contained in:
Daniel Schwarz 2024-06-13 20:27:31 -04:00
parent 31501a84a0
commit ee45ec1ffd
4 changed files with 51 additions and 1 deletions

View File

@ -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

View File

@ -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

14
toot/cli/diag.py Normal file
View File

@ -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()

View File

@ -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: