Report about outdated 99-platformio-udev.rules // Resolve #1823

This commit is contained in:
Ivan Kravets committed 2018-10-12 19:35:58 +03:00
1 parent b77fb79cd6
commit ff8fefb797
7 files changed
+69 -13

No files matched your search

+5 -10
View File
@@ -25,7 +25,7 @@ from time import sleep
from SCons.Script import ARGUMENTS
from serial import Serial, SerialException
from platformio import util
from platformio import exception, util
# pylint: disable=unused-argument
@@ -154,15 +154,10 @@ def AutodetectUploadPort(*args, **kwargs):
and not env.subst("$UPLOAD_PROTOCOL"))):
env.Replace(UPLOAD_PORT=_look_for_mbed_disk())
else:
if ("linux" in util.get_systype() and not any([
isfile("/etc/udev/rules.d/99-platformio-udev.rules"),
isfile("/lib/udev/rules.d/99-platformio-udev.rules")
])):
sys.stderr.write(
"\nWarning! Please install `99-platformio-udev.rules` and "
"check that your board's PID and VID are listed in the rules."
"\n https://docs.platformio.org/en/latest/faq.html"
"#platformio-udev-rules\n")
try:
util.ensure_udev_rules()
except exception.InvalidUdevRules as e:
sys.stderr.write("\n%s\n\n" % e)
env.Replace(UPLOAD_PORT=_look_for_serial_port())
if env.subst("$UPLOAD_PORT"):
+1 -1
View File
@@ -141,7 +141,7 @@ def BuildProgram(env):
return program
def ParseFlagsExtended(env, flags):
def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches
if not isinstance(flags, list):
flags = [flags]
result = {}
+19
View File
@@ -235,6 +235,25 @@ class CIBuildEnvsEmpty(PlatformioException):
"predefined environments using `--project-conf` option")
class InvalidUdevRules(PlatformioException):
pass
class MissedUdevRules(InvalidUdevRules):
MESSAGE = (
"Warning! Please install `99-platformio-udev.rules`. \nMode details: "
"https://docs.platformio.org/en/latest/faq.html#platformio-udev-rules")
class OutdatedUdevRules(InvalidUdevRules):
MESSAGE = (
"Warning! Your `{0}` are outdated. Please update or reinstall them."
"\n Mode details: https://docs.platformio.org"
"/en/latest/faq.html#platformio-udev-rules")
class UpgradeError(PlatformioException):
MESSAGE = """{0}
+37
View File
@@ -786,6 +786,43 @@ def merge_dicts(d1, d2, path=None):
return d1
def ensure_udev_rules():
def _rules_to_set(rules_path):
result = set([])
with open(rules_path, "rb") as fp:
for line in fp.readlines():
line = line.strip()
if not line or line.startswith("#"):
continue
result.add(line)
return result
if "linux" not in get_systype():
return None
installed_rules = [
"/etc/udev/rules.d/99-platformio-udev.rules",
"/lib/udev/rules.d/99-platformio-udev.rules"
]
if not any(isfile(p) for p in installed_rules):
raise exception.MissedUdevRules
origin_path = abspath(
join(get_source_dir(), "..", "scripts", "99-platformio-udev.rules"))
if not isfile(origin_path):
return None
origin_rules = _rules_to_set(origin_path)
for rules_path in installed_rules:
if not isfile(rules_path):
continue
current_rules = _rules_to_set(rules_path)
if not origin_rules <= current_rules:
raise exception.OutdatedUdevRules(rules_path)
return True
def rmtree_(path):
def _onerror(_, name, __):