Skip to content

Commit

Permalink
Merge pull request #176 from thingsboard/fix-validation-script
Browse files Browse the repository at this point in the history
Updated the validation script
  • Loading branch information
ViacheslavKlimov authored Dec 23, 2024
2 parents 8a9eeb8 + 1fede74 commit 4c32451
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions data_converters_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit 4c32451

Please sign in to comment.