From aed7597bd712d3ae6f2ac3a8a39693cf3457378e Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Sat, 3 Dec 2016 17:59:15 +0200 Subject: [PATCH] =?UTF-8?q?Unix=20shell-style=20wildcards=20for=20?= =?UTF-8?q?=E2=80=9Cupload=5Fport=E2=80=9D=20=20//=20Resolve=20#839?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HISTORY.rst | 14 ++++++++------ docs/projectconf.rst | 27 +++++++++++++++++++++++++-- platformio/builder/tools/pioupload.py | 20 +++++++++++++++++++- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index bbc5f09e..0e74b10e 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -19,18 +19,20 @@ PlatformIO 3.0 * `PIO Account `__ and `PLATFORMIO_AUTH_TOKEN `__ environment variable for CI systems -* Refactored `Library Dependency Finder (LDF) `__ - C/C++ Preprocessor for conditional syntax (``#ifdef``, ``#if``, ``#else``, - ``#elif``, ``#define``, etc.) - (`issue #837 `_) -* Added new `LDF Modes `__: - ``chain+`` and ``deep+`` and set ``chain+`` as default * Inject system environment variables to configuration settings in `Project Configuration File "platformio.ini" `__ (`issue #792 `_) * Custom boards per project with ``boards_dir`` option in `Project Configuration File "platformio.ini" `__ (`issue #515 `_) +* Unix shell-style wildcards for `upload_port `_ + (`issue #839 `_) +* Refactored `Library Dependency Finder (LDF) `__ + C/C++ Preprocessor for conditional syntax (``#ifdef``, ``#if``, ``#else``, + ``#elif``, ``#define``, etc.) + (`issue #837 `_) +* Added new `LDF Modes `__: + ``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 diff --git a/docs/projectconf.rst b/docs/projectconf.rst index 2ccb5ebe..69bbb5cd 100644 --- a/docs/projectconf.rst +++ b/docs/projectconf.rst @@ -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`` ^^^^^^^^^^^^^^^^^^^ diff --git a/platformio/builder/tools/pioupload.py b/platformio/builder/tools/pioupload.py index fecb42cc..7f2fd42e 100644 --- a/platformio/builder/tools/pioupload.py +++ b/platformio/builder/tools/pioupload.py @@ -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