SUPPORTED_METADATA_VERSION = 1
+assert sys.version_info >= (3, 5), "Python version too old. Python >=3.5.0 needed."
+
# accepts {<file-path>: <file-content>}
def merge_profiles(profiles, download_url):
title.get("vendor", ""), title["model"], title.get("variant", "")
).strip()
- def add_profile(id, target, profile, code=None):
+ def add_profile(path, id, target, profile, code=None):
images = []
for image in profile["images"]:
images.append({"name": image["name"], "type": image["type"]})
title = get_title(entry)
if len(title) == 0:
- sys.stderr.write("Empty title. Skip title for {}".format(id))
+ sys.stderr.write(
+ "Empty title. Skip title for {} in {}\n".format(id, path)
+ )
continue
output["models"][title] = {"id": id, "target": target, "images": images}
output["models"][title]["code"] = code
for path, content in profiles.items():
- obj = json.loads(content.decode("utf-8"))
+ obj = json.loads(content)
if obj["metadata_version"] != SUPPORTED_METADATA_VERSION:
sys.stderr.write(
- "{} has unsupported metadata version: {} => skip".format(
+ "{} has unsupported metadata version: {} => skip\n".format(
path, obj["metadata_version"]
)
)
try:
if "profiles" in obj:
for id in obj["profiles"]:
- add_profile(id, obj.get("target"), obj["profiles"][id], code)
+ add_profile(path, id, obj.get("target"), obj["profiles"][id], code)
else:
- add_profile(obj["id"], obj["target"], obj, code)
+ add_profile(path, obj["id"], obj["target"], obj, code)
except json.decoder.JSONDecodeError as e:
sys.stderr.write("Skip {}\n {}\n".format(path, e))
except KeyError as e:
def update_config(config_path, versions):
content = ""
- with open(config_path, "r") as file:
+ with open(str(config_path), "r") as file:
content = file.read()
content = re.sub("versions:[\\s]*{[^}]*}", "versions: {}".format(versions), content)
- with open(config_path, "w+") as file:
+ with open(str(config_path), "w+") as file:
file.write(content)
array = json.loads(file.read().decode("utf-8"))
for profile in filter(lambda x: x.endswith("/profiles.json"), array):
with urllib.request.urlopen("{}/{}".format(target, profile)) as file:
- profiles["{}/{}".format(target, profile)] = file.read()
+ profiles["{}/{}".format(target, profile)] = file.read().decode(
+ "utf-8"
+ )
return profiles
if not os.path.isfile(config_path):
profiles = {}
for ppath in Path(path).rglob("profiles.json"):
- with open(ppath, "r") as file:
+ with open(str(ppath), "r") as file:
profiles[ppath] = file.read()
if len(profiles) == 0:
profiles = {}
def add_path(path):
- with open(path, "r") as file:
+ with open(str(path), "r") as file:
profiles[path] = file.read()
for path in input_paths:
profiles = {}
for ppath in Path(path).rglob("profiles.json"):
- with open(ppath, "r") as file:
+ with open(str(ppath), "r", encoding="utf-8") as file:
profiles[ppath] = file.read()
if len(profiles) == 0: