Better resilience against broken software update configs

Fixes #1773
This commit is contained in:
Gina Häußge 2017-02-14 10:40:42 +01:00
parent b453897ea3
commit 5d97dc4b40
7 changed files with 46 additions and 22 deletions

View file

@ -820,8 +820,16 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
if target == "octoprint":
from flask.ext.babel import gettext
result["displayName"] = check.get("displayName", gettext("OctoPrint"))
result["displayVersion"] = check.get("displayVersion", "{octoprint_version}")
result["displayName"] = check.get("displayName")
if result["displayName"] is None:
# displayName missing or set to None
result["displayName"] = gettext("OctoPrint")
result["displayVersion"] = check.get("displayVersion")
if result["displayVersion"] is None:
# displayVersion missing or set to None
result["displayVersion"] = "{octoprint_version}"
stable_branch = "master"
release_branches = []
@ -876,8 +884,16 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
result["release_compare"] = "python_unequal"
else:
result["displayName"] = check.get("displayName", target)
result["displayVersion"] = check.get("displayVersion", check.get("current", "unknown"))
result["displayName"] = check.get("displayName")
if result["displayName"] is None:
# displayName missing or None
result["displayName"] = target
result["displayVersion"] = check.get("displayVersion", check.get("current"))
if result["displayVersion"] is None:
# displayVersion AND current missing or None
result["displayVersion"] = "unknown"
if check["type"] in ("github_commit",):
result["current"] = check.get("current", None)
else:

View file

@ -7,7 +7,7 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
def can_perform_update(target, check):
return "python_updater" in check and check["python_updater"] is not None
return "python_updater" in check and check["python_updater"] is not None and hasattr(check["python_updater"], "perform_update")
def perform_update(target, check, target_version, log_cb=None):

View file

@ -12,10 +12,11 @@ from ..exceptions import ConfigurationInvalid
from ..util import execute
def get_latest(target, check):
if not "command" in check:
raise ConfigurationInvalid("Update configuration for %s of type commandline needs command defined" % target)
command = check.get("command")
if command is None:
raise ConfigurationInvalid("Update configuration for {} of type commandline needs command set and not None".format(target))
returncode, stdout, stderr = execute(check["command"], evaluate_returncode=False)
returncode, stdout, stderr = execute(command, evaluate_returncode=False)
# We expect command line check commands to
#

View file

@ -48,10 +48,9 @@ def _git(args, cwd, hide_stderr=False):
def get_latest(target, check):
if not "checkout_folder" in check:
raise ConfigurationInvalid("Update configuration for %s needs checkout_folder" % target)
checkout_folder = check["checkout_folder"]
checkout_folder = check.get("checkout_folder")
if checkout_folder is None:
raise ConfigurationInvalid("Update configuration for {} of type git_commit needs checkout_folder set and not None".format(target))
returncode, _ = _git(["fetch"], checkout_folder)
if returncode != 0:
@ -85,4 +84,4 @@ def get_latest(target, check):
logger = logging.getLogger("octoprint.plugins.softwareupdate.version_checks.git_commit")
logger.debug("Target: %s, local: %s, remote: %s" % (target, local_commit, remote_commit))
return information, is_current
return information, is_current

View file

@ -31,11 +31,14 @@ def _get_latest_commit(user, repo, branch):
def get_latest(target, check):
if "user" not in check or "repo" not in check:
raise ConfigurationInvalid("Update configuration for %s of type github_commit needs all of user and repo" % target)
user = check.get("user")
repo = check.get("repo")
if user is None or repo is None:
raise ConfigurationInvalid("Update configuration for {} of type github_commit needs user and repo set and not None".format(target))
branch = "master"
if "branch" in check:
if "branch" in check and check["branch"] is not None:
branch = check["branch"]
current = None

View file

@ -115,12 +115,14 @@ def _get_sanitized_version(version_string):
Removes "-..." prefix from version strings.
Tests:
>>> _get_sanitized_version(None)
>>> _get_sanitized_version("1.2.15")
'1.2.15'
>>> _get_sanitized_version("1.2.15-dev12")
'1.2.15'
"""
if "-" in version_string:
if version_string is not None and "-" in version_string:
version_string = version_string[:version_string.find("-")]
return version_string
@ -247,10 +249,12 @@ def _is_current(release_information, compare_type, custom=None, force_base=True)
def get_latest(target, check, custom_compare=None):
from ..exceptions import ConfigurationInvalid
if not "user" in check or not "repo" in check:
raise ConfigurationInvalid("github_release update configuration for %s needs user and repo set" % target)
user = check.get("user", None)
repo = check.get("repo", None)
current = check.get("current", None)
if user is None or repo is None or current is None:
raise ConfigurationInvalid("Update configuration for {} of type github_release needs all of user, repo and current set and not None".format(target))
include_prerelease = check.get("prerelease", False)
prerelease_channel = check.get("prerelease_channel", None)
force_base = check.get("force_base", True)

View file

@ -8,7 +8,8 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
from ..exceptions import ConfigurationInvalid
def get_latest(target, check, full_data=False):
if not "python_checker" in check:
raise ConfigurationInvalid("Update configuration for %s of type commandline needs command defined" % target)
python_checker = check.get("python_checker")
if python_checker is None or not hasattr(python_checker, "get_latest"):
raise ConfigurationInvalid("Update configuration for {} of type python_checker needs python_checker defined and have an attribute \"get_latest\"".format(target))
return check["python_checker"].get_latest(target, check, full_data=full_data)