fix encoding and python 3 errors; add nodejs fact

This commit is contained in:
Robert Kaussow 2018-11-10 14:20:59 +01:00
parent a71e61daf0
commit f9ea9e219a
3 changed files with 63 additions and 6 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "env/bin/python"
}

16
jdk.py Normal file → Executable file
View File

@ -15,7 +15,7 @@ def fetch_java_version():
args = cmd.split(" ") args = cmd.split(" ")
try: try:
proc = subprocess.check_output(args, stderr=subprocess.STDOUT) 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())
@ -32,13 +32,13 @@ def get_vendor_version():
vendor = (line.split()[0]).lower() vendor = (line.split()[0]).lower()
if vendor == "openjdk" and "zulu" in line: if vendor == "openjdk" and "zulu" in line:
exp_jdk = re.compile("(\d(\.\d+){1,}_\d+)") exp_jdk = re.compile(r"(\d+(\.\d+){1,}_\d+)")
exp_zulu = re.compile("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("(\d(\.\d+){1,})") exp = re.compile(r"(\d+(\.\d+){1,})")
version = exp.search(line).group() version = exp.search(line).group()
return (vendor, version) return (vendor, version)
@ -52,11 +52,15 @@ 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:
result.update(vendor="nobody")
result.update(version="0.0.0")
result.update(error=False)
except Exception as e: except Exception as e:
result.update(error=True) result.update(error=True)
result.update(message=e.strerror) result.update(message=str(e))
print json.dumps(result) print(json.dumps(result))
if __name__ == "__main__": if __name__ == "__main__":

50
nodejs.py Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python2.7
# -*- coding: UTF-8 -*-
import re
import json
import subprocess
from collections import defaultdict
def fetch_nodejs_version():
lines = []
cmd = "node --version"
args = cmd.split(" ")
try:
proc = subprocess.check_output(args, stderr=subprocess.STDOUT, universal_newlines=True)
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_nodejs_version()
result.update(version=version)
result.update(error=False)
except OSError as e:
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()