Created
December 25, 2025 19:29
-
-
Save Bugaddr/27cda461cf7225b2ac963cbae13a457d to your computer and use it in GitHub Desktop.
A small CLI utility that scans /etc/thermal-conf.xml* files, extracts thermal zone sensors and trip temperatures, groups identical configurations, and prints a neatly wrapped, terminal-width–aware audit table showing PPCC status, configurations, and source files.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import sys | |
| import glob | |
| import xml.etree.ElementTree as ET | |
| import textwrap | |
| from collections import defaultdict | |
| def parse_thermal_xml(file_path): | |
| try: | |
| with open(file_path, 'r') as f: | |
| content = f.read() | |
| start_idx = content.find('<ThermalConfiguration>') | |
| end_idx = content.find('</ThermalConfiguration>') + len('</ThermalConfiguration>') | |
| if start_idx == -1: return None | |
| root = ET.fromstring(content[start_idx:end_idx]) | |
| platform = root.find('Platform') | |
| if platform is None: return None | |
| ppcc = "Yes" if platform.find('PPCC') is not None else "No" | |
| zones = [] | |
| for zone in platform.find('ThermalZones').findall('ThermalZone'): | |
| sensor = zone.find('.//SensorType').text | |
| trips = [f"{int(t.text)//1000}°C" for t in zone.findall('.//Temperature')] | |
| zones.append(f"{sensor}:({','.join(trips)})") | |
| return (ppcc, " | ".join(zones)) | |
| except: | |
| return None | |
| def generate_wrapped_table(grouped_data): | |
| try: | |
| term_width = os.get_terminal_size().columns | |
| except OSError: | |
| term_width = 100 # Fallback for non-TTY or small screens | |
| headers = ["Grp", "PPCC", "Configuration (Sensor:Trips)", "Source Files"] | |
| # Define fixed widths for small columns | |
| col0_w, col1_w = 4, 5 | |
| # Calculate available space for the two large data columns | |
| available_w = term_width - (col0_w + col1_w + 13) # 13 = padding and borders | |
| col2_w = int(available_w * 0.6) | |
| col3_w = int(available_w * 0.4) | |
| widths = [col0_w, col1_w, col2_w, col3_w] | |
| sep = "+" + "+".join("-" * (w + 2) for w in widths) + "+" | |
| header_row = "|" + "|".join(f" {headers[i]:<{widths[i]}} " for i in range(4)) + "|" | |
| print(f"\n[Thermal Config Audit] Terminal Width: {term_width}") | |
| print(sep) | |
| print(header_row) | |
| print(sep.replace("-", "=")) | |
| for i, (config, files) in enumerate(grouped_data.items(), 1): | |
| ppcc, zones_str = config | |
| files_str = ", ".join(sorted(files, key=lambda x: x.split('.')[-1])) | |
| # Wrap the long text into lists of lines | |
| wrapped_config = textwrap.wrap(zones_str, width=col2_w) | |
| wrapped_files = textwrap.wrap(files_str, width=col3_w) | |
| # Determine how many lines this row needs | |
| max_lines = max(len(wrapped_config), len(wrapped_files), 1) | |
| for line_idx in range(max_lines): | |
| c0 = str(i) if line_idx == 0 else "" | |
| c1 = ppcc if line_idx == 0 else "" | |
| c2 = wrapped_config[line_idx] if line_idx < len(wrapped_config) else "" | |
| c3 = wrapped_files[line_idx] if line_idx < len(wrapped_files) else "" | |
| print(f"| {c0:<{col0_w}} | {c1:<{col1_w}} | {c2:<{col2_w}} | {c3:<{col3_w}} |") | |
| print(sep) | |
| def main(): | |
| target_dir = sys.argv[1] if len(sys.argv) > 1 else "." | |
| all_files = glob.glob(os.path.join(target_dir, "thermal-conf.xml*")) | |
| config_groups = defaultdict(list) | |
| for f_path in all_files: | |
| config = parse_thermal_xml(f_path) | |
| if config: | |
| config_groups[config].append(os.path.basename(f_path)) | |
| if not config_groups: | |
| print("No valid thermal configurations found.") | |
| else: | |
| generate_wrapped_table(config_groups) | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment