- .github
- ansible
- anthias_app
- anthias_django
- api
- bin
- docker
-
docs
- d2
-
images
- balena-deployment-01-dashboard.png
- balena-deployment-02-create-fleet.png
- balena-deployment-03-fleet-summary-page.png
- balena-deployment-04-fleet-config-page.png
- balena-deployment-05-term-deployment-successful.png
- balena-deployment-06-fleet-releases-page.png
- balena-deployment-07-add-device.png
- balena-deployment-08-etcher.png
- balena-deployment-09-device-list.png
- balena-deployment-10-downloading-images.png
- imager-01.png
- imager-02.png
- imager-03.png
- install-anthias.gif
- nmtui-01.png
- nmtui-02.png
- nmtui-03.png
- nmtui-04.png
- README.md
- balena-fleet-deployment.md
- developer-documentation.md
- installation-options.md
- migrating-assets-to-screenly.md
- qa-checklist.md
- wifi-setup.md
- x86-installation.md
- lib
- requirements
-
static
- coffee
- css
-
favicons
- apple-touch-icon-114x114.png
- apple-touch-icon-120x120.png
- apple-touch-icon-144x144.png
- apple-touch-icon-152x152.png
- apple-touch-icon-57x57.png
- apple-touch-icon-60x60.png
- apple-touch-icon-72x72.png
- apple-touch-icon-76x76.png
- favicon-128.png
- favicon-16x16.png
- favicon-196x196.png
- favicon-32x32.png
- favicon-96x96.png
- favicon.ico
- mstile-144x144.png
- mstile-150x150.png
- mstile-310x150.png
- mstile-310x310.png
- mstile-70x70.png
- fontawesome
- img
- js
- sass
- spec
- templates
- tests
- tools
- website
- webview
- .dockerignore
- .flake8
- .gitignore
- LICENSE
- README.md
- balena.yml
- celery_tasks.py
- docker-compose.balena.dev.yml.tmpl
- docker-compose.balena.yml.tmpl
- docker-compose.dev.yml
- docker-compose.test.yml
- docker-compose.yml.tmpl
- host_agent.py
- manage.py
- package-lock.json
- package.json
- poetry.lock
- pyproject.toml
- run_gunicorn.py
- send_zmq_message.py
- settings.py
- start_wifi_connect_service.sh
- viewer.py
- webpack.common.js
- webpack.dev.js
- webpack.prod.js
- websocket_server_layer.py
Explanation
This Python script retrieves information about the latest Anthias releases from GitHub and generates a JSON file suitable for use with the Pi Imager.
Code Breakdown:
Imports:
requests
: used for making HTTP requests to the GitHub API.json
: used for encoding and decoding JSON data.Constants:
BASE_URL
: Base URL for the GitHub API endpoint for the Anthias repository.GITHUB_HEADERS
: Headers required for authenticating with the GitHub API.get_latest_tag()
Function:Makes a GET request to the
latest
release endpoint of the Anthias repository.Extracts the
tag_name
from the response and returns it.get_asset_list()
Function:Takes the release tag as input.
Makes a GET request to the specified release tag endpoint.
Iterates through the
assets
in the response and adds thebrowser_download_url
for each.zip
asset to a list.Returns the list of asset URLs.
retrieve_and_patch_json()
Function:Takes a download URL for a
.zip
file as input.Replaces the
.zip
extension with.json
to get the corresponding JSON file URL.Makes a GET request to the
.json
file URL.Parses the JSON data from the response.
Replaces the
url
field in the JSON data with the original.zip
URL.Converts the
extract_size
andimage_download_size
fields to integers.Returns the patched JSON data.
main()
Function:Calls
get_latest_tag()
to get the latest release tag.Calls
get_asset_list()
to get the list of asset URLs for the latest release.Initializes an empty dictionary
pi_imager_json
with a keyos_list
.Iterates through the asset URLs:
For each URL, calls
retrieve_and_patch_json()
to get the patched JSON data.Appends the patched JSON data to the
os_list
ofpi_imager_json
.Prints the final
pi_imager_json
as a JSON string.
Purpose:
This script automates the process of creating a JSON file that can be used with the Pi Imager to install Anthias on Raspberry Pi devices. The script retrieves the latest release information from GitHub, extracts the necessary data from the release assets, and formats it into a JSON structure that is compatible with the Pi Imager.
Usage:
To use the script, simply run it from the command line. The script will print the generated JSON file to the console. You can then copy and paste the JSON data into a file named pi-imager-config.json
and place it in the imager-config
folder within your Raspberry Pi Imager installation directory.
Additional Notes:
- The script utilizes the GitHub API to retrieve release information. You will need a GitHub account and have your API token set up for the script to work correctly.
- The
pi-imager-config.json
file is used by the Pi Imager to identify and install the available operating system images. - The script assumes that all
.zip
files in the latest release contain a corresponding.json
file with the same name (without the.zip
extension). This JSON file should contain information about the image, such as the download size, extract size, and other relevant details.
Graph
The graph shows the usage of functions within the codebase.
Select a code symbol to view it's graph