2014-01-24 02:53:17 +01:00
|
|
|
import subprocess
|
|
|
|
import json
|
2015-03-24 22:48:00 +01:00
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
class Alfred(object):
|
|
|
|
"""
|
|
|
|
Bindings for the alfred-json utility
|
|
|
|
"""
|
|
|
|
def __init__(self, unix_sockpath=None):
|
2015-03-24 23:17:24 +01:00
|
|
|
self.unix_sock = unix_sockpath
|
|
|
|
if unix_sockpath is not None and not os.path.exists(unix_sockpath):
|
|
|
|
raise RuntimeError('alfred: invalid unix socket path given')
|
2015-03-24 22:48:00 +01:00
|
|
|
|
|
|
|
def _fetch(self, data_type):
|
2015-12-01 19:29:57 +01:00
|
|
|
cmd = ['/usr/local/bin/alfred-json',
|
2015-03-24 22:48:00 +01:00
|
|
|
'-z',
|
|
|
|
'-f', 'json',
|
2015-03-24 23:17:24 +01:00
|
|
|
'-r', str(data_type)]
|
2015-03-24 22:48:00 +01:00
|
|
|
if self.unix_sock:
|
|
|
|
cmd.extend(['-s', self.unix_sock])
|
|
|
|
|
|
|
|
output = subprocess.check_output(cmd)
|
|
|
|
return json.loads(output.decode("utf-8")).values()
|
|
|
|
|
|
|
|
def nodeinfo(self):
|
|
|
|
return self._fetch(158)
|
|
|
|
|
|
|
|
def statistics(self):
|
|
|
|
return self._fetch(159)
|
|
|
|
|
|
|
|
def vis(self):
|
|
|
|
return self._fetch(160)
|