mirror of
https://github.com/ihabunek/toot.git
synced 2025-06-30 22:18:36 -04:00
Move diag logic to own module, break up a bit
This commit is contained in:
parent
0d829e9495
commit
2a5e823878
103
toot/cli/diag.py
103
toot/cli/diag.py
@ -1,9 +1,29 @@
|
||||
import json
|
||||
import platform
|
||||
from os import path
|
||||
from typing import Optional
|
||||
|
||||
import click
|
||||
from toot import api, config
|
||||
from toot.entities import Data, Instance, from_dict
|
||||
from toot.output import print_diags
|
||||
|
||||
from toot import __version__, api, config, settings
|
||||
from toot.cli import cli
|
||||
from toot.entities import Instance, from_dict
|
||||
from toot.output import bold, yellow
|
||||
from toot.utils import get_distro_name, get_version
|
||||
|
||||
DIAG_DEPENDENCIES = [
|
||||
"beautifulsoup4",
|
||||
"click",
|
||||
"pillow",
|
||||
"requests",
|
||||
"setuptools",
|
||||
"term-image",
|
||||
"tomlkit",
|
||||
"typing-extensions",
|
||||
"urwid",
|
||||
"urwidgets",
|
||||
"wcwidth",
|
||||
]
|
||||
|
||||
|
||||
@cli.command()
|
||||
@ -28,4 +48,79 @@ def diag(files: bool, server: bool):
|
||||
response = api.get_instance(app.base_url)
|
||||
instance = from_dict(Instance, response.json())
|
||||
|
||||
print_diags(instance, files)
|
||||
click.echo("## Toot Diagnostics")
|
||||
print_environment()
|
||||
print_dependencies()
|
||||
print_instance(instance)
|
||||
print_settings(files)
|
||||
print_config(files)
|
||||
|
||||
|
||||
def print_environment():
|
||||
click.echo()
|
||||
click.echo(f"toot {__version__}")
|
||||
click.echo(f"Python {platform.python_version()}")
|
||||
click.echo(platform.platform())
|
||||
|
||||
distro = get_distro_name()
|
||||
if distro:
|
||||
click.echo(distro)
|
||||
|
||||
|
||||
def print_dependencies():
|
||||
click.echo()
|
||||
click.secho(bold("Dependencies:"))
|
||||
for dep in DIAG_DEPENDENCIES:
|
||||
version = get_version(dep) or yellow("not installed")
|
||||
click.echo(f" * {dep}: {version}")
|
||||
|
||||
|
||||
def print_instance(instance: Optional[Instance]):
|
||||
if instance:
|
||||
click.echo()
|
||||
click.echo(bold("Server:"))
|
||||
click.echo(instance.title)
|
||||
click.echo(instance.uri)
|
||||
click.echo(f"version {instance.version}")
|
||||
|
||||
|
||||
def print_settings(include_files: bool):
|
||||
click.echo()
|
||||
settings_path = settings.get_settings_path()
|
||||
if path.exists(settings_path):
|
||||
click.echo(f"Settings file: {settings_path}")
|
||||
if include_files:
|
||||
with open(settings_path, "r") as f:
|
||||
click.echo("\n```toml")
|
||||
click.echo(f.read().strip())
|
||||
click.echo("```\n")
|
||||
else:
|
||||
click.echo(f'Settings file: {yellow("not found")}')
|
||||
|
||||
|
||||
def print_config(include_files: bool):
|
||||
click.echo()
|
||||
config_path = config.get_config_file_path()
|
||||
if path.exists(config_path):
|
||||
click.echo(f"Config file: {config_path}")
|
||||
if include_files:
|
||||
content = _get_anonymized_config(config_path)
|
||||
click.echo("\n```json")
|
||||
click.echo(json.dumps(content, indent=4))
|
||||
click.echo("```\n")
|
||||
else:
|
||||
click.echo(f'Config file: {yellow("not found")}')
|
||||
|
||||
|
||||
def _get_anonymized_config(config_path):
|
||||
with open(config_path, "r") as f:
|
||||
content = json.load(f)
|
||||
|
||||
for app in content.get("apps", {}).values():
|
||||
app["client_id"] = "*****"
|
||||
app["client_secret"] = "*****"
|
||||
|
||||
for user in content.get("users", {}).values():
|
||||
user["access_token"] = "*****"
|
||||
|
||||
return content
|
||||
|
@ -1,20 +1,15 @@
|
||||
import json
|
||||
from os import path
|
||||
import click
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import textwrap
|
||||
import typing as t
|
||||
|
||||
import click
|
||||
from wcwidth import wcswidth
|
||||
|
||||
from toot import __version__, config, settings
|
||||
from toot.entities import Account, Data, Instance, Notification, Poll, Status, List
|
||||
from toot.utils import get_distro_name, get_text, get_version, html_to_paragraphs
|
||||
from toot.entities import Account, Instance, List, Notification, Poll, Status
|
||||
from toot.utils import get_text, html_to_paragraphs
|
||||
from toot.wcstring import wc_wrap
|
||||
|
||||
|
||||
DEFAULT_WIDTH = 80
|
||||
|
||||
|
||||
@ -330,76 +325,6 @@ def format_account_name(account: Account) -> str:
|
||||
return acct
|
||||
|
||||
|
||||
def print_diags(instance: t.Optional[Instance], include_files: bool):
|
||||
click.echo("## Toot Diagnostics")
|
||||
click.echo()
|
||||
click.echo(f"toot {__version__}")
|
||||
click.echo(f"Python {platform.python_version()}")
|
||||
click.echo(platform.platform())
|
||||
|
||||
distro = get_distro_name()
|
||||
if distro:
|
||||
click.echo(distro)
|
||||
|
||||
click.echo()
|
||||
click.secho(bold("Dependencies:"))
|
||||
|
||||
deps = [
|
||||
"beautifulsoup4",
|
||||
"click",
|
||||
"pillow",
|
||||
"requests",
|
||||
"setuptools",
|
||||
"term-image",
|
||||
"tomlkit",
|
||||
"typing-extensions",
|
||||
"urwid",
|
||||
"urwidgets",
|
||||
"wcwidth",
|
||||
]
|
||||
|
||||
for dep in deps:
|
||||
version = get_version(dep) or yellow("not installed")
|
||||
click.echo(f" * {dep}: {version}")
|
||||
|
||||
if instance:
|
||||
click.echo()
|
||||
click.echo(bold("Server:"))
|
||||
click.echo(instance.title)
|
||||
click.echo(instance.uri)
|
||||
click.echo(f"version {instance.version}")
|
||||
|
||||
click.echo()
|
||||
|
||||
settings_path = settings.get_settings_path()
|
||||
if path.exists(settings_path):
|
||||
click.echo(f"Settings file: {settings_path}")
|
||||
if include_files:
|
||||
with open(settings_path, "r") as f:
|
||||
click.echo("\n```toml")
|
||||
click.echo(f.read().strip())
|
||||
click.echo("```\n")
|
||||
else:
|
||||
click.echo(f'Settings file: {yellow("not found")}')
|
||||
|
||||
config_path = config.get_config_file_path()
|
||||
if path.exists(config_path):
|
||||
click.echo(f"Config file: {config_path}")
|
||||
if include_files:
|
||||
with open(config_path, "r") as f:
|
||||
content = json.load(f)
|
||||
for app in content.get("apps", {}).values():
|
||||
app["client_id"] = "*****"
|
||||
app["client_secret"] = "*****"
|
||||
for user in content.get("users", {}).values():
|
||||
user["access_token"] = "*****"
|
||||
click.echo("\n```json")
|
||||
click.echo(json.dumps(content, indent=4))
|
||||
click.echo("```\n")
|
||||
else:
|
||||
click.echo(f'Config file: {yellow("not found")}')
|
||||
|
||||
|
||||
# Shorthand functions for coloring output
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user