forked from platformio/platformio-core
Unix shell-style wildcards for “upload_port” // Resolve #839
This commit is contained in:
14
HISTORY.rst
14
HISTORY.rst
@ -19,18 +19,20 @@ PlatformIO 3.0
|
||||
* `PIO Account <http://docs.platformio.org/en/latest/userguide/account/index.html>`__
|
||||
and `PLATFORMIO_AUTH_TOKEN <http://docs.platformio.org/en/latest/envvars.html#envvar-PLATFORMIO_AUTH_TOKEN>`__
|
||||
environment variable for CI systems
|
||||
* Refactored `Library Dependency Finder (LDF) <http://docs.platformio.org/en/stable/librarymanager/ldf.html>`__
|
||||
C/C++ Preprocessor for conditional syntax (``#ifdef``, ``#if``, ``#else``,
|
||||
``#elif``, ``#define``, etc.)
|
||||
(`issue #837 <https://github.com/platformio/platformio/issues/837>`_)
|
||||
* Added new `LDF Modes <http://docs.platformio.org/en/latest/librarymanager/ldf.html#ldf-mode>`__:
|
||||
``chain+`` and ``deep+`` and set ``chain+`` as default
|
||||
* Inject system environment variables to configuration settings in
|
||||
`Project Configuration File "platformio.ini" <http://docs.platformio.org/en/stable/projectconf.html>`__
|
||||
(`issue #792 <https://github.com/platformio/platformio/issues/792>`_)
|
||||
* Custom boards per project with ``boards_dir`` option in
|
||||
`Project Configuration File "platformio.ini" <http://docs.platformio.org/en/stable/projectconf.html>`__
|
||||
(`issue #515 <https://github.com/platformio/platformio/issues/515>`_)
|
||||
* Unix shell-style wildcards for `upload_port <http://docs.platformio.org/en/latest/projectconf.html#upload-port>`_
|
||||
(`issue #839 <https://github.com/platformio/platformio/issues/839>`_)
|
||||
* Refactored `Library Dependency Finder (LDF) <http://docs.platformio.org/en/stable/librarymanager/ldf.html>`__
|
||||
C/C++ Preprocessor for conditional syntax (``#ifdef``, ``#if``, ``#else``,
|
||||
``#elif``, ``#define``, etc.)
|
||||
(`issue #837 <https://github.com/platformio/platformio/issues/837>`_)
|
||||
* Added new `LDF Modes <http://docs.platformio.org/en/latest/librarymanager/ldf.html#ldf-mode>`__:
|
||||
``chain+`` and ``deep+`` and set ``chain+`` as default
|
||||
* Changed a default exit combination for Device Monitor from ``Ctrl+]`` to ``Ctrl+C``
|
||||
* Improved detecting of ARM mbed media disk for uploading
|
||||
* Improved Project Generator for CLion IDE when source folder contains nested items
|
||||
|
@ -653,6 +653,26 @@ To print all available serial ports use :ref:`cmd_device_list` command.
|
||||
This option can be set by global environment variable
|
||||
:envvar:`PLATFORMIO_UPLOAD_PORT`.
|
||||
|
||||
Please note that you can use Unix shell-style wildcards:
|
||||
|
||||
.. list-table::
|
||||
:header-rows: 1
|
||||
|
||||
* - Pattern
|
||||
- Meaning
|
||||
|
||||
* - ``*``
|
||||
- matches everything
|
||||
|
||||
* - ``?``
|
||||
- matches any single character
|
||||
|
||||
* - ``[seq]``
|
||||
- matches any character in seq
|
||||
|
||||
* - ``[!seq]``
|
||||
- matches any character not in seq
|
||||
|
||||
Example:
|
||||
|
||||
.. code-block:: ini
|
||||
@ -660,8 +680,11 @@ Example:
|
||||
[env:uno]
|
||||
platform = atmelavr
|
||||
framework = arduino
|
||||
board = uno
|
||||
upload_port = /dev/ttyUSB0
|
||||
; any port that stats with /dev/ttyUSB
|
||||
upload_port = /dev/ttyUSB*
|
||||
|
||||
; COM1 or COM3
|
||||
upload_port = COM[13]
|
||||
|
||||
``upload_protocol``
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
@ -15,6 +15,7 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
from fnmatch import fnmatch
|
||||
from os import environ
|
||||
from os.path import isfile, join
|
||||
from platform import system
|
||||
@ -85,9 +86,24 @@ def WaitForNewSerialPort(env, before):
|
||||
def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
|
||||
env = args[0]
|
||||
|
||||
def _get_pattern():
|
||||
if "UPLOAD_PORT" not in env:
|
||||
return None
|
||||
if set(["*", "?", "[", "]"]) & set(env['UPLOAD_PORT']):
|
||||
return env['UPLOAD_PORT']
|
||||
return None
|
||||
|
||||
def _is_match_pattern(port):
|
||||
pattern = _get_pattern()
|
||||
if not pattern:
|
||||
return True
|
||||
return fnmatch(port, pattern)
|
||||
|
||||
def _look_for_mbed_disk():
|
||||
msdlabels = ("mbed", "nucleo", "frdm", "microbit")
|
||||
for item in util.get_logicaldisks():
|
||||
if not _is_match_pattern(item['disk']):
|
||||
continue
|
||||
if (item['name'] and
|
||||
any([l in item['name'].lower() for l in msdlabels])):
|
||||
return item['disk']
|
||||
@ -101,6 +117,8 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
|
||||
if "BOARD" in env and "build.hwids" in env.BoardConfig():
|
||||
board_hwids = env.BoardConfig().get("build.hwids")
|
||||
for item in util.get_serialports(filter_hwid=True):
|
||||
if not _is_match_pattern(item['port']):
|
||||
continue
|
||||
port = item['port']
|
||||
for hwid in board_hwids:
|
||||
hwid_str = ("%s:%s" % (hwid[0], hwid[1])).replace("0x", "")
|
||||
@ -108,7 +126,7 @@ def AutodetectUploadPort(*args, **kwargs): # pylint: disable=unused-argument
|
||||
return port
|
||||
return port
|
||||
|
||||
if "UPLOAD_PORT" in env:
|
||||
if "UPLOAD_PORT" in env and not _get_pattern():
|
||||
print env.subst("Use manually specified: $UPLOAD_PORT")
|
||||
return
|
||||
|
||||
|
Reference in New Issue
Block a user