fix flake8; add mosquitto2mqtt script
This commit is contained in:
parent
58ed9c0bc2
commit
9cd52d248f
8
jdk.py
8
jdk.py
@ -15,7 +15,8 @@ def fetch_java_version():
|
|||||||
args = cmd.split(" ")
|
args = cmd.split(" ")
|
||||||
|
|
||||||
try:
|
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()
|
proc = proc.splitlines()
|
||||||
for line in proc:
|
for line in proc:
|
||||||
lines.append(line.rstrip())
|
lines.append(line.rstrip())
|
||||||
@ -36,7 +37,8 @@ def get_vendor_version():
|
|||||||
exp_zulu = re.compile(r"zulu (\d+(\.\d+){1,})")
|
exp_zulu = re.compile(r"zulu (\d+(\.\d+){1,})")
|
||||||
|
|
||||||
vendor = "zulu"
|
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:
|
else:
|
||||||
exp = re.compile(r"(\d+(\.\d+){1,})")
|
exp = re.compile(r"(\d+(\.\d+){1,})")
|
||||||
version = exp.search(line).group()
|
version = exp.search(line).group()
|
||||||
@ -52,7 +54,7 @@ def main():
|
|||||||
result.update(vendor=vendor)
|
result.update(vendor=vendor)
|
||||||
result.update(version=version)
|
result.update(version=version)
|
||||||
result.update(error=False)
|
result.update(error=False)
|
||||||
except OSError as e:
|
except OSError:
|
||||||
result.update(vendor="nobody")
|
result.update(vendor="nobody")
|
||||||
result.update(version="0.0.0")
|
result.update(version="0.0.0")
|
||||||
result.update(error=False)
|
result.update(error=False)
|
||||||
|
@ -15,7 +15,8 @@ def fetch_nodejs_version():
|
|||||||
args = cmd.split(" ")
|
args = cmd.split(" ")
|
||||||
|
|
||||||
try:
|
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()
|
proc = proc.splitlines()
|
||||||
for line in proc:
|
for line in proc:
|
||||||
lines.append(line.rstrip())
|
lines.append(line.rstrip())
|
||||||
@ -36,7 +37,7 @@ def main():
|
|||||||
version = fetch_nodejs_version()
|
version = fetch_nodejs_version()
|
||||||
result.update(version=version)
|
result.update(version=version)
|
||||||
result.update(error=False)
|
result.update(error=False)
|
||||||
except OSError as e:
|
except OSError:
|
||||||
result.update(version="0.0.0")
|
result.update(version="0.0.0")
|
||||||
result.update(error=False)
|
result.update(error=False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
52
zigbee2mqtt.py
Executable file
52
zigbee2mqtt.py
Executable file
@ -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()
|
Reference in New Issue
Block a user