-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Update mpflash version to 0.8.0
The `pyproject.toml` file in the `mpflash` module has been updated to set the version to 0.8.0. This change reflects the new version of the tool and ensures consistency with the package metadata. Resolve board IDs in `cli_flash.py` The `resolve_board_ids` function in `cli_flash.py` has been updated to correctly resolve board IDs and update the `params.boards` list. This change ensures that the board IDs are properly resolved and used in the flash process. Add `Board` dataclass to `board.py` A new `Board` dataclass has been added to the `board.py` file. This dataclass represents MicroPython board definitions and includes attributes such as `port`, `board_id`, `board_name`, and `description`. This change improves the organization and readability of the code. Update board information handling in `store.py` The `write_boardinfo_json` function in `store.py` has been updated to write the board information to a zip file instead of a JSON file. This change improves the file organization and allows for easier distribution of the board information. These changes address various updates and improvements in the `mpflash` module.
- Loading branch information
Showing
17 changed files
with
300 additions
and
20,075 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import shutil | ||
from pathlib import Path | ||
from typing import Union | ||
|
||
import jsonlines | ||
import requests | ||
from loguru import logger as log | ||
|
||
# re-use logic from mpremote | ||
from mpremote.mip import _rewrite_url as rewrite_url # type: ignore | ||
|
||
from mpflash.common import FWInfo | ||
from mpflash.config import config | ||
from mpflash.vendor.versions import get_preview_mp_version, get_stable_mp_version | ||
|
||
|
||
def add_firmware( | ||
source: Union[Path, str], | ||
new_fw: FWInfo, | ||
*, | ||
force: bool = False, | ||
custom: bool = False, | ||
description: str = "", | ||
) -> bool: | ||
"""Add a firmware to the firmware folder. | ||
stored in the port folder, with the same filename as the source. | ||
""" | ||
# Check minimal info needed | ||
if not new_fw.port or not new_fw.board: | ||
log.error("Port and board are required") | ||
return False | ||
if not isinstance(source, Path) and not source.startswith("http"): | ||
log.error(f"Invalid source {source}") | ||
return False | ||
|
||
# use sensible defaults | ||
source_2 = Path(source) | ||
new_fw.ext = new_fw.ext or source_2.suffix | ||
new_fw.variant = new_fw.variant or new_fw.board | ||
new_fw.custom = new_fw.custom or custom | ||
new_fw.description = new_fw.description or description | ||
if not new_fw.version: | ||
# TODO: Get version from filename | ||
# or use the last preview version | ||
new_fw.version = get_preview_mp_version() if new_fw.preview else get_stable_mp_version() | ||
|
||
config.firmware_folder.mkdir(exist_ok=True) | ||
|
||
fw_filename = config.firmware_folder / new_fw.port / source_2.name | ||
|
||
new_fw.filename = str(fw_filename.relative_to(config.firmware_folder)) | ||
new_fw.firmware = source.as_uri() if isinstance(source, Path) else source | ||
|
||
if not copy_firmware(source, fw_filename, force): | ||
log.error(f"Failed to copy {source} to {fw_filename}") | ||
return False | ||
# add to inventory | ||
with jsonlines.open(config.firmware_folder / "firmware.jsonl", "a") as writer: | ||
log.info(f"Adding {new_fw.port} {new_fw.board}") | ||
log.info(f" to {fw_filename}") | ||
|
||
writer.write(new_fw.to_dict()) | ||
return True | ||
|
||
|
||
def copy_firmware(source: Union[Path, str], fw_filename: Path, force: bool = False): | ||
"""Add a firmware to the firmware folder. | ||
stored in the port folder, with the same filename as the source. | ||
""" | ||
if fw_filename.exists() and not force: | ||
log.error(f" {fw_filename} already exists. Use --force to overwrite") | ||
return False | ||
fw_filename.parent.mkdir(exist_ok=True) | ||
if isinstance(source, Path): | ||
if not source.exists(): | ||
log.error(f"File {source} does not exist") | ||
return False | ||
# file copy | ||
log.debug(f"Copy {source} to {fw_filename}") | ||
shutil.copy(source, fw_filename) | ||
return True | ||
# handle github urls | ||
url = rewrite_url(source) | ||
if str(source).startswith("http://") or str(source).startswith("https://"): | ||
log.debug(f"Download {url} to {fw_filename}") | ||
response = requests.get(url) | ||
|
||
if response.status_code == 200: | ||
with open(fw_filename, "wb") as file: | ||
file.write(response.content) | ||
log.info("File downloaded and saved successfully.") | ||
return True | ||
else: | ||
print("Failed to download the file.") | ||
return False | ||
return False |
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
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
Oops, something went wrong.