Commit 143a8df1 authored by José Henrique's avatar José Henrique
Browse files

Sanitize deprecated versions

parent 874797e8
......@@ -6,11 +6,12 @@ import operator
os.chdir('official_devices')
SUGGESTIONS = []
ALLOWED_VERSIONS = ['eleven', 'eleven_plus', 'ten', 'ten_plus', 'pie', 'pie_plus']
ALLOWED_VERSIONS = ['eleven', 'eleven_plus', 'ten', 'ten_plus']
REQUIRED_PARAMS_DEVICE = ['name', 'brand', 'codename', 'supported_versions', 'repositories']
REQUIRED_PARAMS_DEVICE_LIST = ['supported_versions', 'repositories']
REQUIRED_PARAMS_TEAM_MEMBER = ['name', 'country', 'github_username', 'devices', 'ci_username']
REQUIRED_PARAMS_TEAM_MEMBER_DEVICE = ['codename', 'versions']
DEPRECATED_VERSIONS = ['ten', 'ten_plus']
def test_integrity_devices():
......@@ -89,6 +90,15 @@ def test_integrity_team():
def sanitize_username(username):
return ''.join(ch for ch in username.lower() if ch.isalnum())
def is_device_deprecated(device_codename, version, devices):
for device in devices:
if device["codename"] == device_codename:
for supported_version in device["supported_versions"]:
if supported_version["version_code"] == version:
return "deprecated" in supported_version and supported_version["deprecated"]
return False
def format_json():
# Load JSON's
devices = json.loads(open('devices.json', 'r').read())
......@@ -101,6 +111,30 @@ def format_json():
for member in roles:
member["ci_username"] = sanitize_username(member["ci_username"])
# Sanitize github_username
for roles in [core, maintainers]:
for member in roles:
member["github_username"] = sanitize_username(member["github_username"])
# Sanitize deprecated versions
for roles in [core, maintainers]:
for member in roles:
devices_to_remove = []
for device in member["devices"]:
versions_to_remove = []
for version in device["versions"]:
if version not in versions_to_remove:
if is_device_deprecated(device["codename"], version, devices):
versions_to_remove.append(version)
elif version in DEPRECATED_VERSIONS:
versions_to_remove.append(version)
for version in versions_to_remove:
device["versions"].remove(version)
if not device["versions"]:
devices_to_remove.append(device)
for device in devices_to_remove:
member["devices"].remove(device)
# Sort JSON alphabetically with selected keys
devices = sorted(devices, key=operator.itemgetter('codename', 'brand'))
core = sorted(core, key=operator.itemgetter('name', 'country'))
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment