From 1fede74e11bb0993e0e86a8f3e2dca74a6a08d9a Mon Sep 17 00:00:00 2001 From: thingsboard017 Date: Mon, 23 Dec 2024 12:45:52 +0200 Subject: [PATCH] Updated the validation script by adding checks for vendors' photo and info files. --- data_converters_validator.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/data_converters_validator.py b/data_converters_validator.py index 8d38e136..c3967404 100644 --- a/data_converters_validator.py +++ b/data_converters_validator.py @@ -182,6 +182,38 @@ def validate_device_files(device_path): return True +def validate_company_files(company_path): + required_files = ['logo.svg', 'info.json'] + all_present = True + + for file in required_files: + file_path = os.path.join(company_path, file) + if not os.path.exists(file_path): + print(f"Validation failed: Missing '{file}' in {company_path}") + all_present = False + + if "info.json" in required_files: + info_path = os.path.join(company_path, "info.json") + if os.path.exists(info_path): + with open(info_path, 'r') as f: + try: + data = json.load(f) + except json.JSONDecodeError: + print(f"Validation failed: 'info.json' in {company_path} is not valid JSON") + return False + + allowed_keys = {"description", "url"} + if set(data.keys()) != allowed_keys: + print(f"Validation failed: 'info.json' in {company_path} contains invalid keys. Allowed keys are {allowed_keys}.") + return False + + for key in allowed_keys: + if not data[key] or not isinstance(data[key], str): + print(f"Validation failed: '{key}' in 'info.json' in {company_path} is missing or empty.") + return False + + return all_present + def walk_vendors_directory(root_dir): all_success = True @@ -191,6 +223,10 @@ def walk_vendors_directory(root_dir): if not os.path.isdir(company_path): continue + if not validate_company_files(company_path): + all_success = False + continue + for device in os.listdir(company_path): device_path = os.path.join(company_path, device)