From 9cd52d248f38450112bc6e997e34661cbb40084f Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Sun, 11 Nov 2018 02:36:52 +0100 Subject: [PATCH] fix flake8; add mosquitto2mqtt script --- jdk.py | 8 +++++--- nodejs.py | 5 +++-- zigbee2mqtt.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) create mode 100755 zigbee2mqtt.py diff --git a/jdk.py b/jdk.py index d7818d2..4b5bf4b 100755 --- a/jdk.py +++ b/jdk.py @@ -15,7 +15,8 @@ def fetch_java_version(): args = cmd.split(" ") try: - proc = subprocess.check_output(args, stderr=subprocess.STDOUT, universal_newlines=True) + proc = subprocess.check_output( + args, stderr=subprocess.STDOUT, universal_newlines=True) proc = proc.splitlines() for line in proc: lines.append(line.rstrip()) @@ -36,7 +37,8 @@ def get_vendor_version(): exp_zulu = re.compile(r"zulu (\d+(\.\d+){1,})") vendor = "zulu" - version = "%s-jdk%s" % (exp_zulu.search(line).group(1), exp_jdk.search(line).group()) + version = "%s-jdk%s" % (exp_zulu.search(line).group(1), + exp_jdk.search(line).group()) else: exp = re.compile(r"(\d+(\.\d+){1,})") version = exp.search(line).group() @@ -52,7 +54,7 @@ def main(): result.update(vendor=vendor) result.update(version=version) result.update(error=False) - except OSError as e: + except OSError: result.update(vendor="nobody") result.update(version="0.0.0") result.update(error=False) diff --git a/nodejs.py b/nodejs.py index 298be13..56f38b0 100755 --- a/nodejs.py +++ b/nodejs.py @@ -15,7 +15,8 @@ def fetch_nodejs_version(): args = cmd.split(" ") try: - proc = subprocess.check_output(args, stderr=subprocess.STDOUT, universal_newlines=True) + proc = subprocess.check_output( + args, stderr=subprocess.STDOUT, universal_newlines=True) proc = proc.splitlines() for line in proc: lines.append(line.rstrip()) @@ -36,7 +37,7 @@ def main(): version = fetch_nodejs_version() result.update(version=version) result.update(error=False) - except OSError as e: + except OSError: result.update(version="0.0.0") result.update(error=False) except Exception as e: diff --git a/zigbee2mqtt.py b/zigbee2mqtt.py new file mode 100755 index 0000000..1b4692a --- /dev/null +++ b/zigbee2mqtt.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python2.7 +# -*- coding: UTF-8 -*- + +import re +import json +import subprocess + +from collections import defaultdict + + +def fetch_zigbee2mqtt_version(): + lines = [] + + cmd = "git describe --tags" + args = cmd.split(" ") + + try: + proc = subprocess.check_output( + args, stderr=subprocess.STDOUT, universal_newlines=True, + cwd="/opt/zigbee2mqtt") + proc = proc.splitlines() + for line in proc: + lines.append(line.rstrip()) + + exp = re.compile(r"(\d+(\.\d+){1,})") + version = exp.search(lines[0]).group() + + except Exception: + raise + + return version + + +def main(): + result = defaultdict(dict) + + try: + version = fetch_zigbee2mqtt_version() + result.update(version=version) + result.update(error=False) + except OSError: + result.update(version="0.0.0") + result.update(error=False) + except Exception as e: + result.update(error=True) + result.update(message=str(e)) + + print(json.dumps(result)) + + +if __name__ == "__main__": + main()