Esempio n. 1
0
def deal_with_dataset_list(dataset_dict):
    """
    处理返回值
    可能会返回两个数据集,一个是通用信息,一个是数据结果集
    :param dataset_dict:
    :return:
    """
    try:
        print "dataset_list####################################"
        print dataset_dict
        dataset_list = []
        if True:  # 返回通用信息
            data = {'message': str(dataset_dict)}
            data['field'] = list(dataset_dict.keys())
            dataset_list.append(data['field'] )

            values_list = []
            values_list.append(list(dataset_dict.values()))
            # for i in dataset_list[0][1:]:
            #     i_new = []
            #     for j in i:
            #         i_new.append(j.replace("'", "''"))
            #     if len(str(values_list).replace(' ', '')) <= 90000:
            #         values_list.append(i_new)
            data['values_list'] = values_list
            dataset_list.append(data['values_list'])
        if dataset_dict and dataset_dict.has_key("business_reject_text") and dataset_dict.has_key("reject_reason_code"):
            return -1, data, dataset_list
        return 0, data, dataset_list
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().error(exc_info)
        return -1, exc_info, []
Esempio n. 2
0
    def register_client(self):
        """
        注册客户端
        :return:
        """
        try:
            func_body = OrderedDict()
            func_body["func"] = "register_client"
            
            func_body["func_param"] = ("%s" % str(self._agent_id),)
            
            ret, msg = self.call_server_rpc(func_body)
            if ret < 0:
                Logging.getLog().error(msg)
                return -1, msg
            

            # 启动一个线程去拉命令队列
            # self.listen_cmd_queue_thread()
            self._cmd_thread = threading.Thread(target=self.listen_cmd_queue_thread)
            self._cmd_thread.start()
            # 启动一个线程去侦听任务队列
            self._task_thread = threading.Thread(target=self.listen_task_queue)
            self._task_thread.start()
            
            return 0, ""
        except Exception, ex:
            exc_info = cF.getExceptionInfo()
            Logging.getLog().error(exc_info)
            return -1, ""
Esempio n. 3
0
def dbf_read_write_info(path, index_column_name_values, update_column_name_value):
    # dbf_read_write_info('C:\\test.dbf', "YMTH=180000000040&KHRQ=20161013", "KHMC=花果山水帘洞20180203")
    try:
        Logging.getLog().info(u"path:%s, index_column_name_values:%s, update_column_name_value:%s" % (
        path, str(index_column_name_values), str(update_column_name_value)))
        if "ZDMNHB.ini" in path:
            update_ini_file(path, index_column_name_values, update_column_name_value)
            logging.getLogger("更新成功 ZDMNHB.ini")
            return 0, ("",)
        logging.getLogger("enter dbf_read_write_info")
        # 判断是否需要修改多个文件的内容
        # print path, index_column_name_values, update_column_name_value
        if '|' in update_column_name_value:
            update_column_name_values = update_column_name_value.split("|")
            if update_column_name_values:
                update_column_name_value = update_column_name_values[0]
                if 'delete' in path:
                    path = path.replace("delete", "")
                    delete_dbf_file(path, index_column_name_values, update_column_name_value)
                else:
                    update_dbf_file(path, index_column_name_values, update_column_name_value)
            if len(update_column_name_values) >= 2:
                for i in update_column_name_values[1:]:
                    path, index_column_name_values, update_column_name_value = i.split(";")
                    update_dbf_file(path, index_column_name_values, update_column_name_value)
        elif 'delete' in path:
            path = path.replace("delete", "")
            delete_dbf_file(path, index_column_name_values, update_column_name_value)
        else:
            update_dbf_file(path, index_column_name_values, update_column_name_value)
        return 0, ("",)
    except:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().error(exc_info)
        return -1, exc_info
Esempio n. 4
0
def main():
    # signal.signal(signal.SIGINT, processTerm)
    # signal.signal(signal.SIGTERM, processTerm)
    Logging.getLog().info(u'''
    时溪自动化测试平台-Test Agent v2.0 2018.08.22
    (上海时溪信息技术有限公司)
    ''')
    config_name = 'TestAgent.ini'
    # cF.readConfigFile()

    # determine if application is a script file or frozen exe
    if getattr(sys, 'frozen', False):
        application_path = os.path.dirname(sys.executable)
    elif __file__:
        application_path = os.path.dirname(__file__)

    config_path = os.path.join(application_path, config_name)

    mqclient_setting = json.loads(open(config_path, "r").read())

    mqclient = MQClient(mqclient_setting)
    mqclient.setDaemon(True)
    mqclient.start()
    
    ret, ret_info = mqclient.register_client()
    print ret, ret_info
    # mqclient.start_appium_server()
    while True:
        pass
Esempio n. 5
0
    def register_client(self, id):
        try:
            Logging.getLog().debug("receive register_client(%s)\n" % (id))
            agent_id = str(id)

            self._clients_dict[agent_id] = OrderedDict()
            
            #创建一个队列
            new_queue_name = "cmd_queue_%s" % str(id)
            if new_queue_name not in self._channel_dict.keys():
                channel = self._connection.channel()
                channel.queue_declare(queue=new_queue_name)
                self._channel_dict[new_queue_name] = channel
            
            #通知更新脚本
            # cmd_dict = OrderedDict()
            # cmd_dict["func"] = "processScriptUpdate"
            # cmd_dict["func_param"] = ""
            update_script_msg = copy.copy(gl.update_script_msg)
            
            channel = self._channel_dict[new_queue_name]
            channel.basic_publish(exchange='',
                  routing_key=new_queue_name,
                  body=json.dumps(update_script_msg, ensure_ascii=False))
        
            return 0, "OK"
        except:
            exc_info = cF.getExceptionInfo()
            print exc_info
            return -1, exc_info
Esempio n. 6
0
    def rpc_process(self, ch, method, props, body):
        try:
            msg_dict = json.loads(body)
            return_dict = OrderedDict()
            
            if msg_dict["func_param"] == "":
                func_call = "self.%s()" % msg_dict["func"]
            else:
                # func_call = "self.%s(%s)" % (msg_dict["func"], ','.join(str(i) for i in msg_dict["func_param"]))
                func_call = "self.%s(%s)" % (msg_dict["func"], ','.join("'%s'" % str(i) for i in msg_dict["func_param"]))

            Logging.getLog().debug(func_call)
            ret, ret_info = eval(func_call)
            # ret, ret_info = eval("self.%s" % msg_dict["func"])tuple(msg_dict["func_param"])
            return_dict["return"] = ret
            return_dict["return_info"] = ret_info
            
            ch.basic_publish(exchange='',
                             routing_key=props.reply_to,
                             properties=pika.BasicProperties(correlation_id= \
                                                                 props.correlation_id),
                             body=json.dumps(return_dict, ensure_ascii=False))
            ch.basic_ack(delivery_tag=method.delivery_tag)
        except Exception, ex:
            exc_info = cF.getExceptionInfo()
            Logging.getLog().error(exc_info)
Esempio n. 7
0
 def read_curr_task_list(self):
     try:
         curr_task_list = self.r.lrange("curr_task_list", 0, -1)
         return 0, curr_task_list
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 8
0
 def read_task_env_init_state(self, task_id):
     try:
         state = self.r.hget("task_init_state:%s" % str(task_id), "INIT_STATE")
         return 0, state
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 9
0
def selct():
    try:
        conn = DB2SkDB()
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        err = u"连接数据库出现异常,%s" % exc_info
        Logging.getLog().critical(err)
        return -1, err
Esempio n. 10
0
 def get_agent_id_data_list(self):
     agent_id_data_list = self.r.lrange("agent_id_data_list", 0, -1)
     if len(agent_id_data_list) > 0:
         Logging.getLog().debug(u"get_agent_id_data_list %d" % len(agent_id_data_list))
         self.r.delete("agent_id_data_list")
         return 0, agent_id_data_list
     else:
         return -1, ""
Esempio n. 11
0
 def set_account_data_list(self, account_info):
     """
     账号数据
     :param account_info:
     :return:
     """
     Logging.getLog().debug(u"set_account_data_list %s" % account_info)
     self.r.rpush("account_data_list", account_info)
     return 0, ""
Esempio n. 12
0
 def set_agent_id_data_list(self, agent_id_data):
     """
     账号数据
     :param agent_id_data:
     :return:
     """
     Logging.getLog().debug(u"set_agent_id_data_list %s" % agent_id_data)
     self.r.rpush("agent_id_data_list", agent_id_data)
     return 0, ""
Esempio n. 13
0
 def run(self):
     while gl.is_exit_all_thread == False:
         input_string = raw_input("please input what you want server to do:")
         input_list = input_string.split(' ')
         if input_list[0] == "new_task":
             self.fire_new_task(input_list[1], input_list[2], input_list[3])
         elif input_list[0] == "cancel_task":
             self.cancel_a_task(input_list[1], input_list[2])
     Logging.getLog().debug("Exit server loop")
Esempio n. 14
0
    def add_new_task_to_redis(self, task_id, collection_id, collection_name, system_id, cases_num, timed_task_flag,
                              run_record_id_list, warning_info, agent_list):
        """
        新建一个任务,向redis存放一个任务
        :param task_id:
        :param collection_id:
        :param collection_name:
        :param system_id:
        :param cases_num:
        :param timed_task_flag:
        :param run_record_id_list:
        :param warning_info: 警告信息,字符串形式
        :param agent_list: testagent id list
        :return:
        """
        try:
            Logging.getLog().debug("Redis:add_new_task_to_redis(%s)" % str(task_id))
            now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
            p = self.r.pipeline()
            p.rpush("curr_task_list", task_id)

            p.delete("task_record_id_set:%s" % str(task_id))
            for id in run_record_id_list:
                p.sadd("task_record_id_set:%s" % str(task_id), id)

            p.hset("task_info:%s" % str(task_id), "collection_id", collection_id)
            p.hset("task_info:%s" % str(task_id), "collection_name", collection_name)
            p.hset("task_info:%s" % str(task_id), "system_id", system_id)
            p.hset("task_info:%s" % str(task_id), "cases_num", cases_num)
            p.hset("task_info:%s" % str(task_id), "timed_task_flag", timed_task_flag)
            p.hset("task_info:%s" % str(task_id), "run_start_time", now)
            p.hset("task_info:%s" % str(task_id), "run_end_time", "")
            p.hset("task_info:%s" % str(task_id), "run_case_num", 0)
            p.hset("task_info:%s" % str(task_id), "run_case_num_success", 0)
            p.hset("task_info:%s" % str(task_id), "run_case_num_fail", 0)
            p.hset("task_info:%s" % str(task_id), "warning_info", warning_info)
            p.hset("task_info:%s" % str(task_id), "cancel_flag", 0)

            # 新增任务的初始化状态
            p.hset("task_init_state:%s" % str(task_id), "AGNET_ID", "")
            p.hset("task_init_state:%s" % str(task_id), "INIT_STATE", "STATE_UNINIT")
            p.hset("task_init_state:%s" % str(task_id), "INIT_MSG", "")
            p.hset("task_init_state:%s" % str(task_id), "SYNC_FLAG", "FALSE")  # 是否同步到数据库了
            p.hset("task_init_state:%s" % str(task_id), "SYSTEM_ID", system_id)  # system_id fixme

            p.rpush("agent_curr_task", task_id)

            p.hset("task_agent_table", task_id, agent_list)

            p.execute()
            return 0, "OK"
        except redis.RedisError:
            exc_info = cF.getExceptionInfo()
            Logging.getLog().error(exc_info)
            return -1, exc_info
Esempio n. 15
0
 def remove_account_group_dict(self, task_id_list):
     try:
         p = self.r.pipeline()
         for id in task_id_list:
             p.hdel("account_group_dict", id)
         p.execute()
         return 0, "OK"
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 16
0
 def report_case_result(self, task_id, case_result_dict):
     try:
         p = self.r.pipeline()
         for id in case_result_dict.keys():
             p.hset("case_result:%s" % str(task_id), id, case_result_dict[id])
             p.srem("task_record_id_set:%s" % str(task_id), id)
         p.execute()
         return 0, "OK"
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 17
0
 def remove_case_result(self, task_id, run_record_id_list):
     try:
         p = self.r.pipeline()
         for id in run_record_id_list:
             # p.hset("case_result:%d" % task_id, id, case_result_dict[id])
             p.hdel("case_result:%s" % str(task_id), id)
         p.execute()
         return 0, "OK"
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 18
0
def truncateHTKSempTable():
    Logging.getLog().info(u"准备清空临时表……")
    doc = ET.parse("DB2_column_report_scan.xml")
    table_root = doc.getroot()
    conn = DB2SkDB()
    crs = conn.cursor()
    try:
        sql = "select NAME from sysibm.systables where type='T' AND CREATOR='KS' AND NAME='TMP_AUTOTEST_TRIGGER'"
        crs.execute(sql)
        print sql
        ds = crs.fetchall()
        conn.commit()

        if len(ds) != 0:
            sql = "truncate table KS.TMP_AUTOTEST_TRIGGER IMMEDIATE;"
            crs.execute(sql)
            conn.commit()
            # print sql
        # print sql
        for schemaElem in table_root:
            for i, tableElem in enumerate(schemaElem):
                if tableElem.attrib["disableflag"] == "1":
                    continue
                schema = schemaElem.attrib["schemaname"]
                tablename = tableElem.attrib["tablename"]
                sql_i = "select COUNT(*) from sysibm.systables where CREATOR='KS' AND name='AUTO_I_%s';" % (tablename)
                # print sql_i
                sql_d = "select COUNT(*) from sysibm.systables where CREATOR='KS' AND name='AUTO_D_%s';" % (tablename)
                # print sql_d
                r = crs.execute(sql_i)
                ds_i = crs.fetchall()
                r = crs.execute(sql_d)
                ds_d = crs.fetchall()
                conn.commit()
                if ds_i[0][0] != 0:
                    sql = "truncate table %s.AUTO_I_%s IMMEDIATE " % (schema, tablename)
                    # print sql
                    crs.execute(sql)
                if ds_d[0][0] != 0:
                    conn.commit()
                    sql = "truncate table %s.AUTO_D_%s IMMEDIATE" % (schema, tablename)
                    # print sql
                    crs.execute(sql)
                conn.commit()
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().critical(exc_info)
        err = u"连接数据库出现异常,%s" % exc_info
        crs.close()
        conn.rollback()
        conn.close()
        return -1, err
Esempio n. 19
0
def read_dbf_file(path):
    try:
        Logging.getLog().info(u"path:%s" % (str(path)))
        f = open(path, 'rb')
        db = list(dbfreader(f))
        num = len(db)
        if num >= 2:
            num = num - 1
        print num
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().error(u"异常发生,请检查日志文件,提示信息为:%s" % (exc_info))
        return -1, u"异常发生,请检查日志文件,提示信息为:%s" % (exc_info)
Esempio n. 20
0
def generateDB2ColumnXml():
    """
    产生数据库字段配置表
    """
    Logging.getLog().info(u"扫描DB2数据库开始")
    root = etree.Element("comparesetting")
    try:
        conn = DB2SkDB()
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        err = u"连接数据库出现异常,%s" % exc_info
        Logging.getLog().critical(err)
        return -1, err
Esempio n. 21
0
 def read_task_info(self, task_id):
     try:
         p = self.r.pipeline()
         p.smembers("task_record_id_set:%s" % str(task_id))
         p.hgetall("task_init_state:%s" % str(task_id))
         p.hgetall("case_result:%s" % str(task_id))
         p.hgetall("task_info:%s" % str(task_id))
         task_info_list = p.execute()
         # curr_task_list = self.r.lrange("curr_task_list", 0, -1)
         return 0, task_info_list
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 22
0
 def call_server_rpc(self, func_body_dict):
     try:
         self.corr_id = str(uuid.uuid4())
         self.result_dict[self.corr_id] = None
     
         self.rpc_channel.basic_publish(exchange='',
                                        routing_key='server_rpc_queue',
                                        properties=pika.BasicProperties(
                                            reply_to=self.callback_queue,
                                            correlation_id=self.corr_id,
                                        ),
                                        body=json.dumps(func_body_dict, ensure_ascii=False))
         try:
             while self.result_dict[self.corr_id] is None and gl.is_exit_all_thread == False:
                 self._rpc_connection.process_data_events()
             
             if gl.is_exit_all_thread == True:
                 Logging.getLog().debug("exit call_server_rpc")
                 return -1, "exit call_server_rpc"
             else:
                 Logging.getLog().debug("call %s return %s" %(func_body_dict["func"], self.result_dict[self.corr_id]))
                 return 0, self.result_dict[self.corr_id]
         except KeyboardInterrupt:
             Logging.getLog().debug("get KeyboardInterrupt")
             return -1, "KeyboardInterrupt"
     except Exception, ex:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, ""
Esempio n. 23
0
def process_disable_column(db_id, schema, tablename, result_dict):
    '''
    将传递进来的表数据,根据disableflag的配置情况从中剔除,不参与比较
    :param db_id:
    :param schema:
    :param tablename:
    :param result_dict:
    :param model:
    :return:
    '''
    try:
        table_column_disable_info = scanOracleDB.getTableColumnInfo()
        # if gl.g_table_column_disable_info == OrderedDict():
        #     scanOracleDB.getTableColumnInfo()

        remove_index_list = []
        field_list = result_dict["field"]
        if table_column_disable_info[db_id][schema][tablename]["disableflag"] == 1:  # 如果该表被禁掉
            return 0, {}
        for idx, column in enumerate(table_column_disable_info[db_id][schema][tablename]["column_list"].keys()):
            if table_column_disable_info[db_id][schema][tablename]["column_list"][column]["disableflag"] == 1:
                remove_index_list.append(idx)

        # 删除的时候,索引值从大到小删除。

        # 从大到小排序
        remove_index_list.sort(reverse=True)
        for idx in remove_index_list:
            result_dict["field"].pop(idx)
            if result_dict.has_key('add'):
                for row in result_dict["add"]:
                    row.pop(idx)
            if result_dict.has_key('del'):
                for row in result_dict["del"]:
                    row.pop(idx)
            if result_dict.has_key('update'):
                for row in result_dict["update"]["old"]:
                    row.pop(idx)
                for row in result_dict["update"]["new"]:
                    row.pop(idx)
                for row in result_dict["update"]["diff_flag"]:
                    row.pop(idx)
        return 0, result_dict


    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().error(exc_info)
        return -1, exc_info
Esempio n. 24
0
def createHTKSTrigger():
    Logging.getLog().info(u"准备在创建触发器……")
    doc = ET.parse("DB2_column_report_scan.xml")
    table_root = doc.getroot()
    conn = DB2SkDB()
    crs = conn.cursor()
    try:
        sql = "select trigname from syscat.triggers WHERE tabschema='KS' and trigname LIKE 'KS_%_%_TRIGGER'"
        crs.execute(sql)
        ds = crs.fetchall()
        for rec in ds:
            sql = "drop trigger KS.%s" % (rec[0])
            print sql
            try:
                crs.execute(sql)
            except:
                print "%s except and continue" % sql
            conn.commit()
            # 创建新触发器
            # for schemaElem in table_root:
            #    for i,tableElem in enumerate(schemaElem):
            #        if tableElem.attrib["disableflag"] == "1":
            #            continue
            #        schema = schemaElem.attrib["schemaname"]
            #        tablename = tableElem.attrib["tablename"]
            #        #if tableElem.attrib["have_exclude_column"] == "1":
            #        column_list = []
            #        for columnElem in tableElem:
            #            if columnElem.attrib["is_exclude"] == "0":
            #                column_list.append(columnElem.attrib["column_name"])
            #        sql_d = "CREATE TRIGGER %s.%s_%d_d_trigger AFTER DELETE ON %s.%s REFERENCING OLD AS O FOR EACH ROW MODE DB2SQL begin atomic insert into KS.TMP_AUTOTEST_TRIGGER(username,tablename,operation) values('%s','%s',3);insert into %s.AUTO_D_%s (%s) values (%s); end"%(schema,schema,i,schema,tablename,schema,tablename,schema,tablename,",".join(column_list),"O."+",O.".join(column_list))
            #        sql_u = "CREATE TRIGGER %s.%s_%d_u_trigger AFTER UPDATE ON %s.%s REFERENCING OLD AS O FOR EACH ROW MODE DB2SQL begin atomic insert into KS.TMP_AUTOTEST_TRIGGER(username,tablename,operation) values('%s','%s',2);insert into %s.AUTO_I_%s (%s) values (%s); end"%(schema,schema,i,schema,tablename,schema,tablename,schema,tablename,",".join(column_list),"O."+",O.".join(column_list))
            #        sql_i = "CREATE TRIGGER %s.%s_%d_i_trigger AFTER INSERT ON %s.%s REFERENCING NEW AS O FOR EACH ROW MODE DB2SQL begin atomic insert into KS.TMP_AUTOTEST_TRIGGER(username,tablename,operation) values('%s','%s',1);insert into %s.AUTO_I_%s (%s) values (%s); end"%(schema,schema,i,schema,tablename,schema,tablename,schema,tablename,",".join(column_list),"O."+",O.".join(column_list))
            #        #print sql_d
            #        #print sql_u
            #        #print sql_i
            #        #print '==========================================='
            #        crs.execute(sql_d)
            #        crs.execute(sql_u)
            #        crs.execute(sql_i)
            #        conn.commit()
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        err = u"出现异常,提示%s" % (exc_info)
        Logging.getLog().critical(err)
        crs.close()
        conn.rollback()
        conn.close()
        return -1, err
Esempio n. 25
0
def ChangStkPrice(server=0):
    '''
    初始化所有用到股票代码的价格
    '''
    price_dict = {"maxrisevalue": "17.8300", "maxdownvalue": "14.5900", "stopflag": "F", "closeprice": "16.2100",
                  "openprice": "16.2200", "lastprice": "16.2500", "highprice": "16.3200", "lowprice": "16.1300",
                  "lastcloseprice": "16.2500"}
    stkcode_list = []
    Logging.getLog().info(u"准备在集中交易 server %s 初始化股票价格……" % str(server))
    ret, conn = cF.ConnectToRunDB(server)
    cursor = conn.cursor()
    servertype = gl.g_connectSqlServerSetting[server]["servertype"]
    try:
        sql = "select * from tbl_cases where cmdstring like '%stkcode:%' and cmdstring like '%price:%'"
        ds = cF.executeCaseSQL(sql)
        if len(ds) > 0:
            for i, line in enumerate(ds):
                stkcode = line["cmdstring"].split('stkcode:')[1].split(',')[0]
                if stkcode not in stkcode_list:
                    stkcode_list.append(stkcode)

        for item in stkcode_list:
            sql = "select * from run..stktrd where  stkcode='%s'" % (stkcode)
            cursor.execute(sql)
            dss = cursor.fetchall()
            if len(dss) > 0:
                sql = "update run..stktrd set maxrisevalue='%s',maxdownvalue='%s',stopflag='%s',fixprice='%s' where stkcode='%s'" % (
                    price_dict["maxrisevalue"], price_dict["maxdownvalue"], price_dict["stopflag"],
                    price_dict["openprice"],
                    item)
                cursor.execute(sql)

            sql1 = "select * from run..stkprice where stkcode='%s'" % (item)
            cursor.execute(sql1)
            dsp = cursor.fetchall()
            if len(dsp) > 0:
                sql1 = "update run..stkprice set closeprice='%s',openprice='%s',lastprice='%s',highprice='%s',lowprice='%s',lastcloseprice='%s' where stkcode='%s'" % (
                    price_dict["closeprice"], price_dict["openprice"], price_dict["lastprice"], price_dict["highprice"],
                    price_dict["lowprice"], price_dict["lastcloseprice"], item)
                cursor.execute(sql1)

    except Exception, ex:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().info(u"在核心%s初始化股票代码价格出现异常,提示信息 stkcode= %s  %s……" % (str(server), stkcode, exc_info))
        cursor.close()
        conn.rollback()
        conn.close()
        gl.threadQueue.put((-1, u"exc_info", "ChangStkPrice", server))  # 返回结果放入队列,供线程结束后读取运行结果
        return -1, exc_info
Esempio n. 26
0
 def del_task(self, task_id):
     try:
         p = self.r.pipeline()
         self.lrem_item(p, "curr_task_list", task_id)
         p.delete("task_record_id_set:%s" % str(task_id))
         p.delete("task_init_state:%s" % str(task_id))
         p.delete("task_info:%s" % str(task_id))
         self.lrem_item(p, "agent_curr_task", task_id)
         p.hdel("task_agent_table", task_id)
         p.execute()
         return 0, "OK"
     except redis.RedisError:
         exc_info = cF.getExceptionInfo()
         Logging.getLog().error(exc_info)
         return -1, exc_info
Esempio n. 27
0
def main():
    signal.signal(signal.SIGINT, processTerm)
    signal.signal(signal.SIGTERM, processTerm)
    Logging.getLog().info(u'''
    时溪自动化测试平台-Test Agent v2.0 2018.08.22
    (上海时溪信息技术有限公司)
    ''')
    config_name = 'TestAgent.ini'
    # cF.readConfigFile()
    
    # determine if application is a script file or frozen exe
    if getattr(sys, 'frozen', False):
        application_path = os.path.dirname(sys.executable)
    elif __file__:
        application_path = os.path.dirname(__file__)
    
    config_path = os.path.join(application_path, config_name)
    
    mqclient_setting = json.loads(open(config_path, "r").read())
    
    mqclient = MQClient(mqclient_setting)
    mqclient.setDaemon(True)
    mqclient.start()
    
    ret, ret_info = mqclient.register_client()
    # ret, ret_info = mqclient.register_client()
    # ret, ret_info = mqclient.register_client()
    # ret, ret_info = mqclient.register_client()
    print ret, ret_info
    # mqclient.start_appium_server()
    thread = threading.current_thread()
    print "curr thread is %s" % thread.getName()
    while gl.is_exit_all_thread == False:
        # mqclient._rpc_connection.process_data_events()
        pass
        # if mqclient.isAlive() == False:
        #     mqclient.rpcserver.server_close()
        #     break;
    if gl.is_exit_all_thread == True:
        new_queue_name = "cmd_queue_%s" % mqclient.get_agent_id()
        
        #退出命令队列,如果命令队列存在的话
        cmd_channel = mqclient._channel_dict.get(new_queue_name,"")
        if cmd_channel != "":
            cmd_channel.stop_consuming()
            mqclient._cmd_thread.join()
            mqclient._task_thread.join()
    Logging.getLog().debug("Exit the Client Safely")
Esempio n. 28
0
def RunScript(execEngine, system_id, funcid, cmdstring, runtaskid, run_record_id, expect_ret):
    """
    运行接口脚本
    :param system_id: 系统ID
    :param funcid:
    :param cmdstring:
    :param runtaskid:
    :param run_record:
    :return:
        一个元组(ret,msg):
        ret : 0 表示 成功,-1 表示 失败
        msg : 对应信息
        log_info : 日志信息
        dataset_list: 中间件的返回值列表,用于后续动作的一个参数
        return_json_string: 中间件返回值的json字符串,返回给TestAgentServer,并写入数据库
        data_change_info_json_string:数据库变动的json字符串,返回给TestAgentServer,并写入数据库
    """
    succ_flag = False
    msg = ""
    log_info = ""
    return_json_string = ""
    data_change_info_json_string = ""
    dataset_list = []
    sdk = GetSdk()
    try:
        dataset_dict = {}
        ret, msg = ExecuteOneTestCase(sdk, funcid, cmdstring)
        if ret == 0:
            dataset_dict = sdk.GetReturnResult()
            r, return_json_string , dataset_list= deal_with_dataset_list(dataset_dict)
            if int(expect_ret) != 0:
                succ_flag = False
            else:
                succ_flag = True
            if r < 0:
                succ_flag = False
        else:
            succ_flag = False

        if succ_flag == True:
            return 0, msg, log_info, dataset_list, return_json_string, data_change_info_json_string
        else:
            return -1, msg, log_info, dataset_list, return_json_string, data_change_info_json_string
    except BaseException, ex:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().critical(u"异常发生,请检查日志文件,提示信息为:%s" % (exc_info))
        return -1, u"异常发生,请检查日志文件,提示信息为:%s" % (
            exc_info), log_info, [], return_json_string, data_change_info_json_string
Esempio n. 29
0
def mycopyfile(flag):
    try:
        srcfile = r'D:\\ABOSS2\\SSKH\\MN\\qtymtzl.dbf'
        dstfile = r'D:\YMAT_MY_COPY\qtymtzl_%s_%s.dbf' % (time.strftime('%Y%m%d%H%M%S'), flag)
        if not os.path.isfile(srcfile):
            print "%s not exist!" % (srcfile)
        else:
            fpath, fname = os.path.split(dstfile)  # 分离文件名和路径
            if not os.path.exists(fpath):
                os.makedirs(fpath)  # 创建路径
            shutil.copyfile(srcfile, dstfile)  # 复制文件
            print "copy %s -> %s" % (srcfile, dstfile)
    except:
        exc_info = cF.getExceptionInfo()
        Logging.getLog().info(exc_info)
        return -1, exc_info
Esempio n. 30
0
    def cancel_task(self, task_id):
        try:
            Logging.getLog().debug("Redis:cancel_task %s" % str(task_id))
            key = "task_record_id_set:%s" % str(task_id)
            num = self.r.scard(key)

            p = self.r.pipeline()
            p.hset("task_info:%s" % str(task_id), "cancel_flag", 1)
            for i in xrange(num):
                p.spop(key)

            p.execute()
            return 0, "OK"
        except redis.RedisError:
            exc_info = cF.getExceptionInfo()
            Logging.getLog().error(exc_info)
            return -1, exc_info