From ba6a8be5b938ebae40652cb1f0b381330cf83edd Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 23 Jan 2019 23:11:16 +0100 Subject: [PATCH 1/3] json boards.txt parser to help building FQBN --- tools/fqbn.py | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 tools/fqbn.py diff --git a/tools/fqbn.py b/tools/fqbn.py new file mode 100644 index 0000000000..d82bbee302 --- /dev/null +++ b/tools/fqbn.py @@ -0,0 +1,92 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +from __future__ import print_function +import re +import os +import sys +import json +import argparse +import collections + +# tweaks per historically malformed entries +hide = ('ESPModule', 'BoardModel') + +desc = 'Arduino boards.txt parser for FQBN details' + +parser = argparse.ArgumentParser(description=desc) +parser.add_argument('--machine', action='store_true', + help='machine version') +args = parser.parse_args() + +if not args.machine: + print('#') + print('# -- ' + desc + ' --') + print('#') + print('# random example:') + print('# esp8266com:esp8266:d1:xtal=80,vt=flash,exception=disabled,eesz=4M,ip=lm2f,dbg=Disabled,lvl=None____,wipe=none,baud=460800') + print('#') + print('# description of possible values in configurable menu entries:') + print('# (run with \'--machine\' for machine version)') + print('#') + print('#') + +REmenuentry = re.compile('^([^\.]*)\.menu\.([^\.]*)\.([^\.]*)(?:\.linux|\.macos|\.windows|)=(.*)') +REmenudesc = re.compile('^menu\.([^\.]*)=(.*)') +REmenuinternal = re.compile('^([^\.]*)\.([^\.]*)\.([^\.]*)=(.*)') + +menudescs = collections.OrderedDict([ ( 'UploadTool', 'Upload Tool' ) ]) +menuentries = collections.OrderedDict([ ]) +boards = collections.OrderedDict([ ]) + +boardstxt = False +for f in ( "../boards.txt", "boards.txt" ): + if os.path.isfile(f): + boardstxt = open(f) +if not boardstxt: + print("cannot open " + f) + sys.exit(1) + +line = boardstxt.readline() + +while line: + + catch = REmenudesc.match(line) + if catch: + #print("menudesc " + str(catch.groups())) + menudescs.update(collections.OrderedDict([ ( catch.group(1), catch.group(2) ) ])) + + catch = REmenuentry.match(line) + if catch: + #print("menuentry " + str(catch.groups())) + if not catch.group(2) in menuentries: + menuentries.update(collections.OrderedDict([(catch.group(2), collections.OrderedDict([]))])) + menuentries[catch.group(2)].update(collections.OrderedDict([(catch.group(3), catch.group(4))])) + + catch = REmenuinternal.match(line) + if catch: + #print("menuinternal " + str(catch.groups())) + if catch.group(3) == 'board': + boards.update(collections.OrderedDict([ (catch.group(1), catch.group(4)) ])) + + line = boardstxt.readline() + + +for p in menuentries: + for q in menuentries[p]: + menuentries[p][q] = menudescs[p] + ': ' + menuentries[p][q] + +for h in hide: + del menuentries[h] + +all = collections.OrderedDict([ + ( 'boards', boards ), + ( 'options', menudescs ), + ( 'values', menuentries ) +]) + +if args.machine: + print(json.dumps(all)) +else: + print(json.dumps(all, indent=2)) + print() From b025b3ff278a962a28192cd5311ff3a52ca6b2ed Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 24 Jan 2019 15:04:23 +0100 Subject: [PATCH 2/3] update output structure --- tools/fqbn.py | 42 +++++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/tools/fqbn.py b/tools/fqbn.py index d82bbee302..6991fd641d 100644 --- a/tools/fqbn.py +++ b/tools/fqbn.py @@ -71,19 +71,43 @@ line = boardstxt.readline() - -for p in menuentries: - for q in menuentries[p]: - menuentries[p][q] = menudescs[p] + ': ' + menuentries[p][q] +# end parsing +# now formatting for h in hide: del menuentries[h] -all = collections.OrderedDict([ - ( 'boards', boards ), - ( 'options', menudescs ), - ( 'values', menuentries ) -]) +all = { } + +all["options"] = [ ] +for entry in menuentries: + list = [ ] + for value in menuentries[entry]: + subdict = { } + subdict["value"] = value + subdict["description"] = menuentries[entry][value] + list.append(subdict) + dict = { } + dict["values"] = list + dict["ID"] = entry + dict["description"] = menudescs[entry] + all["options"].append(dict) + +all["menus"] = [ ] +for desc in menudescs: + dict = { } + dict["description"] = menudescs[desc] + dict["ID"] = desc + all["menus"].append(dict) + +all["boards"] = [ ] +for board in boards: + dict = { } + dict["description"] = boards[board] + dict["ID"] = board + all["boards"].append(dict) + +# display if args.machine: print(json.dumps(all)) From 5bb0bcf30ca387b34e1885b615d1e193a31bfe78 Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Mon, 28 Jan 2019 14:27:35 +0100 Subject: [PATCH 3/3] human output --- tools/fqbn.py | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/fqbn.py b/tools/fqbn.py index 6991fd641d..629bceb744 100644 --- a/tools/fqbn.py +++ b/tools/fqbn.py @@ -9,14 +9,13 @@ import argparse import collections -# tweaks per historically malformed entries -hide = ('ESPModule', 'BoardModel') - desc = 'Arduino boards.txt parser for FQBN details' parser = argparse.ArgumentParser(description=desc) parser.add_argument('--machine', action='store_true', - help='machine version') + help='machine json') +parser.add_argument('--json', action='store_true', + help='json') args = parser.parse_args() if not args.machine: @@ -74,9 +73,6 @@ # end parsing # now formatting -for h in hide: - del menuentries[h] - all = { } all["options"] = [ ] @@ -111,6 +107,17 @@ if args.machine: print(json.dumps(all)) -else: +elif args.json: print(json.dumps(all, indent=2)) print() +else: + print('FQBN parameters:') + #for entry in menuentries: + for desc in menudescs: + entry = desc + print() + print(' ' + entry + ': (' + menudescs[entry] + ')') + for value in menuentries[entry]: + print('%20s'%value + ' => ' + menuentries[entry][value]) + print() +