cli: add --all for doctor/modules command
This commit is contained in:
parent
4b49add746
commit
3b9941e9ee
2 changed files with 33 additions and 15 deletions
|
@ -63,8 +63,11 @@ def eprint(x: str):
|
||||||
def indent(x: str) -> str:
|
def indent(x: str) -> str:
|
||||||
return ''.join(' ' + l for l in x.splitlines(keepends=True))
|
return ''.join(' ' + l for l in x.splitlines(keepends=True))
|
||||||
|
|
||||||
|
OK = '✅'
|
||||||
|
OFF = '🔲'
|
||||||
|
|
||||||
def info(x: str):
|
def info(x: str):
|
||||||
eprint('✅ ' + x)
|
eprint(OK + ' ' + x)
|
||||||
|
|
||||||
def error(x: str):
|
def error(x: str):
|
||||||
eprint('❌ ' + x)
|
eprint('❌ ' + x)
|
||||||
|
@ -135,17 +138,29 @@ def config_check(args):
|
||||||
sys.stderr.write(indent(mres.stdout.decode('utf8')))
|
sys.stderr.write(indent(mres.stdout.decode('utf8')))
|
||||||
|
|
||||||
|
|
||||||
|
def _modules(all=False):
|
||||||
|
from .util import modules
|
||||||
|
skipped = []
|
||||||
|
for m in modules():
|
||||||
|
if not all and m.skip_reason is not None:
|
||||||
|
skipped.append(m.name)
|
||||||
|
else:
|
||||||
|
yield m
|
||||||
|
if len(skipped) > 0:
|
||||||
|
warning(f'Skipped {len(skipped)} modules: {skipped}. Pass --all if you want to see them.')
|
||||||
|
|
||||||
|
|
||||||
def modules_check(args):
|
def modules_check(args):
|
||||||
verbose: bool = args.verbose
|
verbose: bool = args.verbose
|
||||||
module: Optional[str] = args.module
|
module: Optional[str] = args.module
|
||||||
vw = '' if verbose else '; pass --verbose to print more information'
|
vw = '' if verbose else '; pass --verbose to print more information'
|
||||||
|
|
||||||
from .util import get_stats, HPIModule, modules
|
from .util import get_stats, HPIModule
|
||||||
from .core_config import config
|
from .core_config import config
|
||||||
|
|
||||||
mods: Iterable[HPIModule]
|
mods: Iterable[HPIModule]
|
||||||
if module is None:
|
if module is None:
|
||||||
mods = modules()
|
mods = _modules(all=args.all)
|
||||||
else:
|
else:
|
||||||
mods = [HPIModule(name=module, skip_reason=None)]
|
mods = [HPIModule(name=module, skip_reason=None)]
|
||||||
|
|
||||||
|
@ -154,19 +169,19 @@ def modules_check(args):
|
||||||
skip = mr.skip_reason
|
skip = mr.skip_reason
|
||||||
m = mr.name
|
m = mr.name
|
||||||
if skip is not None:
|
if skip is not None:
|
||||||
eprint(f'🔲 {color.YELLOW}SKIP{color.RESET}: {m:<30} {skip}')
|
eprint(OFF + f' {color.YELLOW}SKIP{color.RESET}: {m:<50} {skip}')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
mod = importlib.import_module(m)
|
mod = importlib.import_module(m)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# todo more specific command?
|
# todo more specific command?
|
||||||
error(f'{color.RED}FAIL{color.RESET}: {m:<30} loading failed{vw}')
|
error(f'{color.RED}FAIL{color.RESET}: {m:<50} loading failed{vw}')
|
||||||
if verbose:
|
if verbose:
|
||||||
tb(e)
|
tb(e)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
info(f'{color.GREEN}OK{color.RESET} : {m:<30}')
|
info(f'{color.GREEN}OK{color.RESET} : {m:<50}')
|
||||||
stats = get_stats(m)
|
stats = get_stats(m)
|
||||||
if stats is None:
|
if stats is None:
|
||||||
continue
|
continue
|
||||||
|
@ -188,16 +203,17 @@ def list_modules(args) -> None:
|
||||||
# todo add a --sort argument?
|
# todo add a --sort argument?
|
||||||
from .core_config import config
|
from .core_config import config
|
||||||
|
|
||||||
# todo add an active_modules() method? would be useful for doctor?
|
for mr in _modules(all=args.all):
|
||||||
from .util import modules
|
|
||||||
for mr in modules():
|
|
||||||
m = mr.name
|
m = mr.name
|
||||||
skip = mr.skip_reason
|
sr = mr.skip_reason
|
||||||
|
if sr is None:
|
||||||
|
pre = OK
|
||||||
|
suf = ''
|
||||||
|
else:
|
||||||
|
pre = OFF
|
||||||
|
suf = f' {color.YELLOW}[disabled: {sr}]{color.RESET}'
|
||||||
|
|
||||||
active = skip is None
|
print(f'{pre} {m:50}{suf}')
|
||||||
# todo maybe reorder? (e.g. enabled first/last)? or/and color?
|
|
||||||
# todo maybe use [off] / [ON] so it's easier to distinguish visually?
|
|
||||||
print(f'- {m:50}' + ('' if active else f' {color.YELLOW}[disabled]{color.RESET}'))
|
|
||||||
|
|
||||||
|
|
||||||
# todo check that it finds private modules too?
|
# todo check that it finds private modules too?
|
||||||
|
@ -216,6 +232,7 @@ Work in progress, will be used for config management, troubleshooting & introspe
|
||||||
sp = p.add_subparsers(dest='mode')
|
sp = p.add_subparsers(dest='mode')
|
||||||
dp = sp.add_parser('doctor', help='Run various checks')
|
dp = sp.add_parser('doctor', help='Run various checks')
|
||||||
dp.add_argument('--verbose', action='store_true', help='Print more diagnosic infomration')
|
dp.add_argument('--verbose', action='store_true', help='Print more diagnosic infomration')
|
||||||
|
dp.add_argument('--all' , action='store_true', help='List all modules, including disabled')
|
||||||
dp.add_argument('module', nargs='?', type=str , help='Pass to check a specific module')
|
dp.add_argument('module', nargs='?', type=str , help='Pass to check a specific module')
|
||||||
dp.set_defaults(func=doctor)
|
dp.set_defaults(func=doctor)
|
||||||
|
|
||||||
|
@ -229,6 +246,7 @@ Work in progress, will be used for config management, troubleshooting & introspe
|
||||||
icp.set_defaults(func=config_create)
|
icp.set_defaults(func=config_create)
|
||||||
|
|
||||||
mp = sp.add_parser('modules', help='List available modules')
|
mp = sp.add_parser('modules', help='List available modules')
|
||||||
|
mp.add_argument('--all' , action='store_true', help='List all modules, including disabled')
|
||||||
mp.set_defaults(func=list_modules)
|
mp.set_defaults(func=list_modules)
|
||||||
|
|
||||||
return p
|
return p
|
||||||
|
|
|
@ -41,7 +41,7 @@ def ignored(m: str) -> bool:
|
||||||
'bluemaestro.check',
|
'bluemaestro.check',
|
||||||
'location.__main__',
|
'location.__main__',
|
||||||
'photos.utils',
|
'photos.utils',
|
||||||
'books',
|
'books.kobo',
|
||||||
'coding',
|
'coding',
|
||||||
'media',
|
'media',
|
||||||
'reading',
|
'reading',
|
||||||
|
|
Loading…
Add table
Reference in a new issue