kopia lustrzana https://github.com/micropython/micropython
Merge b52cf9e277
into d11ca092f7
commit
411d45f64c
|
@ -107,7 +107,7 @@ The full list of supported commands are:
|
||||||
**Note:** Instead of using the ``connect`` command, there are several
|
**Note:** Instead of using the ``connect`` command, there are several
|
||||||
:ref:`pre-defined shortcuts <mpremote_shortcuts>` for common device paths. For
|
:ref:`pre-defined shortcuts <mpremote_shortcuts>` for common device paths. For
|
||||||
example the ``a0`` shortcut command is equivalent to
|
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
|
**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
|
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>``
|
- ``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
|
Additional shortcuts can be defined by in the user configuration file ``mpremote/config.py``, located in:
|
||||||
located at ``.config/mpremote/config.py``. This file should define a
|
# ``$XDG_CONFIG_HOME/mpremote/config.py``
|
||||||
dictionary named ``commands``. The keys of this dictionary are the shortcuts
|
# ``$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:
|
and the values are either a string or a list-of-strings:
|
||||||
|
|
||||||
.. code-block:: python3
|
.. code-block:: python3
|
||||||
|
|
|
@ -341,10 +341,12 @@ _BUILTIN_COMMAND_EXPANSIONS = {
|
||||||
"--version": "version",
|
"--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 "connect /dev/ttyACMn" (and /dev/ttyUSBn, COMn) etc.
|
||||||
for port_num in range(4):
|
for port_num in range(4):
|
||||||
for prefix, port in [("a", "/dev/ttyACM"), ("u", "/dev/ttyUSB"), ("c", "COM")]:
|
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)] = {
|
_BUILTIN_COMMAND_EXPANSIONS["{}{}".format(prefix, port_num)] = {
|
||||||
"command": "connect {}{}".format(port, port_num),
|
"command": "connect {}{}".format(port, port_num),
|
||||||
"help": 'connect to serial port "{}{}"'.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.
|
# Create empty config object.
|
||||||
config = __build_class__(lambda: None, "Config")()
|
config = __build_class__(lambda: None, "Config")()
|
||||||
config.commands = {}
|
config.commands = {}
|
||||||
|
path = None
|
||||||
# Get config file name.
|
for env_var in ("XDG_CONFIG_HOME", "HOME", "APPDATA", "USERPROFILE"):
|
||||||
path = os.getenv("XDG_CONFIG_HOME")
|
path = os.getenv(env_var)
|
||||||
if path is None:
|
if not path:
|
||||||
path = os.getenv("HOME")
|
continue
|
||||||
if path is None:
|
if env_var == "HOME" and os.path.exists(os.path.join(path, ".config", _PROG, "config.py")):
|
||||||
return config
|
# Unix style
|
||||||
path = os.path.join(path, ".config")
|
path = os.path.join(path, ".config", _PROG)
|
||||||
path = os.path.join(path, _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")
|
config_file = os.path.join(path, "config.py")
|
||||||
|
|
||||||
# Check if config file exists.
|
|
||||||
if not os.path.exists(config_file):
|
if not os.path.exists(config_file):
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
@ -375,9 +381,11 @@ def load_user_config():
|
||||||
config_data = f.read()
|
config_data = f.read()
|
||||||
prev_cwd = os.getcwd()
|
prev_cwd = os.getcwd()
|
||||||
os.chdir(path)
|
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__)
|
exec(config_data, config.__dict__)
|
||||||
os.chdir(prev_cwd)
|
os.chdir(prev_cwd)
|
||||||
|
|
||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue