mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-20 15:35:05 +00:00
CDN script fixes (#412)
This commit is contained in:
parent
7918451699
commit
0df6b78bd6
@ -4,6 +4,7 @@ import configparser
|
|||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
import json
|
import json
|
||||||
import shutil
|
import shutil
|
||||||
|
from configparser import ConfigParser, RawConfigParser
|
||||||
|
|
||||||
VERBOSE = False
|
VERBOSE = False
|
||||||
DEVICES_FOLDER = "Boards"
|
DEVICES_FOLDER = "Boards"
|
||||||
@ -69,9 +70,32 @@ def exit_with_error(message):
|
|||||||
|
|
||||||
def read_properties_file(path):
|
def read_properties_file(path):
|
||||||
config = configparser.RawConfigParser()
|
config = configparser.RawConfigParser()
|
||||||
|
# Don't convert keys to lowercase
|
||||||
|
config.optionxform = str
|
||||||
config.read(path)
|
config.read(path)
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
def get_property_or_none(properties: RawConfigParser, group: str, key: str):
|
||||||
|
if group not in properties.sections():
|
||||||
|
return None
|
||||||
|
if key not in properties[group].keys():
|
||||||
|
return None
|
||||||
|
return properties[group][key]
|
||||||
|
|
||||||
|
def get_boolean_property_or_false(properties: RawConfigParser, group: str, key: str):
|
||||||
|
if group not in properties.sections():
|
||||||
|
return False
|
||||||
|
if key not in properties[group].keys():
|
||||||
|
return False
|
||||||
|
return properties[group][key] == "true"
|
||||||
|
|
||||||
|
def get_property_or_exit(properties: RawConfigParser, group: str, key: str):
|
||||||
|
if group not in properties.sections():
|
||||||
|
exit_with_error(f"Device properties does not contain group: {group}")
|
||||||
|
if key not in properties[group].keys():
|
||||||
|
exit_with_error(f"Device properties does not contain key: {key}")
|
||||||
|
return properties[group][key]
|
||||||
|
|
||||||
def read_device_properties(device_id):
|
def read_device_properties(device_id):
|
||||||
mapping_file_path = os.path.join(DEVICES_FOLDER, device_id, "device.properties")
|
mapping_file_path = os.path.join(DEVICES_FOLDER, device_id, "device.properties")
|
||||||
if not os.path.isfile(mapping_file_path):
|
if not os.path.isfile(mapping_file_path):
|
||||||
@ -106,18 +130,21 @@ def to_manifest_chip_name(name):
|
|||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
def process_device(in_path: str, out_path: str, device_directory: str, device_id: str, device_properties: configparser, version: str):
|
def process_device(in_path: str, out_path: str, device_directory: str, device_id: str, device_properties: RawConfigParser, version: str):
|
||||||
in_device_path = os.path.join(in_path, device_directory)
|
in_device_path = os.path.join(in_path, device_directory)
|
||||||
in_device_binaries_path = os.path.join(in_device_path, "Binaries")
|
in_device_binaries_path = os.path.join(in_device_path, "Binaries")
|
||||||
assert os.path.isdir(in_device_binaries_path)
|
if not os.path.isdir(in_device_binaries_path):
|
||||||
|
exit_with_error(f"Could not find directory {in_device_binaries_path}")
|
||||||
flasher_args_path = os.path.join(in_device_binaries_path, "flasher_args.json")
|
flasher_args_path = os.path.join(in_device_binaries_path, "flasher_args.json")
|
||||||
assert os.path.isfile(flasher_args_path)
|
if not os.path.isfile(flasher_args_path):
|
||||||
|
exit_with_error(f"Could not find flasher arguments path {flasher_args_path}")
|
||||||
with open(flasher_args_path) as json_data:
|
with open(flasher_args_path) as json_data:
|
||||||
flasher_args = json.load(json_data)
|
flasher_args = json.load(json_data)
|
||||||
json_data.close()
|
|
||||||
flash_files = flasher_args["flash_files"]
|
flash_files = flasher_args["flash_files"]
|
||||||
|
device_vendor = get_property_or_exit(device_properties, "general", "vendor")
|
||||||
|
device_name = get_property_or_exit(device_properties, "general", "name")
|
||||||
manifest = Manifest(
|
manifest = Manifest(
|
||||||
name=f"Tactility for {device_properties["general"]["vendor"]} {device_properties["general"]["name"]}",
|
name=f"Tactility for {device_vendor} {device_name}",
|
||||||
version=version,
|
version=version,
|
||||||
new_install_prompt_erase="true",
|
new_install_prompt_erase="true",
|
||||||
funding_url="https://github.com/sponsors/ByteWelder",
|
funding_url="https://github.com/sponsors/ByteWelder",
|
||||||
@ -143,11 +170,9 @@ def process_device(in_path: str, out_path: str, device_directory: str, device_id
|
|||||||
offset=int(offset, 16)
|
offset=int(offset, 16)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
json_manifest_path = os.path.join(out_path, f"{device_id}.json")
|
json_manifest_path = os.path.join(out_path, f"{device_id}.json")
|
||||||
with open(json_manifest_path, 'w') as json_manifest_file:
|
with open(json_manifest_path, 'w') as json_manifest_file:
|
||||||
json.dump(asdict(manifest), json_manifest_file, indent=2)
|
json.dump(asdict(manifest), json_manifest_file, indent=2)
|
||||||
json_manifest_file.close()
|
|
||||||
|
|
||||||
def main(in_path: str, out_path: str, version: str):
|
def main(in_path: str, out_path: str, version: str):
|
||||||
if not os.path.exists(in_path):
|
if not os.path.exists(in_path):
|
||||||
@ -158,39 +183,29 @@ def main(in_path: str, out_path: str, version: str):
|
|||||||
device_directories = os.listdir(in_path)
|
device_directories = os.listdir(in_path)
|
||||||
device_index = DeviceIndex(version, [])
|
device_index = DeviceIndex(version, [])
|
||||||
for device_directory in device_directories:
|
for device_directory in device_directories:
|
||||||
if not device_directory.endswith("-symbols"):
|
if device_directory.endswith("-symbols"):
|
||||||
device_id = device_directory[10:]
|
continue
|
||||||
device_properties = read_device_properties(device_id)
|
device_id = device_directory.removeprefix("Tactility-")
|
||||||
device_properties_general = device_properties["general"]
|
if not device_id:
|
||||||
process_device(in_path, out_path, device_directory, device_id, device_properties, version)
|
exit_with_error(f"Cannot derive device id from directory: {device_directory}")
|
||||||
if device_properties.has_section("cdn"):
|
device_properties = read_device_properties(device_id)
|
||||||
device_properties_cdn = device_properties["cdn"]
|
process_device(in_path, out_path, device_directory, device_id, device_properties, version)
|
||||||
if "warningMessage" in device_properties_cdn.keys():
|
warning_message = get_property_or_none(device_properties, "cdn", "warningMessage")
|
||||||
warning_message = device_properties_cdn["warningMessage"]
|
info_message = get_property_or_none(device_properties, "cdn", "infoMessage")
|
||||||
else:
|
incubating = get_boolean_property_or_false(device_properties, "general", "incubating")
|
||||||
warning_message = None
|
device_names = get_property_or_exit(device_properties, "general", "name").split(',')
|
||||||
if "infoMessage" in device_properties_cdn.keys():
|
for device_name in device_names:
|
||||||
info_message = device_properties_cdn["infoMessage"]
|
device_index.devices.append(asdict(IndexEntry(
|
||||||
else:
|
id=device_id,
|
||||||
info_message = None
|
name=device_name.strip(),
|
||||||
if "incubating" in device_properties_general.keys():
|
vendor=get_property_or_exit(device_properties, "general", "vendor"),
|
||||||
incubating = device_properties_general["incubating"].lower() == 'true'
|
incubating=incubating,
|
||||||
else:
|
warningMessage=warning_message,
|
||||||
incubating = False
|
infoMessage=info_message
|
||||||
device_names = device_properties_general["name"].split(',')
|
)))
|
||||||
for device_name in device_names:
|
|
||||||
device_index.devices.append(asdict(IndexEntry(
|
|
||||||
id=device_id,
|
|
||||||
name=device_name,
|
|
||||||
vendor=device_properties_general["vendor"],
|
|
||||||
incubating=incubating,
|
|
||||||
warningMessage=warning_message,
|
|
||||||
infoMessage=info_message
|
|
||||||
)))
|
|
||||||
index_file_path = os.path.join(out_path, "index.json")
|
index_file_path = os.path.join(out_path, "index.json")
|
||||||
with open(index_file_path, "w") as index_file:
|
with open(index_file_path, "w") as index_file:
|
||||||
json.dump(asdict(device_index), index_file, indent=2)
|
json.dump(asdict(device_index), index_file, indent=2)
|
||||||
index_file.close()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("Tactility CDN File Generator")
|
print("Tactility CDN File Generator")
|
||||||
|
|||||||
@ -37,7 +37,6 @@ def get_properties_file_path(device_id: str):
|
|||||||
def read_file(path: str):
|
def read_file(path: str):
|
||||||
with open(path, "r") as file:
|
with open(path, "r") as file:
|
||||||
result = file.read()
|
result = file.read()
|
||||||
file.close()
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def read_properties_file(path):
|
def read_properties_file(path):
|
||||||
@ -229,7 +228,6 @@ def main(device_id: str, is_dev: bool):
|
|||||||
device_properties = read_device_properties(device_id)
|
device_properties = read_device_properties(device_id)
|
||||||
with open(output_file_path, "w") as output_file:
|
with open(output_file_path, "w") as output_file:
|
||||||
write_properties(output_file, device_properties, device_id, is_dev)
|
write_properties(output_file, device_properties, device_id, is_dev)
|
||||||
output_file.close()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if "--help" in sys.argv:
|
if "--help" in sys.argv:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user