@@ -62,12 +62,14 @@ def age(self):
62
62
return datetime .datetime .now ()- self .time
63
63
64
64
class TStat :
65
- def __init__ (self , address , cacheExpiry = 5 , api = None , logger = None ):
65
+ def __init__ (self , address , cacheExpiry = 5 , api = None , logger = None , logLevel = None ):
66
66
self .address = address
67
67
self .setCacheExpiry (cacheExpiry )
68
68
self .cache = {}
69
69
if logger is None :
70
- logging .basicConfig (level = logging .DEBUG )
70
+ if logLevel is None :
71
+ logLevel = logging .WARNING
72
+ logging .basicConfig (level = logLevel )
71
73
self .logger = logging .getLogger ('TStat' )
72
74
else :
73
75
self .logger = logger
@@ -147,7 +149,10 @@ def _get(self, key, raw=False):
147
149
# Allow mappings to subdictionaries in json data
148
150
# e.g. 'today/heat_runtime' from '/tstat/datalog'
149
151
for key in getter [1 ].split ("/" ):
150
- response = response [key ]
152
+ try :
153
+ response = response [key ]
154
+ except :
155
+ pass
151
156
152
157
#response = response[getter[1]]
153
158
@@ -247,3 +252,14 @@ def setCloudMode(self, state=True):
247
252
if not state :
248
253
command = "off"
249
254
return self ._post ("/cloud/mode" , {'command' : command })
255
+
256
+ def main ():
257
+ import sys
258
+ addr = sys .argv [1 ]
259
+ t = TStat (addr )
260
+ for cmd in sys .argv [2 :]:
261
+ result = eval ("t.%s()" % cmd )
262
+ print "%s: %s" % (cmd , result )
263
+
264
+ if __name__ == '__main__' :
265
+ main ()
0 commit comments