52 lines
1.0 KiB
Python
Executable File
52 lines
1.0 KiB
Python
Executable File
#!/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:
|
|
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()
|