Переглянути джерело

add sanity check for alfred-json

check that the binary exists, can be called and returns sane JSON
Helge Jung 9 роки тому
батько
коміт
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()