瀏覽代碼

add sanity check for alfred-json

check that the binary exists, can be called and returns sane JSON
Helge Jung 10 年之前
父節點
當前提交
d15aca4feb
共有 1 個文件被更改,包括 15 次插入0 次删除
  1. 15 0
      ffstatus.py

+ 15 - 0
ffstatus.py

@@ -31,6 +31,20 @@ class AlfredParser:
 	alfred_dump = '/www/alfred.json'
 	whitelist = [ "24:a4:3c:f8:5e:fa", "24:a4:3c:f8:5e:db", "24:a4:3c:d9:4f:69", "24:a4:3c:a3:67:f0", "24:a4:3c:a3:68:07", "24:a4:3c:d2:21:d5" ]
 
+	def sanitycheck(self):
+		testdata = None
+		try:
+			testdata = subprocess.check_output(['alfred-json', '-z', 'r', str(int(self.alfred_datatypes[0]))])
+		except Exception as err:
+			raise Exception("alfred-json not found or incompatible: " + str(err))
+
+		try:
+			check = json.loads(testdata)
+		except Exception as err:
+			raise Exception("alfred-json does not return valid JSON data: " + str(err))
+
+		return True
+
 	def execute(self):
 		data = { }
 		ts = int(time.time())
@@ -81,4 +95,5 @@ class AlfredParser:
 
 if __name__ == "__main__":
 	a = AlfredParser()
+	a.sanitycheck()
 	a.execute()