def doAPI(req): try: if req and'action' in req: if req['action'] in actions: action = actions[req['action']] # status.pushStatus("API: " + req['action']) params = action[1][:] valid = True missing = [] for p in params: if not p in req: valid = False missing.append(p) if not valid: return fail("Missing parameters.", data=missing) return action[0](req) else: return fail("Invalid action.") else: return fail("Invalid request data.") except Exception, e: status.pushError(traceback.format_exc()) return fail(str(e), error=ErrorCode.GENERAL_ERROR, data=None)
def doAPI(req): try: if req and 'action' in req: if req['action'] in actions: action = actions[req['action']] # status.pushStatus("API: " + req['action']) params = action[1][:] valid = True missing = [] for p in params: if not p in req: valid = False missing.append(p) if not valid: return fail("Missing parameters.", data=missing) return action[0](req) else: return fail("Invalid action.") else: return fail("Invalid request data.") except Exception, e: status.pushError(traceback.format_exc()) return fail(str(e), error=ErrorCode.GENERAL_ERROR, data=None)
def load_module(path): try: try: code_dir = os.path.dirname(path) code_file = os.path.basename(path) base = code_file.replace(".py", "") fin = open(path, 'rb') hash = md5.new(path).hexdigest() + "_" + code_file return (base, imp.load_source(base, path, fin)) except Exception, e: status.pushError("Error loading {}".format(path)) status.pushError(e) return (None, None) finally: try: fin.close() except: pass
def api(): req = d(request.json) result = doAPI(req) if not result.status: status.pushError(result.msg) return result