Jos Verlinde 2024-04-26 08:41:28 -07:00 zatwierdzone przez GitHub
commit b96e727d89
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: B5690EEEBB952194
2 zmienionych plików z 30 dodań i 17 usunięć

Wyświetl plik

@ -107,7 +107,7 @@ The full list of supported commands are:
**Note:** Instead of using the ``connect`` command, there are several
:ref:`pre-defined shortcuts <mpremote_shortcuts>` for common device paths. For
example the ``a0`` shortcut command is equivalent to
``connect /dev/ttyACM0`` (Linux), or ``c0`` for ``COM0`` (Windows).
``connect /dev/ttyACM0`` (Linux), or ``c1`` for ``COM1`` (Windows).
**Note:** The ``auto`` option will only detect USB serial ports, i.e. a serial
port that has an associated USB VID/PID (i.e. CDC/ACM or FTDI-style
@ -429,9 +429,14 @@ Shortcuts can be defined using the macro system. Built-in shortcuts are:
- ``cat``, ``edit``, ``ls``, ``cp``, ``rm``, ``mkdir``, ``rmdir``, ``touch``: Aliases for ``fs <sub-command>``
Additional shortcuts can be defined by in user-configuration files, which is
located at ``.config/mpremote/config.py``. This file should define a
dictionary named ``commands``. The keys of this dictionary are the shortcuts
Additional shortcuts can be defined by in the user configuration file ``mpremote/config.py``, located in:
# ``$XDG_CONFIG_HOME/mpremote/config.py``
# ``$HOME/.config/mpremote/config.py``
# ``%APPDATA%/mpremote/config.py``
# ``%USERPROFILE%/mpremote/config.py``
searched in that order on all platforms.
This file should define a dictionary named ``commands``. The keys of this dictionary are the shortcuts
and the values are either a string or a list-of-strings:
.. code-block:: python3

Wyświetl plik

@ -341,10 +341,12 @@ _BUILTIN_COMMAND_EXPANSIONS = {
"--version": "version",
}
# Add "a0", "a1", ..., "u0", "u1", ..., "c0", "c1", ... as aliases
# Add "a0", "a1", ..., "u0", "u1", ..., "c1", "c2", ... as aliases
# for "connect /dev/ttyACMn" (and /dev/ttyUSBn, COMn) etc.
for port_num in range(4):
for prefix, port in [("a", "/dev/ttyACM"), ("u", "/dev/ttyUSB"), ("c", "COM")]:
if port_num == 0 and port == "COM":
continue # skip COM0 as it does not exist on Windows
_BUILTIN_COMMAND_EXPANSIONS["{}{}".format(prefix, port_num)] = {
"command": "connect {}{}".format(port, port_num),
"help": 'connect to serial port "{}{}"'.format(port, port_num),
@ -355,18 +357,22 @@ def load_user_config():
# Create empty config object.
config = __build_class__(lambda: None, "Config")()
config.commands = {}
# Get config file name.
path = os.getenv("XDG_CONFIG_HOME")
if path is None:
path = os.getenv("HOME")
if path is None:
return config
path = os.path.join(path, ".config")
path = os.path.join(path, _PROG)
path = None
for env_var in ("XDG_CONFIG_HOME", "HOME", "APPDATA", "USERPROFILE"):
path = os.getenv(env_var)
if not path:
continue
if env_var == "HOME" and os.path.exists(os.path.join(path, ".config", _PROG, "config.py")):
# Unix style
path = os.path.join(path, ".config", _PROG)
break
elif os.path.exists(os.path.join(path, _PROG, "config.py")):
# Windows style
path = os.path.join(path, _PROG)
break
if not path:
return config
config_file = os.path.join(path, "config.py")
# Check if config file exists.
if not os.path.exists(config_file):
return config
@ -375,9 +381,11 @@ def load_user_config():
config_data = f.read()
prev_cwd = os.getcwd()
os.chdir(path)
# pass in the config path so that the config file can use it
config.__dict__["config_path"] = path
config.__dict__["__file__"] = config_file
exec(config_data, config.__dict__)
os.chdir(prev_cwd)
return config