Skip to content

Commit

Permalink
Added 'toot diag' command that outputs useful diagnostic info
Browse files Browse the repository at this point in the history
  • Loading branch information
danschwarz committed Jun 14, 2024
1 parent 31501a8 commit ee45ec1
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions toot/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions toot/cli/diag.py
Original file line number Diff line number Diff line change
@@ -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()
35 changes: 35 additions & 0 deletions toot/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ee45ec1

Please sign in to comment.