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()