From: Moritz Warning Date: Mon, 2 Mar 2020 12:18:30 +0000 (+0100) Subject: use separate method to get model name X-Git-Tag: v2.1.0~16 X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f518be925bafd2288865d1a79f4ba38665225cbc;p=web%2Ffirmware-selector-openwrt-org.git use separate method to get model name --- diff --git a/misc/collect.py b/misc/collect.py index 16b9065..fca0b02 100755 --- a/misc/collect.py +++ b/misc/collect.py @@ -30,6 +30,12 @@ if args.input_path: for path in Path(args.input_path).rglob('*.json'): paths.append(path) +def get_title_name(title): + if 'title' in title: + return title['title'] + else: + return "{} {} {}".format(title.get('vendor', ''), title['model'], title.get('variant', '')).strip() + # json output data output = {} for path in paths: @@ -63,12 +69,13 @@ for path in paths: target = obj['target'] id = obj['id'] for title in obj['titles']: - if 'title' in title: - name = title['title'] - output['models'][name] = {'id': id, 'target': target, 'images': images} - else: - name = "{} {} {}".format(title.get('vendor', ''), title['model'], title.get('variant', '')).strip() - output['models'][name] = {'id': id, 'target': target, 'images': images} + name = get_title_name(title) + + if len(name) == 0: + sys.stderr.write("Empty title. Skip title in {}\n".format(path)) + continue + + output['models'][name] = {'id': id, 'target': target, 'images': images} except json.decoder.JSONDecodeError as e: sys.stderr.write("Skip {}\n {}\n".format(path, e))