1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00
esp8266/package/merge_packages.py
Earle F. Philhower, III 0a031ce957
Move all scripts and documentation to Python3 (#6378)
* Move all scripts and documentation to Python3

Python 2 EOL is Jan 1, 2020.  Migrate scripts to run under Python 3.

Under Windows, we're already running Python 3.7, by dumb luck.  The
oddness is that the Windows standalone executable for Python 3 is called
"python" whereas under UNIX-like OSes it's called "python3" with
"python" always referring to the Python 2 executable.  The ZIP needs to
be updated to include a Python3.exe (copy of Python.exe) so that we can
use the same command lines under Linux and Windows, and to preserve my
sanity.

Fixes #6376

* Add new Windows ZIP with python3.exe file

* Sort options in boards.txt generation for repeatability

The order of the board opts dict changes depending on the Python version
and machine, so sort the options before printing them to get a stable
ordering.

* Re-add Python2 compatibility tweaks

Most scripts can run as Python 2 or Python 3 with minimal changes, so
re-add (and fix, as necessary) compatibility tweaks to the scripts.
2019-08-28 12:42:48 -07:00

61 lines
2.0 KiB
Python
Executable File

#!/usr/bin/env python3
# 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), file=sys.stderr)
print("{0} platform(s), {1} tools".format(len(pkg['platforms']), len(pkg['tools'])), file=sys.stderr)
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), file=sys.stderr)
versions[name] = {}
if not ver in versions[name]:
print("found new version {0} for object {1}".format(ver, name), file=sys.stderr)
versions[name][ver] = o
return versions
def main(args):
if len(args) < 3:
print("Usage: {0} <package1> <package2>".format(args[0]), file=sys.stderr)
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), file=sys.stderr)
pkg1['tools'].append(tools[name][version])
for name in platforms:
for version in platforms[name]:
print("Adding platform {0}-{1}".format(name, version), file=sys.stderr)
pkg1['platforms'].append(platforms[name][version])
json.dump({'packages':[pkg1]}, sys.stdout, indent=2)
if __name__ == '__main__':
sys.exit(main(sys.argv))