-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getinfo: determine boardname of firmware #357
Labels
Comments
working propotype mpremote COM16 mount . get-port "stubber: get-port"
import gc
import os
import sys
try:
from collections import OrderedDict
except ImportError:
from ucollections import OrderedDict # type: ignore
info = OrderedDict(
{
"family": sys.implementation.name,
"version": "",
"port": "stm32" if sys.platform.startswith("pyb") else sys.platform, # port: esp32 / win32 / linux / stm32
"board": "GENERIC",
"cpu": "",
"build": "",
"board_d": "",
}
)
try:
info["version"] = ".".join([str(n) for n in sys.implementation.version])
except AttributeError:
pass
try:
machine = sys.implementation._machine if "_machine" in dir(sys.implementation) else os.uname().machine
info["board"] = machine.strip()
info["cpu"] = machine.split("with")[1].strip()
except (AttributeError, IndexError):
pass
gc.collect()
try:
# look up the board name in the board_info.csv file
with open("board_info.csv", "r") as f:
b = info["board"]
for line in f:
descr_, board_ = line.split(",")[1].strip(), line.split(",")[0].strip()
if board_ == b:
info["board_d"] = board_
info["board"] = descr_
break
info["board"] = info["board"].replace(" ", "_")
except (AttributeError, IndexError, OSError):
pass
gc.collect()
try:
info["build"] = sys.version.split(";")[1].strip().split(" ")[1].split("-")[1]
except (AttributeError, IndexError):
pass
if info["version"] == "" and sys.platform not in ("unix", "win32"):
try:
u = os.uname()
info["version"] = u.release
except (IndexError, AttributeError, TypeError):
pass
try: # families
from pycopy import const as _t # type: ignore
info["family"] = "pycopy"
del _t
except (ImportError, KeyError):
pass
try: # families
from pycom import FAT as _t # type: ignore
info["family"] = "pycom"
del _t
except (ImportError, KeyError):
pass
if info["family"] == "micropython":
if (
info["version"]
and info["version"].endswith(".0")
and info["version"] >= "1.10.0" # versions from 1.10.0 to 1.20.0 do not have a micro .0
and info["version"] <= "1.20.0"
):
# drop the .0 for newer releases
info["version"] = info["version"][:-2]
# output the info dict as a string with the OrderedDict() removed
print(str(info).replace("OrderedDict(", "").rstrip(")")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
depends on #285
The text was updated successfully, but these errors were encountered: