-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
# SPDX-FileCopyrightText: 2024 Alec Delaney, for Adafruit Industries | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
"""CLI functionality for the query subcommand. | ||
Author(s): Alec Delaney | ||
""" | ||
|
||
import re | ||
|
||
import click | ||
import github | ||
import packaging.version | ||
|
||
import circfirm | ||
import circfirm.backend | ||
import circfirm.cli | ||
|
||
|
||
@click.group() | ||
def cli(): | ||
"""Query things like latest versions and board lists.""" | ||
|
||
|
||
def query_sync() -> None: | ||
"""Sync CircuitPython board information.""" | ||
click.echo("Boards list will now be synchronized with the git repository.") | ||
click.echo( | ||
"Please note that this operation can only be performed 60 times per hour due to GitHub rate limiting." | ||
) | ||
try: | ||
boards = circfirm.cli.announce_and_await( | ||
"Updating boards list", circfirm.backend.get_board_list, use_spinner=True | ||
) | ||
except github.GithubException as err: | ||
raise click.ClickException(err.data["message"]) | ||
with open(circfirm.UF2_BOARD_LIST, mode="w", encoding="utf-8") as boardfile: | ||
for board in boards: | ||
boardfile.write(f"{board}\n") | ||
|
||
|
||
@cli.command(name="boards") | ||
@click.option( | ||
"-r", "--regex", default=None, help="Regex pattern to use for board names" | ||
) | ||
@click.option("-s", "--sync", is_flag=True, default=False, help="Sync the boards list") | ||
def query_boards(regex: str, sync: bool) -> None: | ||
"""Query the synchronized CircuitPython board list.""" | ||
if sync and regex: | ||
raise click.ClickException("Cannot use --regex and --sync simultaneously.") | ||
|
||
if sync: | ||
query_sync() | ||
return | ||
|
||
if regex is None: | ||
regex = ".*" | ||
|
||
with open(circfirm.UF2_BOARD_LIST, encoding="utf-8") as boardfile: | ||
for board in boardfile: | ||
board_name = board.strip() | ||
result = re.match(regex, board_name) | ||
if result: | ||
click.echo(board_name) | ||
|
||
|
||
@cli.command(name="versions") | ||
@click.argument("board") | ||
@click.option("-l", "--language", default="en_US", help="CircuitPython language/locale") | ||
@click.option("-r", "--regex", default=".*", help="Regex pattern to use for versions") | ||
def query_versions(board: str, language: str, regex: str) -> None: | ||
"""Query the CircuitPython versions available for a board.""" | ||
versions = circfirm.backend.get_board_versions(board, language, regex=regex) | ||
for version in reversed(versions): | ||
click.echo(version) | ||
|
||
|
||
@cli.command(name="latest") | ||
@click.argument("board") | ||
@click.option("-l", "--language", default="en_US", help="CircuitPython language/locale") | ||
@click.option( | ||
"-p", | ||
"--pre-release", | ||
is_flag=True, | ||
default=False, | ||
help="Consider pre-release versions", | ||
) | ||
def query_latest(board: str, language: str, pre_release: bool) -> None: | ||
"""Query the latest CircuitPython versions available for a board.""" | ||
versions = circfirm.backend.get_board_versions(board, language) | ||
if not pre_release: | ||
versions = [ | ||
version | ||
for version in versions | ||
if not packaging.version.Version(version).is_prerelease | ||
] | ||
click.echo(versions[0]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters