def setImageDir(self, args): rval = "ok" id = args[0] path = self.getCacheDir(id) self.queue.put(path) print("SetImageDir to %s: %s" % (path, rval)) return Hosts.jsonStatus(rval)
def cmdHandler(self, cmd): Debug().p("%s handling cmd: %s" % (self.name, cmd['cmd'])) if cmd['cmd'] not in self.commandTable.keys(): return Hosts.jsonStatus( "%s: %s not implemented" % (self.name, cmd['cmd']), False) status = self.commandTable[cmd['cmd']](cmd['args']) return status
def clearCache(args): path = ImageHandler.getImageCache() for f in os.listdir(path): try: r = path + "/%s" % f print("rm: %s" % r) shutil.rmtree(path) except OSError as e: rval = "Error: %s - %s." % (e.filename, e.strerror) return Hosts.jsonStatus("ok")
def rmCacheDir(args): rval = "ok" id = args[0] path = ImageHandler.getCacheDir(id) try: shutil.rmtree(path) except OSError as e: rval = "Error: %s - %s." % (e.filename, e.strerror) print("rmCacheDir: path %s %s" % (path, rval)) return Hosts.jsonStatus(rval)
def addImage(self, args): id = args['id'] imgData = args['imgData'] if self.currentId is None or self.currentId != id: self.currentId = id print("addImage currentId: %d" % self.currentId) path = self.getCacheDir(self.currentId) for d in imgData: file = path + "/%s" % d['name'] print("---name: %s" % file) with open(file, 'wb') as f: f.write(base64.b64decode(d['img'])) return Hosts.jsonStatus("ok")
def setSearchType(self, args): self.searchType = args['type'] Debug().p("%s set Search Type to %s" % (self.name, self.searchType)) Archive().reset() return Hosts.jsonStatus("ok")
def startMusic(self, cmd): self.queue.put("__start__") return Hosts.jsonStatus(str(cmd))
def haltMusic(self, cmd): self.queue.put("__halt__") return Hosts.jsonStatus(str(cmd))
def mute(self, args): self.musicBlocks[args['ip']].mute = args['mute'] return Hosts.jsonStatus(str(args))
def haltRecog(self,cmd): Debug().p("halting recog") self.queue.put("__halt__") return Hosts.jsonStatus("ok")
def startRecog(self,cmd): Debug().p("starting recog") self.queue.put("__start__") return Hosts.jsonStatus("ok")
def doHalt(self, cmd): for t in self.eventThreads: t.halt() return Hosts.jsonStatus(str(cmd))
def doSound(self, cmd): for t in self.eventThreads: t.setCurrentSound(cmd) return Hosts.jsonStatus(str(cmd))
def haltVoice(self, cmd): self.queue.put("__halt__") return Hosts.jsonStatus("ok")
def startVoice(self, cmd): self.queue.put("__start__") return Hosts.jsonStatus("ok")