fix encoding and python 3 errors; add nodejs fact
This commit is contained in:
parent
a71e61daf0
commit
f9ea9e219a
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"python.pythonPath": "env/bin/python"
|
||||
}
|
16
jdk.py
Normal file → Executable file
16
jdk.py
Normal file → Executable file
@ -15,7 +15,7 @@ def fetch_java_version():
|
||||
args = cmd.split(" ")
|
||||
|
||||
try:
|
||||
proc = subprocess.check_output(args, stderr=subprocess.STDOUT)
|
||||
proc = subprocess.check_output(args, stderr=subprocess.STDOUT, universal_newlines=True)
|
||||
proc = proc.splitlines()
|
||||
for line in proc:
|
||||
lines.append(line.rstrip())
|
||||
@ -32,13 +32,13 @@ def get_vendor_version():
|
||||
vendor = (line.split()[0]).lower()
|
||||
|
||||
if vendor == "openjdk" and "zulu" in line:
|
||||
exp_jdk = re.compile("(\d(\.\d+){1,}_\d+)")
|
||||
exp_zulu = re.compile("zulu (\d(\.\d+){1,})")
|
||||
exp_jdk = re.compile(r"(\d+(\.\d+){1,}_\d+)")
|
||||
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())
|
||||
else:
|
||||
exp = re.compile("(\d(\.\d+){1,})")
|
||||
exp = re.compile(r"(\d+(\.\d+){1,})")
|
||||
version = exp.search(line).group()
|
||||
|
||||
return (vendor, version)
|
||||
@ -52,11 +52,15 @@ def main():
|
||||
result.update(vendor=vendor)
|
||||
result.update(version=version)
|
||||
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:
|
||||
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__":
|
||||
|
50
nodejs.py
Executable file
50
nodejs.py
Executable 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()
|
Reference in New Issue
Block a user