add alfred socket support (--alfred-sock)
This commit is contained in:
parent
c74b7b95fb
commit
6fba8ad21b
2 changed files with 33 additions and 12 deletions
|
@ -1,20 +1,35 @@
|
|||
import subprocess
|
||||
import json
|
||||
import os
|
||||
|
||||
|
||||
def _fetch(data_type):
|
||||
output = subprocess.check_output(
|
||||
["alfred-json", "-z", "-f", "json", "-r", str(data_type)])
|
||||
return json.loads(output.decode("utf-8")).values()
|
||||
class Alfred(object):
|
||||
"""
|
||||
Bindings for the alfred-json utility
|
||||
"""
|
||||
def __init__(self, unix_sockpath=None):
|
||||
if unix_sockpath:
|
||||
if os.path.exists(unix_sockpath):
|
||||
self.unix_sock = unix_sockpath
|
||||
else:
|
||||
raise RuntimeError('alfred: invalid unix socket path given')
|
||||
|
||||
def _fetch(self, data_type):
|
||||
cmd = ['alfred-json',
|
||||
'-z',
|
||||
'-f', 'json',
|
||||
'-r', data_type]
|
||||
if self.unix_sock:
|
||||
cmd.extend(['-s', self.unix_sock])
|
||||
|
||||
def nodeinfo():
|
||||
return _fetch(158)
|
||||
output = subprocess.check_output(cmd)
|
||||
return json.loads(output.decode("utf-8")).values()
|
||||
|
||||
def nodeinfo(self):
|
||||
return self._fetch(158)
|
||||
|
||||
def statistics():
|
||||
return _fetch(159)
|
||||
def statistics(self):
|
||||
return self._fetch(159)
|
||||
|
||||
|
||||
def vis():
|
||||
return _fetch(160)
|
||||
def vis(self):
|
||||
return self._fetch(160)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue