From 9047dedb594597a566f0ac3bc49982f1628c019d Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Sun, 24 May 2020 13:59:57 +0200 Subject: [PATCH] collect.py: support new format --- misc/collect.py | 69 +++++++++++++++++++++++++------------------------ 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/misc/collect.py b/misc/collect.py index f5f2556..bb7b3ae 100755 --- a/misc/collect.py +++ b/misc/collect.py @@ -42,52 +42,53 @@ def get_title_name(title): else: return "{} {} {}".format(title.get('vendor', ''), title['model'], title.get('variant', '')).strip() -# json output data -output = {} -for path in paths: - with open(path, "r") as file: - try: - obj = json.load(file) +def add_profile(id, target, profile): + images = [] + for image in profile['images']: + images.append({'name': image['name'], 'type': image['type']}) - if obj['metadata_version'] != SUPPORTED_METADATA_VERSION: - sys.stderr.write('{} has unsupported metadata version: {} => skip\n'.format(path, obj['metadata_version'])) - continue + if args.change_prefix: + change_prefix(images, 'openwrt-', args.change_prefix) - code = obj.get('version_code', obj.get('version_commit')) + for title in profile['titles']: + name = get_title_name(title) - if not 'version_code' in output: - output = { - 'version_code': code, - 'url': args.url, - 'models' : {} - } + if len(name) == 0: + sys.stderr.write("Empty title. Skip title in {}\n".format(path)) + continue - # only support a version_number with images of a single version_commit - if output['version_code'] != code: - sys.stderr.write('mixed revisions for a release ({} and {}) => abort\n'.format(output['version_code'], commit)) - exit(1) + output['models'][name] = {'id': id, 'target': target, 'images': images} - images = [] - for image in obj['images']: - images.append({'name': image['name'], 'type': image['type']}) +for path in paths: + with open(path, "r") as file: + obj = json.load(file) - if args.change_prefix: - change_prefix(images, 'openwrt-', args.change_prefix) + if obj['metadata_version'] != SUPPORTED_METADATA_VERSION: + sys.stderr.write('{} has unsupported metadata version: {} => skip\n'.format(path, obj['metadata_version'])) + continue - target = obj['target'] - id = obj['id'] - for title in obj['titles']: - name = get_title_name(title) + code = obj.get('version_code', obj.get('version_commit')) - if len(name) == 0: - sys.stderr.write("Empty title. Skip title in {}\n".format(path)) - continue + if not 'version_code' in output: + output = { + 'version_code': code, + 'url': args.url, + 'models' : {} + } - output['models'][name] = {'id': id, 'target': target, 'images': images} + # only support a version_number with images of a single version_commit + if output['version_code'] != code: + sys.stderr.write('mixed revisions for a release ({} and {}) => abort\n'.format(output['version_code'], commit)) + exit(1) + try: + if 'profiles' in obj: + for id in obj['profiles']: + add_profile(id, obj['target'], obj['profiles'][id]) + else: + add_profile(obj['id'], obj['target'], obj) except json.decoder.JSONDecodeError as e: sys.stderr.write("Skip {}\n {}\n".format(path, e)) - continue except KeyError as e: sys.stderr.write("Abort on {}\n Missing key {}\n".format(path, e)) exit(1) -- 2.30.2