Skip to content

Instantly share code, notes, and snippets.

@vshymanskyy
Created September 22, 2023 12:59
Show Gist options
  • Save vshymanskyy/f5e33c6f8ff22213dbd5831a696d5ebe to your computer and use it in GitHub Desktop.
Save vshymanskyy/f5e33c6f8ff22213dbd5831a696d5ebe to your computer and use it in GitHub Desktop.
Publish TRICE to PlatformIO
#!/usr/bin/env python3
import os
import json
import requests
import tarfile
from zipfile import ZipFile
def download_file(url, filename):
with requests.get(url, stream=True) as r:
r.raise_for_status()
with open(filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
packages = [
{ "fn": "trice_darwin_arm64.tar.gz", "system": "darwin_arm64" },
{ "fn": "trice_darwin_amd64.tar.gz", "system": "darwin_x86_64" },
{ "fn": "trice_linux_arm64.tar.gz", "system": "linux_aarch64" },
{ "fn": "trice_linux_arm7.tar.gz", "system": [ "linux_armv7l", "linux_armv8l" ] },
{ "fn": "trice_linux_amd64.tar.gz", "system": "linux_x86_64" },
{ "fn": "trice_windows_amd64.zip", "system": "windows_amd64" },
]
version = "0.62.3"
for pkg in packages:
#
# Download original package file
#
fn = pkg["fn"]
url = f"https://github.com/rokath/trice/releases/download/v{version}/{fn}"
if not os.path.exists(fn):
download_file(url, fn)
#
# Extract the required files
#
if fn.endswith(".tar.gz"):
f = tarfile.open(fn)
files = [x.name for x in f.getmembers()]
path = fn.removesuffix(".tar.gz")
elif fn.endswith(".zip"):
f = ZipFile(fn)
files = f.namelist()
path = fn.removesuffix(".zip")
files = filter(lambda x:x.endswith(("trice.exe", "trice", "README.md", "LICENSE.md")) and "third_party" not in x, files)
for member in files:
f.extract(member)
if member.endswith(("trice.exe", "trice")):
os.chmod(member, 0o0777)
#
# Create package.json
#
pkg_json_data = {
"name": "tool-trice",
"version": version,
"description": "Super fast and tiny embedded device printf-like tracer, works also inside interrupts",
"homepage": "https://rokath.github.io/trice",
"keywords": [
"tools",
"build tools",
"tracing",
"diagnostics"
],
"license": "MIT",
"system": pkg["system"],
"repository": {
"type": "git",
"url": "https://github.com/rokath/trice"
}
}
with open(f"{path}/package.json", "w") as pkg_json:
json.dump(pkg_json_data, pkg_json, indent=4)
#
# Publish to PlatformIO
#
os.system(f"cd {path}; pio pkg publish --no-interactive")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment