def get_place_rabbitmq_channel(): global mylogger conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "rabbitmq") if "placemq_server_addr" in conf_dict: _mq_host = conf_dict["placemq_server_addr"] else: _mq_host = "localhost" if "placemq_server_port" in conf_dict: _mq_port = int(conf_dict["placemq_server_port"]) else: _mq_port = 5672 if "placemq_user_name" in conf_dict: _mq_user_name = conf_dict["placemq_user_name"] else: _mq_user_name = "guest" if "placemq_passwd" in conf_dict: _mq_passwd = conf_dict["placemq_passwd"] else: _mq_passwd = "guest" while True: try: credentials = pika.PlainCredentials(_mq_user_name, _mq_passwd) conn_params = pika.ConnectionParameters(host=_mq_host, virtual_host='/', credentials=credentials) conn_broker = pika.BlockingConnection(conn_params) break except Exception, e: mylogger.info(str(e)) time.sleep(20)
def get_serverID(): _dict = wtclib.get_user_config_ret_dict("../conf/id.conf", "system") if not "serverid" in _dict: _dict.update({"serverid": "1710890123"}) wtclib.set_user_config_from_dict("../conf/id.conf", "system", _dict) return _dict["serverid"]
def get_serverID(): _dict = wtclib.get_user_config_ret_dict("../conf/id.conf", "system") if not "serverid" in _dict: serverID = make_serverID() _dict.update({"serverid": serverID}) wtclib.set_user_config_from_dict("../conf/id.conf", "system", _dict) else: serverID = _dict["serverid"] return serverID
def get_plate_rabbitmq_channel(): global mylogger conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "rabbitmq") if "platemq_server_addr" in conf_dict: _Plate_host = conf_dict["platemq_server_addr"] else: _Plate_host = wtclib.get_ip_addr1("eth0") if "platemq_server_port" in conf_dict: _Plate_port = int(conf_dict["platemq_server_port"]) else: _Plate_port = 5672 if "platemq_exchange" in conf_dict: Rabbitmq_Plate_exchange = conf_dict["platemq_exchange"] else: Rabbitmq_Plate_exchange = "plate" if "platemq_exchange_type" in conf_dict: _Plate_exchange_type = conf_dict["platemq_exchange_type"] else: _Plate_exchange_type = "direct" if "platemq_router_key" in conf_dict: Rabbitmq_Plate_router_key = conf_dict["platemq_router_key"] else: Rabbitmq_Plate_router_key = "plate queue" if "platemq_user_name" in conf_dict: _Plate_user_name = conf_dict["platemq_user_name"] else: _Plate_user_name = "wutao" if "platemq_passwd" in conf_dict: _Plate_passwd = conf_dict["platemq_passwd"] else: _Plate_passwd = "12345678" while True: try: credentials = pika.PlainCredentials("guest", "guest") conn_params = pika.ConnectionParameters(host="localhost", virtual_host="/", credentials=credentials, heartbeat=60, connection_attempts=5) conn_broker = pika.BlockingConnection(conn_params) break except Exception, e: mylogger.info(str(e)) time.sleep(20)
def get_rabbitmq_channel(): global mylogger conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "rabbitmq") if "aioutmq_server_addr" in conf_dict: _mq_host = conf_dict["aioutmq_server_addr"] else: _mq_host = wtclib.get_ip_addr1("eth0") if "aioutmq_server_port" in conf_dict: _mq_port = int(conf_dict["aioutmq_server_port"]) else: _mq_port = 5672 if "aioutmq_exchange" in conf_dict: _mq_exchange = conf_dict["aioutmq_exchange"] else: _mq_exchange = "AiOut.tr" if "aioutmq_user_name" in conf_dict: _mq_user_name = conf_dict["aioutmq_user_name"] else: _mq_user_name = "user1" if "aioutmq_passwd" in conf_dict: _mq_passwd = conf_dict["aioutmq_passwd"] else: _mq_passwd = "9876543" if "aioutmq_vhost" in conf_dict: _mq_vhost = conf_dict["aioutmq_vhost"] else: _mq_vhost = "OutTrig" while True: try: credentials = pika.PlainCredentials(_mq_user_name, _mq_passwd) conn_params = pika.ConnectionParameters(host=_mq_host, virtual_host=_mq_vhost, credentials=credentials) conn_broker = pika.BlockingConnection(conn_params) break except Exception, e: mylogger.info(str(e)) time.sleep(20)
def get_plateOUT_rabbitmq_channel(): global mylogger conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "rabbitmq") if "reoutmq_server_addr" in conf_dict: _mq_host = conf_dict["reoutmq_server_addr"] else: _mq_host = "localhost" if "reoutmq_server_port" in conf_dict: _mq_port = int(conf_dict["reoutmq_server_port"]) else: _mq_port = 5672 if "reoutmq_user_name" in conf_dict: _mq_user_name = conf_dict["reoutmq_user_name"] else: _mq_user_name = "cpf" if "reoutmq_passwd" in conf_dict: _mq_passwd = conf_dict["reoutmq_passwd"] else: _mq_passwd = "cpf" if "aioutmq_vhost" in conf_dict: _mq_vhost = conf_dict["reoutmq_vhost"] else: _mq_vhost = "OutTrig" while True: try: credentials = pika.PlainCredentials(_mq_user_name, _mq_passwd) conn_params = pika.ConnectionParameters(host=_mq_host, virtual_host=_mq_vhost, credentials=credentials, heartbeat=60, connection_attempts=5) conn_broker = pika.BlockingConnection(conn_params) break except Exception, e: mylogger.info(str(e)) time.sleep(20)
time.sleep(20) return _cur if __name__ == '__main__': if not os.path.isdir("../log/airet"): try: os.mkdir("../log/airet") except Exception, e: print str(e) + " in line: " + str(sys._getframe().f_lineno) os._exit() mylogger = wtclib.create_logging("../log/airet/yuvfilter.log") mylogger.info("start running") cur = get_a_sql_cur_forever(mylogger) conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "plate") _haveCar_delay = 30 if "havecar_delay" in conf_dict: _haveCar_delay = int(conf_dict["havecar_delay"]) if _haveCar_delay < 5 or _haveCar_delay > 600: _haveCar_delay = 30 channel = get_rabbitmq_channel() # msg = sys.argv[1] msg = "hello" + str(time.localtime()) msg_props = pika.BasicProperties() msg_props.content_type = "text/plain" _pid = os.getpid() #sqlite3_cur, sqlite3_conn = wtclib.get_a_sqlite3_cur_forever(mylogger, "/tmp/softdog.db")
try: os.mkdir("../log/airet") except Exception, e: print str(e) + " in line: " + str(sys._getframe().f_lineno) os._exit() mylogger = wtclib.create_logging("../log/airet/ai2filter.log") mylogger.info("start running") cur = get_a_sql_cur_forever(mylogger) ServerID = wtclib.get_serverID() try: time.sleep(random.random()) cur.execute( "insert into WatchdogTable(pid, runCMD,watchSeconds,renewTimet, ServerID)values(%d, " "'python %s &', 300, %d,'%s')" % (os.getpid(), __file__, time.time(), ServerID)) _dic1 = wtclib.get_user_config_ret_dict("aisoftversion.ini", "version") if "ai2filter" in _dic1: _version = _dic1["ai2filter"] else: stat = os.stat(__file__) _version = datetime.date.fromtimestamp(stat.st_mtime).isoformat() cur.execute( "insert into AiSoftwareVersion(SoftwareName, version)values('ai2filter','%s')" "ON DUPLICATE KEY UPDATE version='%s'" % (_version, _version)) except Exception, e: mylogger.error(str(e) + time.asctime()) os._exit() msg_props = pika.BasicProperties() msg_props.content_type = "text/plain"
try: mylogger.debug("basic_publish:"+msg) channelOut.basic_publish(body=msg, exchange="ReOut.filter", properties=msg_props,routing_key="hola") except Exception, e: channel.basic_cancel(consumer_tag="hello-consumer2") channel.stop_consuming() mylogger.error("channelOut Error "+str(e)) except: mylogger.error("end") pass return if __name__ == '__main__': conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "rabbitmq") if "reoutmq_server_addr" in conf_dict: _mq_host = conf_dict["reoutmq_server_addr"] else: _mq_host = wtclib.get_ip_addr1("eth0") if "reoutmq_server_port" in conf_dict: _mq_port = int(conf_dict["reoutmq_server_port"]) else: _mq_port = 5672 if "reoutmq_exchange" in conf_dict: _mq_exchange = conf_dict["reoutmq_exchange"] else: _mq_exchange = "ReOut.tr" if "reoutmq_user_name" in conf_dict: _mq_user_name = conf_dict["reoutmq_user_name"]
(cur, err) = wtclib.get_a_sql_cur("../conf/conf.conf") if None != cur: break else: mylog.info(err) time.sleep(20) renew_config_info_sql(cur, 0) _ConfDelay = 2 _pid = os.getpid() _timeSecInt = int(time.time()) try: ServerID = wtclib.get_serverID() cur.execute("insert into WatchdogTable(pid, runCMD,watchSeconds,renewTimet,ServerID)values(%d, " "'python %s &', 300, %d,'%s')" % (_pid, __file__, _timeSecInt,ServerID)) _dic1 = wtclib.get_user_config_ret_dict("aisoftversion.ini", "version") if "configfiles" in _dic1: _version = _dic1["configfiles"] else: stat = os.stat(__file__) _version = datetime.date.fromtimestamp(stat.st_mtime).isoformat() cur.execute("insert into AiSoftwareVersion(SoftwareName, version)values('configfiles','%s')" "ON DUPLICATE KEY UPDATE version='%s'" % (_version, _version)) except Exception, e: mylog.error(str(e) + time.asctime()) _min10_delay_cnt = 2 socket.setdefaulttimeout(3) check_ucmq_MQs(userjpgMQ_status_url, userjpgMQ_reset_url, 1000) check_ucmq_MQs(downloadMQ_status_url, downloadMQ_reset_url, 1000)
mylogger.info(conn_err) time.sleep(20) return _cur, conn_err if __name__ == '__main__': if not os.path.isdir("../log/rmfilelog"): try: os.mkdir("../log/rmfilelog") except Exception, e: print str(e) + " in line: " + str(sys._getframe().f_lineno) os._exit() mylogger = wtclib.create_logging("../log/rmfilelog/rmfile.log") mylogger.info("start running") conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "file_save") if "root_dir" in conf_dict: root_dir = conf_dict["root_dir"] else: #s = os.getcwd() #root_dir = s[:s[0:s.rfind('/')].rfind('/')] #del s root_dir = "../.." if "fullsize_pic_save_days" in conf_dict and conf_dict[ "fullsize_pic_save_days"].isdigit(): fullsize_days = int(conf_dict["fullsize_pic_save_days"]) else: fullsize_days = 30 if "ai_littlesize_pic_save_days" in conf_dict and conf_dict[ "ai_littlesize_pic_save_days"].isdigit(): aisize_days = int(conf_dict["ai_littlesize_pic_save_days"])
def python_cmd(cmd): #os.system(cmd) while True: str1 = "@%d"%(os.getpid()) print cmd + str1 os.system(cmd) #os.system("pause") time.sleep(10) def python_cmd_once(cmd): os.system(cmd) if __name__ == '__main__': id1 = wtclib.get_serverID() ucmq_dict = wtclib.get_user_config_ret_dict("../ucmq/conf/ucmq.ini", "server") conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "ucmq") eth_addr = wtclib.get_ip_addr1("eth0") if "server_addr" in conf_dict and eth_addr != conf_dict["server_addr"]: #when set the ucmq server,ucmq is running in other pc #wtclib.set_user_config_from_dict("../ucmq/conf/ucmq.ini", "server", {"wtc":eth_addr}) #path1 = os.getcwd() #path2 = path1[0:path1.rfind('/')] #cmd1 = path2+"/ucmq/bin/ucmq -c "+path2+"/conf/ucmq.ini -d" print "ucmq is running in %s"%conf_dict["server_addr"] else: if eth_addr != ucmq_dict["http_listen_addr"]: wtclib.set_user_config_from_dict("../ucmq/conf/ucmq.ini", "server", {"http_listen_addr": eth_addr}) cmd2 = "../ucmq/bin/ucmq -c ../ucmq/conf/ucmq.ini &" thread.start_new_thread(python_cmd_once, (cmd2,)) time.sleep(0.5)
#mylogger.info(Aimq) #print Aimq msg_props = pika.BasicProperties() msg_props.content_type = "text/plain" socket.setdefaulttimeout(10) j = 2000 cur = get_a_sql_cur_forever(mylogger) if None == cur: mylogger.error("config fail with db") os._exit() #Load_camera_table2Mem(cur) #print time.time() _dic1 = wtclib.get_user_config_ret_dict("../conf/conf.conf", "file_save") if "backup_ai_jpg" in _dic1: Backup_ai_jpg = _dic1["backup_ai_jpg"] else: Backup_ai_jpg = '0' if "backup_re_jpg" in _dic1: Backup_re_jpg = _dic1["backup_re_jpg"] else: Backup_re_jpg = '0' del _dic1 threads = [] thread_idles = THREAD_NUM clear_tmp_waiting_files(1).start() mono_dict_process(2).start() gThread_using_flag = []
def run(self): global msg_props, REOUT_CH, Backup_re_jpg #NEW_daybook_create = 1 self.__logger.info("result start") time.sleep(6) conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "db") if "ai_daybook_en" in conf_dict: AI_daybook_en = int(conf_dict["ai_daybook_en"]) else: AI_daybook_en = 0 del conf_dict if 0 != AI_daybook_en: log_cur = get_a_sql_cur_forever(self.__logger, 'alglog') result_cur = get_a_sql_cur_forever(self.__logger) while True: msg = result_queue.get(block=True) try: _timeSec = int(time.time()) try: _O_cam_id, _O_cmos_id, _O_which_slot, _O_pic_full_name = struct.unpack( "32s2b128s", msg[:162]) _cam_id = str(_O_cam_id.rstrip('\0')) del _O_cam_id, _O_cmos_id has_result, plate, plate_type, aveBrightnessCarplate, confidence = struct.unpack( "b24s8s2B", msg[162:197]) """ has_result1, plate1, plate_type1, aveBrightnessCarplate1, confidence1 = struct.unpack("b24s8s2B", msg1[0][197:232]) has_result2, plate2, plate_type2, aveBrightnessCarplate2, confidence2 = struct.unpack("b24s8s2B", msg1[0][232:267]) """ _O_plate_stable, _O_staisitc_plate = struct.unpack( "i24s", msg[268:296]) _O_use_by_statistic_plate = struct.unpack( "24s24s24s24s24s24s24s24s", msg[296:488]) _O_ai_filename, = struct.unpack("128s", msg[488:616]) _ai_filename = str(_O_ai_filename.rstrip('\0')) _plate = str(plate.rstrip('\0')) _plate_type = str(plate_type.rstrip('\0')) #_plate_type = "blue" print "pic full name " + _O_pic_full_name _pic_name_after = str(_O_pic_full_name).rstrip('\0') _staisitc_plate = str(_O_staisitc_plate).rstrip('\0') del plate, plate_type, _O_pic_full_name, _O_ai_filename del msg, _O_staisitc_plate #_O_which_slot += 1 self.__logger.info( "get %s bay%d VLPR out staisitc:%s, %s" % (_cam_id, _O_which_slot, _staisitc_plate, _plate)) body = json.dumps({"cam_id": _cam_id, "CMOS": 0}) except Exception, e: self.__logger.error(str(e)) continue if 0 != AI_daybook_en: mylogger.debug("AI daybook") localtime1 = time.localtime() ailog_table = "ailog%d%02d%02d" % (localtime1.tm_year, localtime1.tm_mon, localtime1.tm_mday) try: _sql_str = "UPDATE %s SET reyuv%dname='%s',plate%dNumber='%s',plate%dconfidence=%d," \ "plate%dbrightness=%d,plate%dstable=%d,stableplate%dnumber='%s'," \ "plate%dupdateTimet=now() WHERE aijpgname='%s'" \ % (ailog_table, _O_which_slot, _pic_name_after, _O_which_slot, _plate, _O_which_slot, confidence, _O_which_slot, aveBrightnessCarplate, _O_which_slot, _O_plate_stable, _O_which_slot, _staisitc_plate, _O_which_slot, _ai_filename) log_cur.execute(_sql_str) self.__logger.debug(_sql_str) except Exception, e: self.__logger.error(str(e)) self.__logger.error(_sql_str) if 'MySQL server has gone away' in str(e): log_cur = get_a_sql_cur_forever( self.__logger, 'alglog') continue _after_filename1 = _pic_name_after.split('.')[0] _after_filename = _after_filename1.split("/")[-1] _day_file = "%d%02d%02d/%s0/%s.jpg" % ( localtime1.tm_year, localtime1.tm_mon, localtime1.tm_mday, _cam_id, _after_filename) _path_file = os.path.join('../../re/save_orig_jpg', _day_file) if False == has_result: # not result self.__logger.debug("no result") try: _sql_str = "update reouttable set Plate%dupdateTimet=%d,Plate%dNumber=null,Plate%dtype=null where " \ "cameraID='%s'" \ % (_O_which_slot, _timeSec, _O_which_slot, _O_which_slot,_cam_id) result_cur.execute(_sql_str) _comment = "sn:%s; plate:noplr" % _cam_id except Exception, e: self.__logger.error(_sql_str) self.__logger.error(str(e)) if 'MySQL server has gone away' in str(e): result_cur = get_a_sql_cur_forever(self.__logger) continue
try: os.mkdir("../log/airet") except Exception, e: print str(e) + " in line: " + str(sys._getframe().f_lineno) os._exit() mylogger = wtclib.create_logging("../log/airet/ai2lamp.log") mylogger.info("start running") cur = get_a_sql_cur_forever(mylogger) #sqlite3_cur, sqlite3_conn = wtclib.get_a_sqlite3_cur_forever(mylogger, "/tmp/softdog.db") try: ServerID = wtclib.get_serverID() cur.execute( "insert into WatchdogTable(pid, runCMD,watchSeconds,renewTimet,ServerID)values(%d, " "'python %s &', 135, %d,'%s')" % (os.getpid(), __file__, time.time(), ServerID)) _dic1 = wtclib.get_user_config_ret_dict("aisoftversion.ini", "version") if "ai2lamp" in _dic1: _version = _dic1["ai2lamp"] else: stat = os.stat(__file__) _version = datetime.date.fromtimestamp(stat.st_mtime).isoformat() cur.execute( "insert into AiSoftwareVersion(SoftwareName, version)values('ai2Lamp','%s')" "ON DUPLICATE KEY UPDATE version='%s'" % (_version, _version)) except Exception, e: mylogger.error(str(e) + time.asctime()) os._exit() socket.setdefaulttimeout(2) conf_dict = wtclib.get_user_config_ret_dict("../conf/conf.conf", "aiplace") if "lamp_interval" in conf_dict: