devices/cli: make device list way more readable, add package name and path, mark currently selected
This commit is contained in:
parent
5edfac42ce
commit
63156776a2
3 changed files with 49 additions and 6 deletions
|
@ -135,7 +135,7 @@ def prompt_profile_device(current: Optional[str], profile_name: str) -> tuple[st
|
||||||
devices = get_devices()
|
devices = get_devices()
|
||||||
print(click.style("Pick your device!\nThese are the available devices:", bold=True))
|
print(click.style("Pick your device!\nThese are the available devices:", bold=True))
|
||||||
for dev in sorted(devices.keys()):
|
for dev in sorted(devices.keys()):
|
||||||
print(devices[dev])
|
print(f"{devices[dev]}\n")
|
||||||
return prompt_choice(current, f'profiles.{profile_name}.device', devices.keys())
|
return prompt_choice(current, f'profiles.{profile_name}.device', devices.keys())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
import click
|
import click
|
||||||
|
import logging
|
||||||
|
|
||||||
from .device import get_devices
|
from config.state import config
|
||||||
|
|
||||||
|
from .device import get_devices, get_profile_device
|
||||||
|
|
||||||
|
|
||||||
@click.command(name='devices')
|
@click.command(name='devices')
|
||||||
|
@ -9,5 +12,29 @@ def cmd_devices():
|
||||||
devices = get_devices()
|
devices = get_devices()
|
||||||
if not devices:
|
if not devices:
|
||||||
raise Exception("No devices found!")
|
raise Exception("No devices found!")
|
||||||
for d in sorted(devices.keys()):
|
profile_device = None
|
||||||
print(devices[d])
|
try:
|
||||||
|
dev = get_profile_device()
|
||||||
|
assert dev
|
||||||
|
profile_device = dev
|
||||||
|
except Exception as ex:
|
||||||
|
logging.debug(f"Failed to get profile device for visual highlighting, not a problem: {ex}")
|
||||||
|
output = ['']
|
||||||
|
for name in sorted(devices.keys()):
|
||||||
|
prefix = ''
|
||||||
|
suffix = ''
|
||||||
|
device = devices[name]
|
||||||
|
assert device
|
||||||
|
try:
|
||||||
|
device.parse_deviceinfo(try_download=False)
|
||||||
|
except Exception as ex:
|
||||||
|
logging.debug(f"Failed to parse deviceinfo for extended description, not a problem: {ex}")
|
||||||
|
if profile_device and profile_device.name == device.name:
|
||||||
|
prefix = '>>> '
|
||||||
|
suffix = f'\n\nCurrently selected by profile "{config.file.profiles.current}"'
|
||||||
|
snippet = f'{device}{suffix}'
|
||||||
|
# prefix each line in the snippet
|
||||||
|
snippet = '\n'.join([f'{prefix}{line}' for line in snippet.split('\n')])
|
||||||
|
output.append(f"{snippet}\n")
|
||||||
|
for line in output:
|
||||||
|
print(line)
|
||||||
|
|
|
@ -30,8 +30,24 @@ class Device(DataClass):
|
||||||
deviceinfo: Optional[DeviceInfo]
|
deviceinfo: Optional[DeviceInfo]
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return (f'Device "{self.name}": "{self.package.description if self.package else ""}", '
|
return f'Device<{self.name},{self.arch},{self.package.path if self.package else "[no package]"}>'
|
||||||
f'Architecture: {self.arch}, package: {self.package.name if self.package else "??? PROBABLY A BUG!"}')
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.get_summary_str(newlines=True)
|
||||||
|
|
||||||
|
def get_summary_str(self, newlines: bool = False):
|
||||||
|
separator = '\n' if newlines else ', '
|
||||||
|
description = (
|
||||||
|
(self.package.description if self.package else "").strip() or
|
||||||
|
(self.deviceinfo.get("name", "[No name in deviceinfo]") if self.deviceinfo else "")
|
||||||
|
).strip()
|
||||||
|
description = description or f"[no package {'description' if self.package else 'associated (?!)'} and deviceinfo not parsed]"
|
||||||
|
return separator.join([
|
||||||
|
f'Device: {self.name}',
|
||||||
|
f'Description: {description}',
|
||||||
|
f'Architecture: {self.arch}',
|
||||||
|
'Package Name: ' + (f"{self.package.name}{separator}Package Path: {self.package.path}" if self.package else "??? PROBABLY A BUG!"),
|
||||||
|
])
|
||||||
|
|
||||||
def parse_deviceinfo(self, try_download: bool = True, lazy: bool = True):
|
def parse_deviceinfo(self, try_download: bool = True, lazy: bool = True):
|
||||||
if not lazy or 'deviceinfo' not in self or self.deviceinfo is None:
|
if not lazy or 'deviceinfo' not in self or self.deviceinfo is None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue