utils: gen-debug-controls: Improve log output

Add log statements for found controls and the file written. This makes
it easier to understand what happens under the hood.

While at it, create nice colored log out put using coloredlogs if
available.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
This commit is contained in:
Stefan Klug
2025-07-07 10:55:06 +02:00
parent 8fa1d608c3
commit 6630533c8d

View File

@@ -17,8 +17,13 @@ import sys
from dataclasses import dataclass
from pathlib import Path
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO, format='%(levelname)s: %(message)s')
fmt = '%(levelname)s: %(message)s'
try:
import coloredlogs
coloredlogs.install(level=logging.INFO, fmt=fmt)
except ImportError:
logging.basicConfig(level=logging.INFO, format=fmt)
try:
import ruamel.yaml as ruyaml
@@ -27,6 +32,8 @@ except:
f'Failed to import ruamel.yaml. Please install the ruamel.yaml package.')
sys.exit(1)
logger = logging.getLogger(__name__)
@dataclass
class FoundMatch:
file: os.PathLike
@@ -106,6 +113,7 @@ def main(argv):
continue
p = m.file.relative_to(root_dir)
logger.info(f"Found control {m.name} in {p}")
desc = {'type': m.type,
'direction': 'out',
'description': f'Debug control {m.name} found in {p}'}
@@ -165,6 +173,9 @@ def main(argv):
"#\n"))
yaml.dump(doc, f)
p = ctrl_file.relative_to(Path.cwd(), walk_up=True)
logger.info(f"Sucessfully updated {p}")
return 0