Refactor generate-sku-list.py
parent
5935e5f43c
commit
b84259e08f
|
@ -1,37 +1,50 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
variants = []
|
def format_skus(sku_ids, suffix):
|
||||||
sku_ids = {}
|
sku_ids_formatted = ""
|
||||||
|
for sku in sku_ids[suffix]:
|
||||||
|
if sku_ids_formatted == "":
|
||||||
|
sku_ids_formatted = sku
|
||||||
|
else:
|
||||||
|
sku_ids_formatted = f"{sku_ids_formatted}|{sku}"
|
||||||
|
return sku_ids_formatted
|
||||||
|
|
||||||
with open("project-config.json", "r") as project:
|
def load_project_config():
|
||||||
p_json = json.load(project)
|
with open("project-config.json", "r") as project:
|
||||||
|
project_json = json.load(project)
|
||||||
|
return project_json['chromeos']['configs']
|
||||||
|
|
||||||
configs = p_json['chromeos']['configs']
|
def select_variant(configs):
|
||||||
|
variants = []
|
||||||
|
print("Variants:")
|
||||||
|
for config in configs:
|
||||||
|
if config['name'] in variants:
|
||||||
|
continue
|
||||||
|
variants.append(config['name'])
|
||||||
|
print(config['name'])
|
||||||
|
return input("Choose a variant: ")
|
||||||
|
|
||||||
print("Variants:")
|
def parse_sku_ids(configs, variant):
|
||||||
for config in configs:
|
sku_ids = {}
|
||||||
variant = config['name']
|
for config in configs:
|
||||||
if not variant in variants:
|
if variant not in config['audio']['main']['cras-config-dir']:
|
||||||
variants.append(variant)
|
continue
|
||||||
print(variant)
|
if config['audio']['main']['ucm-suffix'] not in sku_ids:
|
||||||
|
|
||||||
variant = input("Choose a variant: ")
|
|
||||||
|
|
||||||
for config in configs:
|
|
||||||
if config['audio']['main']['cras-config-dir'] == variant:
|
|
||||||
if not config['audio']['main']['ucm-suffix'] in sku_ids:
|
|
||||||
sku_ids[config['audio']['main']['ucm-suffix']] = []
|
sku_ids[config['audio']['main']['ucm-suffix']] = []
|
||||||
sku_ids[config['audio']['main']['ucm-suffix']].append(config['identity']['sku-id'])
|
sku_ids[config['audio']['main']['ucm-suffix']].append(config['identity']['sku-id'])
|
||||||
|
return sku_ids
|
||||||
|
|
||||||
for suffix in sku_ids:
|
def print_sku_id_list(sku_ids):
|
||||||
suffixes_formatted = ""
|
for suffix in sku_ids:
|
||||||
for sku in sku_ids[suffix]:
|
sku_ids_formatted = format_skus(sku_ids, suffix)
|
||||||
if suffixes_formatted == "":
|
print(f"{suffix}: {sku_ids_formatted}")
|
||||||
suffixes_formatted = str(sku)
|
|
||||||
else:
|
def main():
|
||||||
suffixes_formatted = f"{suffixes_formatted}|{str(sku)}"
|
configs = load_project_config()
|
||||||
print(f"{suffix}: {suffixes_formatted}")
|
variant = select_variant(configs)
|
||||||
|
sku_ids = parse_sku_ids(configs, variant)
|
||||||
|
print_sku_id_list(sku_ids)
|
||||||
|
|
||||||
|
main()
|
||||||
|
|
Loading…
Reference in New Issue