def test_log_api(self): """ Test get exist option """ OrcTest.test_print_begin() init_log() _log = OrcLog("api.test01") _log.info("This 001!") _log.warning("This 002!") _log.error("This 003!") _log.critical("This 004!") _log.debug("This 005!") OrcTest.test_print_end()
class StatusReceiver(QThread): sig_status = OrcSignal(str) def __init__(self): QThread.__init__(self) self.__config = get_config("network") self.__logger = OrcLog("view") def run(self, *args, **kwargs): _ip = self.__config.get_option("VIEW", "ip") _port = int(self.__config.get_option("VIEW", "port")) sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((_ip, _port)) sock.listen(1) while True: connection, address = sock.accept() try: connection.settimeout(5) _cmd = connection.recv(1024) self.sig_status.emit(_cmd) connection.send(_cmd) except socket.timeout: self.__logger.error("time out") except Exception, err: self.__logger.error(err) connection.close()
class RunDefBus(object): def __init__(self): object.__init__(self) self.__logger = OrcLog("api.run.bus.run_def") self.__model_run_def = RunDefMod() def bus_list_add(self, p_data): """ 新增 :param p_data: :return: """ try: result = self.__model_run_def.usr_add(p_data) except Exception: self.__logger.error("Add run error, input: %s" % p_data) raise OrcApiModelFailException self.__logger.debug("function %s return %s" % ("bus_list_add", result)) return result def bus_list_delete(self, p_list): """ 删除 :param p_list: :return: """ try: self.__model_run_def.usr_delete(p_list) except Exception: self.__logger.error("Add batch error, input: %s" % p_list) raise OrcApiModelFailException return True def bus_list_search(self, p_cond): """ 查询 :param p_cond: :return: """ try: result = self.__model_run_def.usr_search(p_cond) except Exception: self.__logger.error("Add batch error, input: %s" % p_cond) raise OrcApiModelFailException return result
class WidgetDefBus(object): def __init__(self): object.__init__(self) init_log() self.__logger = OrcLog("api.driver.web.widget.bus.widget_def") self.__model_widget_def = WidgetDefMod() self.__bus_widget_det = WidgetDetBus() def bus_list_add(self, p_data): """ 新增 :param p_data: :return: """ try: result = self.__model_widget_def.usr_add(p_data) except Exception: self.__logger.error("Add widget error, input: %s" % p_data) raise OrcApiModelFailException return result def bus_list_delete(self, p_list): """ 删除 :param p_list: :return: """ try: for _id in p_list: self.bus_delete(_id) except Exception: self.__logger.error("Delete widget error, input: %s" % p_list) raise OrcApiModelFailException return True def bus_list_search(self, p_cond): """ 查询 :param p_cond: :return: """ result = [] mode = p_cond["type"] if "type" in p_cond else None widget_id = p_cond["id"] if "id" in p_cond else None try: # 查询符合条件的整用例树,至根节点 if "all" == mode: result = self.__model_widget_def.usr_search_all(p_cond) # 查询节点及子节点 elif "tree" == mode: if widget_id is not None: result = self.__model_widget_def.usr_search_tree(widget_id) # 查询节点路径 elif "path" == mode: if widget_id is not None: result = self.__model_widget_def.usr_search_path(widget_id) # 其他情况只查询符合条件的数据 else: result = self.__model_widget_def.usr_search(p_cond) except Exception: self.__logger.error("Search widget error, input: %s" % p_cond) raise OrcApiModelFailException return result def bus_delete(self, p_id): """ 删除单一步骤 :param p_id: :return: """ try: # 查找 widget_det_list widget_det_list = self.__bus_widget_det.bus_list_search( dict(widget_id=p_id)) # 获取 widget_det_id_list widget_det_id_list = [ widget_det.id for widget_det in widget_det_list ] # 删除 widget_dets self.__bus_widget_det.bus_list_delete(widget_det_id_list) # 删除 widget_def self.__model_widget_def.usr_delete(p_id) except Exception: self.__logger.error("Delete widget error, input: %s" % p_id) raise OrcApiModelFailException return True def bus_update(self, p_id, p_cond): """ 更新步骤 :param p_id: :param p_cond: :return: """ cond = dict(id=p_id) cond.update(p_cond) try: self.__model_widget_def.usr_update(cond) except Exception: self.__logger.error("Update widget error, input: %s" % cond) raise OrcApiModelFailException return True def bus_search(self, p_id): """ 查询单一步骤 :param p_id: :return: """ try: result = self.__model_widget_def.usr_search(dict(id=p_id)) result = None if not result else result[0] except Exception: self.__logger.error("Search widget error, input: %s" % p_id) raise OrcApiModelFailException return result
class WidgetDetBus(object): def __init__(self): object.__init__(self) init_log() self.__logger = OrcLog("api.driver.web.widget.bus.widget_det") self.__model_widget_det = WidgetDetMod() def bus_list_add(self, p_data): """ 新增 :param p_data: :return: """ try: result = self.__model_widget_det.usr_add(p_data) except Exception: self.__logger.error("Add widget detail error, input: %s" % p_data) raise OrcApiModelFailException return result def bus_list_delete(self, p_list): """ 删除 :param p_list: :return: """ try: for _id in p_list: self.bus_delete(_id) except Exception: self.__logger.error("Delete widget detail error, input: %s" % p_list) raise OrcApiModelFailException return True def bus_list_search(self, p_cond): """ 查询 :param p_cond: :return: """ try: result = self.__model_widget_det.usr_search(p_cond) except Exception: self.__logger.error("Search widget detail error, input: %s" % p_cond) raise OrcApiModelFailException return result def bus_delete(self, p_id): """ 删除单一 item :param p_id: :return: """ try: self.__model_widget_det.usr_delete(p_id) except Exception: self.__logger.error("Delete widget detail error, input: %s" % p_id) raise OrcApiModelFailException return True def bus_update(self, p_id, p_cond): """ 更新 :param p_id: :param p_cond: :return: """ cond = dict(id=p_id) cond.update(p_cond) try: self.__model_widget_det.usr_update(cond) except Exception: self.__logger.error("Update widget detail error, input: %s" % p_cond) raise OrcApiModelFailException return True def bus_search(self, p_id): """ 查询单一条目 :param p_id: :return: """ try: result = self.__model_widget_det.usr_search(dict(id=p_id)) result = None if not result else result[0] except Exception: self.__logger.error("Search widget detail error, input: %s" % p_id) raise OrcApiModelFailException return result
class ItemBus(object): def __init__(self): object.__init__(self) init_log() self.__logger = OrcLog("api.step.bus.step_def") self.__model_item = ItemMod() def bus_list_add(self, p_data): """ 新增 :param p_data: :return: """ try: result = self.__model_item.usr_add(p_data) except Exception: self.__logger.error("Add case error, input: %s" % p_data) raise OrcApiModelFailException return result def bus_list_delete(self, p_list): """ 删除 :param p_list: :return: """ try: for _id in p_list: self.bus_delete(_id) except Exception: self.__logger.error("Add case error, input: %s" % p_list) raise OrcApiModelFailException return True def bus_list_search(self, p_cond): """ 查询 :param p_cond: :return: """ try: result = self.__model_item.usr_search(p_cond) except Exception: self.__logger.error("Add case error, input: %s" % p_cond) raise OrcApiModelFailException return result def bus_delete(self, p_id): """ 删除一条 :param p_id: :return: """ try: self.__model_item.usr_delete(p_id) except Exception: self.__logger.error("Add case error, input: %s" % p_id) raise OrcApiModelFailException return True def bus_update(self, p_id, p_cond): """ 更新 :param p_id: :param p_cond: :return: """ cond = dict(id=p_id) cond.update(p_cond) try: self.__model_item.usr_update(cond) except Exception: self.__logger.error("Add case error, input: %s" % cond) raise OrcApiModelFailException return True def bus_search(self, p_id): """ 查询一条 :param p_id: :return: """ print "DDDD" print p_id print "DDD" try: result = self.__model_item.usr_search(dict(id=p_id)) result = None if not result else result[0] except Exception: self.__logger.error("Search item error, input: %s" % p_id) raise OrcApiModelFailException return result
class PageDefBus(object): def __init__(self): object.__init__(self) init_log() self.__logger = OrcLog("api.step.bus.step_def") self.__model_page_def = PageDefMod() self.__bus_page_det = PageDetBus() def bus_list_add(self, p_data): """ 新增 :param p_data: :return: """ try: result = self.__model_page_def.usr_add(p_data) except Exception: self.__logger.error("Add case error, input: %s" % p_data) raise OrcApiModelFailException return result def bus_list_delete(self, p_list): """ 删除 :param p_list: :return: """ try: for _id in p_list: self.bus_delete(_id) except Exception: self.__logger.error("Add case error, input: %s" % p_list) raise OrcApiModelFailException return True def bus_list_search(self, p_cond): """ 查询 :param p_cond: :return: """ try: result = self.__model_page_def.usr_search(p_cond) except Exception: self.__logger.error("Add case error, input: %s" % p_cond) raise OrcApiModelFailException return result def bus_delete(self, p_id): """ 删除单一步骤 :param p_id: :return: """ try: # 查找 page_det_list page_det_list = self.__bus_page_det.bus_list_search( dict(page_id=p_id)) # 获取 page_det_id_list page_det_id_list = [page_det.id for page_det in page_det_list] # 删除 page_dets self.__bus_page_det.bus_list_delete(page_det_id_list) # 删除 page_def self.__model_page_def.usr_delete(p_id) except Exception: self.__logger.error("Add case error, input: %s" % p_id) raise OrcApiModelFailException return True def bus_update(self, p_id, p_cond): """ 更新步骤 :param p_id: :param p_cond: :return: """ cond = dict(id=p_id) cond.update(p_cond) try: self.__model_page_def.usr_update(cond) except Exception: self.__logger.error("Add case error, input: %s" % cond) raise OrcApiModelFailException return True def bus_search(self, p_id): """ 查询单一步骤 :param p_id: :return: """ try: result = self.__model_page_def.usr_search(dict(id=p_id)) result = None if not result else result[0] except Exception: self.__logger.error("Add case error, input: %s" % p_id) raise OrcApiModelFailException return result
class StepDetBus(object): def __init__(self): object.__init__(self) init_log() self.__logger = OrcLog("api.step.bus.step_def") self.__model_step_det = StepDetMod() self.__bus_item = ItemBus() def bus_list_add(self, p_data): """ 新增 :param p_data: :return: """ try: result = self.__model_step_det.usr_add(p_data) except Exception: self.__logger.error("Add step error, input: %s" % p_data) raise OrcApiModelFailException return result def bus_list_delete(self, p_list): """ 删除 :param p_list: :return: """ try: for _id in p_list: self.bus_delete(_id) except Exception: self.__logger.error("Delete step error, input: %s" % p_list) raise OrcApiModelFailException return True def bus_list_search(self, p_cond): """ 查询 :param p_cond: :return: """ try: result = self.__model_step_det.usr_search(p_cond) except Exception: self.__logger.error("Search step error, input: %s" % p_cond) raise OrcApiModelFailException return result def bus_delete(self, p_id): """ 删除单一 item :param p_id: :return: """ try: # step_det step_det = self.bus_search(p_id) # item items = self.__bus_item.bus_list_search(dict(id=step_det.item_id)) item_ids = [item.id for item in items] # delete item self.__bus_item.bus_list_delete(item_ids) # delete step_det self.__model_step_det.usr_delete(p_id) except Exception: self.__logger.error("Delete step error, input: %s" % p_id) raise OrcApiModelFailException return True def bus_update(self, p_id, p_cond): """ 更新 :param p_id: :param p_cond: :return: """ cond = dict(id=p_id) cond.update(p_cond) try: self.__model_step_det.usr_update(cond) except Exception: self.__logger.error("Update step error, input: %s" % cond) raise OrcApiModelFailException return True def bus_search(self, p_id): """ 查询单一条目 :param p_id: :return: """ try: result = self.__model_step_det.usr_search(dict(id=p_id)) result = None if not result else result[0] except Exception: self.__logger.error("Search step error, input: %s" % p_id) raise OrcApiModelFailException return result