mirror of
https://github.com/platformio/platformio-core.git
synced 2025-09-27 22:30:56 +02:00
Minor improvements
This commit is contained in:
@@ -163,7 +163,7 @@ class SerialPortFinder:
|
|||||||
for item in list_serial_ports(as_objects=True):
|
for item in list_serial_ports(as_objects=True):
|
||||||
if item.vid == device.vid and item.pid == device.pid:
|
if item.vid == device.vid and item.pid == device.pid:
|
||||||
candidates.append(item)
|
candidates.append(item)
|
||||||
if len(candidates) == 1:
|
if len(candidates) <= 1:
|
||||||
return device.device
|
return device.device
|
||||||
for item in candidates:
|
for item in candidates:
|
||||||
if ("GDB" if self.prefer_gdb_port else "UART") in item.description:
|
if ("GDB" if self.prefer_gdb_port else "UART") in item.description:
|
||||||
|
@@ -81,7 +81,7 @@ class InvalidSettingValue(UserSideException):
|
|||||||
MESSAGE = "Invalid value '{0}' for the setting '{1}'"
|
MESSAGE = "Invalid value '{0}' for the setting '{1}'"
|
||||||
|
|
||||||
|
|
||||||
class InvalidJSONFile(PlatformioException):
|
class InvalidJSONFile(ValueError, UserSideException):
|
||||||
MESSAGE = "Could not load broken JSON: {0}"
|
MESSAGE = "Could not load broken JSON: {0}"
|
||||||
|
|
||||||
|
|
||||||
|
@@ -157,7 +157,10 @@ class HTTPClient:
|
|||||||
with ContentCache("http") as cc:
|
with ContentCache("http") as cc:
|
||||||
result = cc.get(cache_key)
|
result = cc.get(cache_key)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
return json.loads(result)
|
try:
|
||||||
|
return json.loads(result)
|
||||||
|
except json.JSONDecodeError:
|
||||||
|
pass
|
||||||
response = self.send_request(method, path, **kwargs)
|
response = self.send_request(method, path, **kwargs)
|
||||||
data = self._parse_json_response(response)
|
data = self._parse_json_response(response)
|
||||||
cc.set(cache_key, response.text, cache_valid)
|
cc.set(cache_key, response.text, cache_valid)
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
import os
|
import os
|
||||||
from time import sleep, time
|
from time import sleep, time
|
||||||
|
|
||||||
from platformio.exception import PlatformioException
|
from platformio.exception import UserSideException
|
||||||
|
|
||||||
LOCKFILE_TIMEOUT = 3600 # in seconds, 1 hour
|
LOCKFILE_TIMEOUT = 3600 # in seconds, 1 hour
|
||||||
LOCKFILE_DELAY = 0.2
|
LOCKFILE_DELAY = 0.2
|
||||||
@@ -36,11 +36,11 @@ except ImportError:
|
|||||||
LOCKFILE_CURRENT_INTERFACE = None
|
LOCKFILE_CURRENT_INTERFACE = None
|
||||||
|
|
||||||
|
|
||||||
class LockFileExists(PlatformioException):
|
class LockFileExists(UserSideException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class LockFileTimeoutError(PlatformioException):
|
class LockFileTimeoutError(UserSideException):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@@ -25,12 +25,13 @@ from platformio.registry.mirror import RegistryFileMirrorIterator
|
|||||||
|
|
||||||
class PackageManagerRegistryMixin:
|
class PackageManagerRegistryMixin:
|
||||||
def install_from_registry(self, spec, search_qualifiers=None):
|
def install_from_registry(self, spec, search_qualifiers=None):
|
||||||
|
package = version = None
|
||||||
if spec.owner and spec.name and not search_qualifiers:
|
if spec.owner and spec.name and not search_qualifiers:
|
||||||
package = self.fetch_registry_package(spec)
|
package = self.fetch_registry_package(spec)
|
||||||
if not package:
|
if not package:
|
||||||
raise UnknownPackageError(spec.humanize())
|
raise UnknownPackageError(spec.humanize())
|
||||||
version = self.pick_best_registry_version(package["versions"], spec)
|
version = self.pick_best_registry_version(package["versions"], spec)
|
||||||
else:
|
elif spec.id or spec.name:
|
||||||
packages = self.search_registry_packages(spec, search_qualifiers)
|
packages = self.search_registry_packages(spec, search_qualifiers)
|
||||||
if not packages:
|
if not packages:
|
||||||
raise UnknownPackageError(spec.humanize())
|
raise UnknownPackageError(spec.humanize())
|
||||||
|
@@ -17,7 +17,7 @@ import os
|
|||||||
from platformio import fs, util
|
from platformio import fs, util
|
||||||
from platformio.compat import MISSING
|
from platformio.compat import MISSING
|
||||||
from platformio.debug.exception import DebugInvalidOptionsError, DebugSupportError
|
from platformio.debug.exception import DebugInvalidOptionsError, DebugSupportError
|
||||||
from platformio.exception import UserSideException
|
from platformio.exception import InvalidJSONFile, UserSideException
|
||||||
from platformio.platform.exception import InvalidBoardManifest
|
from platformio.platform.exception import InvalidBoardManifest
|
||||||
|
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class PlatformBoardConfig:
|
|||||||
self.manifest_path = manifest_path
|
self.manifest_path = manifest_path
|
||||||
try:
|
try:
|
||||||
self._manifest = fs.load_json(manifest_path)
|
self._manifest = fs.load_json(manifest_path)
|
||||||
except ValueError as exc:
|
except InvalidJSONFile as exc:
|
||||||
raise InvalidBoardManifest(manifest_path) from exc
|
raise InvalidBoardManifest(manifest_path) from exc
|
||||||
if not set(["name", "url", "vendor"]) <= set(self._manifest):
|
if not set(["name", "url", "vendor"]) <= set(self._manifest):
|
||||||
raise UserSideException(
|
raise UserSideException(
|
||||||
|
Reference in New Issue
Block a user