Small simplifications and clarifications

This commit is contained in:
Gina Häußge 2017-07-06 16:18:55 +02:00
parent e86ba9a395
commit 4c6c764c5c
2 changed files with 11 additions and 15 deletions

View file

@ -8,8 +8,6 @@ import requests
import logging
import base64
from ..exceptions import ConfigurationInvalid
BRANCH_HEAD_URL = "https://api.bitbucket.org/2.0/repositories/{user}/{repo}/commit/{branch}"
logger = logging.getLogger("octoprint.plugins.softwareupdate.version_checks.bitbucket_commit")
@ -19,8 +17,8 @@ def _get_latest_commit(user, repo, branch, api_user=None, api_password=None):
url = BRANCH_HEAD_URL.format(user=user, repo=repo, branch=branch)
headers = {}
if api_user is not None and api_password is not None:
headers['authorization'] = 'Basic {}'.format(
base64.b64encode(b"{user}:{pw}".format(user=api_user, pw=api_password)))
auth_value = base64.b64encode(b"{user}:{pw}".format(user=api_user, pw=api_password))
headers["authorization"] = "Basic {}".format(auth_value)
r = requests.get(url, headers=headers)
if not r.status_code == requests.codes.ok:
@ -34,19 +32,19 @@ def _get_latest_commit(user, repo, branch, api_user=None, api_password=None):
def get_latest(target, check):
from ..exceptions import ConfigurationInvalid
if "user" not in check or "repo" not in check:
raise ConfigurationInvalid("Update configuration for %s of type bitbucket_commit needs all of user and repo" % target)
branch = "master"
if "branch" in check:
if "branch" in check and check["branch"] is not None:
branch = check["branch"]
api_user = check["api_user"] if 'api_user' in check else None
api_password = check["api_password"] if 'api_password' in check else None
api_user = check.get("api_user")
api_password = check.get("api_password")
current = None
if "current" in check:
current = check["current"]
current = check.get("current")
remote_commit = _get_latest_commit(check["user"], check["repo"], branch, api_user, api_password)

View file

@ -8,8 +8,6 @@ __copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms
import requests
import logging
from ..exceptions import ConfigurationInvalid
BRANCH_HEAD_URL = "https://api.github.com/repos/{user}/{repo}/git/refs/heads/{branch}"
logger = logging.getLogger("octoprint.plugins.softwareupdate.version_checks.github_commit")
@ -31,6 +29,8 @@ def _get_latest_commit(user, repo, branch):
def get_latest(target, check):
from ..exceptions import ConfigurationInvalid
user = check.get("user")
repo = check.get("repo")
@ -41,9 +41,7 @@ def get_latest(target, check):
if "branch" in check and check["branch"] is not None:
branch = check["branch"]
current = None
if "current" in check:
current = check["current"]
current = check.get("current")
remote_commit = _get_latest_commit(check["user"], check["repo"], branch)