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

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

View File

@ -15,6 +15,8 @@ PlatformIO 3.0
* Support in-line comments for multi-line value (``lib_deps``, ``build_flags``, etc) in `“platformio.ini” (Project Configuration File) <https://docs.platformio.org/page/projectconf.html>`__ * Support in-line comments for multi-line value (``lib_deps``, ``build_flags``, etc) in `“platformio.ini” (Project Configuration File) <https://docs.platformio.org/page/projectconf.html>`__
* Do not re-create ".gitignore" and ".travis.yml" files if they were removed * Do not re-create ".gitignore" and ".travis.yml" files if they were removed
from a project from a project
* Report about outdated `99-platformio-udev.rules <http://docs.platformio.org/page/faq.html#platformio-udev-rules>`__
(`issue #1823 <https://github.com/platformio/platformio-core/issues/1823>`_)
* Fixed an issue when dynamic build flags were not handled correctly * Fixed an issue when dynamic build flags were not handled correctly
(`issue #1799 <https://github.com/platformio/platformio-core/issues/1799>`_) (`issue #1799 <https://github.com/platformio/platformio-core/issues/1799>`_)

2
docs

Submodule docs updated: 97cde4edd9...4d4a51260b

View File

@ -25,7 +25,7 @@ from time import sleep
from SCons.Script import ARGUMENTS from SCons.Script import ARGUMENTS
from serial import Serial, SerialException from serial import Serial, SerialException
from platformio import util from platformio import exception, util
# pylint: disable=unused-argument # pylint: disable=unused-argument
@ -154,15 +154,10 @@ def AutodetectUploadPort(*args, **kwargs):
and not env.subst("$UPLOAD_PROTOCOL"))): and not env.subst("$UPLOAD_PROTOCOL"))):
env.Replace(UPLOAD_PORT=_look_for_mbed_disk()) env.Replace(UPLOAD_PORT=_look_for_mbed_disk())
else: else:
if ("linux" in util.get_systype() and not any([ try:
isfile("/etc/udev/rules.d/99-platformio-udev.rules"), util.ensure_udev_rules()
isfile("/lib/udev/rules.d/99-platformio-udev.rules") except exception.InvalidUdevRules as e:
])): sys.stderr.write("\n%s\n\n" % e)
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")
env.Replace(UPLOAD_PORT=_look_for_serial_port()) env.Replace(UPLOAD_PORT=_look_for_serial_port())
if env.subst("$UPLOAD_PORT"): if env.subst("$UPLOAD_PORT"):

View File

@ -141,7 +141,7 @@ def BuildProgram(env):
return program return program
def ParseFlagsExtended(env, flags): def ParseFlagsExtended(env, flags): # pylint: disable=too-many-branches
if not isinstance(flags, list): if not isinstance(flags, list):
flags = [flags] flags = [flags]
result = {} result = {}

View File

@ -235,6 +235,25 @@ class CIBuildEnvsEmpty(PlatformioException):
"predefined environments using `--project-conf` option") "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): class UpgradeError(PlatformioException):
MESSAGE = """{0} MESSAGE = """{0}

View File

@ -786,6 +786,43 @@ def merge_dicts(d1, d2, path=None):
return d1 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 rmtree_(path):
def _onerror(_, name, __): def _onerror(_, name, __):

View File

@ -37,7 +37,7 @@ setup(
license=__license__, license=__license__,
python_requires='>=2.7, <3', python_requires='>=2.7, <3',
install_requires=install_requires, install_requires=install_requires,
packages=find_packages(), packages=find_packages() + ["scripts"],
package_data={ package_data={
"platformio": [ "platformio": [
"projectconftpl.ini", "projectconftpl.ini",
@ -45,6 +45,9 @@ setup(
"ide/tpls/*/*.tpl", "ide/tpls/*/*.tpl",
"ide/tpls/*/*/*.tpl", "ide/tpls/*/*/*.tpl",
"ide/tpls/*/.*/*.tpl" "ide/tpls/*/.*/*.tpl"
],
"scripts": [
"99-platformio-udev.rules"
] ]
}, },
entry_points={ entry_points={