Skip to content

Commit

Permalink
Add script to merge boards manager packages
Browse files Browse the repository at this point in the history
  • Loading branch information
igrr committed Nov 17, 2015
1 parent 39cf5d6 commit 16a2cdc
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
60 changes: 60 additions & 0 deletions package/merge_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env python
# This script merges two Arduino Board Manager package json files.
# Usage:
# python merge_packages.py package_esp8266com_index.json version/new/package_esp8266com_index.json
# Written by Ivan Grokhotkov, 2015
#
from __future__ import print_function
import json
import sys

def load_package(filename):
pkg = json.load(open(filename))['packages'][0]
print("Loaded package {0} from {1}".format(pkg['name'], filename))
print("{0} platform(s), {1} tools".format(len(pkg['platforms']), len(pkg['tools'])))
return pkg

def merge_objects(versions, obj):
for o in obj:
name = o['name'].encode('ascii')
ver = o['version'].encode('ascii')
if not name in versions:
print("found new object, {0}".format(name))
versions[name] = {}
if not ver in versions[name]:
print("found new version {0} for object {1}".format(ver, name))
versions[name][ver] = o
return versions


def main(args):
if len(args) < 3:
print("Usage: {0} <package1> <package2>".format(args[0]))
return 1

tools = {}
platforms = {}
pkg1 = load_package(args[1])
tools = merge_objects(tools, pkg1['tools']);
platforms = merge_objects(platforms, pkg1['platforms']);
pkg2 = load_package(args[2])
tools = merge_objects(tools, pkg2['tools']);
platforms = merge_objects(platforms, pkg2['platforms']);

pkg1['tools'] = []
pkg1['platforms'] = []

for name in tools:
for version in tools[name]:
print("Adding tool {0}-{1}".format(name, version))
pkg1['tools'].append(tools[name][version])

for name in platforms:
for version in platforms[name]:
print("Adding platform {0}-{1}".format(name, version))
pkg1['platforms'].append(platforms[name][version])

json.dump({'packages':[pkg1]}, sys.stdout, indent=2)

if __name__ == '__main__':
sys.exit(main(sys.argv))
6 changes: 3 additions & 3 deletions tools/get.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# This script will download and extract required tools into the current directory
# Tools list is obtained from tools.json file
# Written by Ivan Grokhotkov, 2015
# This script will download and extract required tools into the current directory.
# Tools list is obtained from package/package_esp8266com_index.template.json file.
# Written by Ivan Grokhotkov, 2015.
#
from __future__ import print_function
import urllib
Expand Down

0 comments on commit 16a2cdc

Please sign in to comment.