From 8bf10139e59438d7b2f34daf506be7313aac4eec Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 27 Sep 2024 18:07:48 +0200 Subject: [PATCH] add legacy mode make workbench-script compatible with the old devicehub --- settings.ini.example | 1 + workbench-script.py | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/settings.ini.example b/settings.ini.example index 81dac5e..a51397b 100644 --- a/settings.ini.example +++ b/settings.ini.example @@ -4,3 +4,4 @@ token = '1234' # path = /path/to/save # device = your_device_name # # erase = basic +# legacy = true diff --git a/workbench-script.py b/workbench-script.py index 743a505..3cf9e12 100644 --- a/workbench-script.py +++ b/workbench-script.py @@ -13,6 +13,31 @@ import requests from datetime import datetime +## Legacy Functions ## +def convert_to_legacy_snapshot(snapshot): + snapshot["sid"] = str(uuid.uuid4()).split("-")[0] + snapshot["software"] = "UsodyOS" + snapshot["version"] = "2023.4.0-alpha" + snapshot["schema_api"] = "1.0.0" + snapshot["settings_version"] = "No Settings Version (NaN)" + snapshot["timestamp"] = snapshot["timestamp"].replace(" ", "T") + snapshot["tests"] = [] + snapshot["sanitize"] = [] + snapshot["hwmd"] = { + "hwmd_version": "1.1.0-alpha", + "lshw": snapshot["data"].get("lshw", ""), + "hwinfo": snapshot["data"].get("hwinfo", ""), + "smart": snapshot["data"].get("smart", ""), + "dmidecode": snapshot["data"].get("dmidecode", ""), + "lspci": snapshot["data"].get("lspci", "") + } + snapshot.pop("data") + snapshot.pop("code") + snapshot.pop("erase") + +## End Legacy Functions ## + + ## Utility Functions ## def logs(f): def wrapper(*args, **kwargs): @@ -309,17 +334,19 @@ def load_config(config_file="settings.ini"): # TODO validate that the device exists? device = config.get('settings', 'device', fallback=None) erase = config.get('settings', 'erase', fallback=None) + legacy = config.get('settings', 'legacy', fallback=None) else: print(f"workbench: ERROR: Config file '{config_file}' not found. Using default values.") path = os.path.join(os.getcwd()) - url, token, device, erase = None, None, None, None + url, token, device, erase, legacy = None, None, None, None, None return { 'path': path, 'url': url, 'token': token, 'device': device, - 'erase': erase + 'erase': erase, + 'legacy': legacy } def parse_args(): @@ -354,11 +381,14 @@ def main(): all_disks = get_disks() snapshot = gen_snapshot(all_disks) - if config['erase'] and config['device']: + if config['erase'] and config['device'] and not config.get("legacy"): snapshot['erase'] = gen_erase(all_disks, config['erase'], user_disk=config['device']) - elif config['erase']: + elif config['erase'] and not config.get("legacy"): snapshot['erase'] = gen_erase(all_disks, config['erase']) + if config.get("legacy"): + convert_to_legacy_snapshot(snapshot) + save_snapshot_in_disk(snapshot, config['path']) if config['url']: