def setPhrase(args): global phrase p = args print("%s setting phrase to %s"%(name,p['phrase'])) phraseMutex.acquire() phrase=p phraseMutex.release() return host.jsonStatus("ok")
def clearCache(args): path = 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 host.jsonStatus("ok")
def setImageDir(args): rval = "ok" id = args[0] global imageDir path = getCacheDir(id) idLock.acquire() imageDir = path idLock.release() print("SetImageDir to %s: %s"%(imageDir,rval)) return host.jsonStatus(rval)
def rmCacheDir(args): rval = "ok" id = args[0] path = 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 host.jsonStatus(rval)
def addImage(args): global currentId id = args['id'] imgData = args['imgData'] if currentId is None or currentId != id: currentId = id print("addImage currentId: %d"%currentId) path = getCacheDir(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 host.jsonStatus("ok");
def handleCmd(cmd): if debug: print("handling cmd:"+str(cmd['cmd'])); if cmd['cmd'] not in cmds.keys(): return host.jsonStatus("%s: not implemented"%cmd['cmd']); status = cmds[cmd['cmd']](cmd['args']) return status
def doReboot(cmd): return host.jsonStatus("reboot");
def doPoweroff(cmd): return host.jsonStatus("poweroff");
def doUpgrade(cmd): upgrade.upgrade() print("returned from upgrade") return host.jsonStatus("reboot")
def setSearchType(t): global searchType searchType = t[0] archive.init = False return host.jsonStatus("ok")