def create_agv_info_xml(self, file_name):
        try:
            a = ET.Element('agv_info')
            b1 = ET.SubElement(a, 'layouts')
            b2 = ET.SubElement(a, 'router')
            b3 = ET.SubElement(a, 'agvs')

            layout = ET.SubElement(
                b1, 'layout', {
                    'dock': '/etc/docks.xml',
                    "id": "1",
                    "path": "/etc/layout.xml",
                    "search_type": "1"
                })
            attribute = ET.SubElement(b2, 'attribute', {
                "detourByDock_enable": "0",
                "detourByDock_timeout": "3000"
            })

            tree1 = ET.ElementTree(a)
            tree1.write(file_name, encoding='utf-8')
        except Exception as e:
            logger.error(
                'create agv_info xml error!原因:{},filename:{},line:{}'.format(
                    e, e.__traceback__.tb_frame.f_globals['__file__'],
                    e.__traceback__.tb_lineno))
Esempio n. 2
0
    def kill_process(self, process_list):
        try:
            #
            for i in process_list:
                # print(i)
                logger.info('Star kill process:{}!'.format(i))
                if i.find('om.exe') > -1:
                    command = r'wmic process where name="{program}" delete'.format(
                        program=i)
                else:
                    command = 'taskkill /f /t /im {program}'.format(program=i)
                temp = os.system(command)
                # if self.is_admin():
                #     print("以管理员权限运行")
                #     temp=os.system(command)
                # else:
                #     if sys.version_info[0] == 3:
                #         print("无管理员权限")
                #         ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, __file__, None, 1)

                logger.info('End kill prcess:{} !'.format(i))
        except Exception as e:
            logger.error(
                'kill all process error!原因:{},filename:{},line:{}'.format(
                    e, e.__traceback__.tb_frame.f_globals['__file__'],
                    e.__traceback__.tb_lineno))
 def copy_layout_to_general_process(self):
     try:
         logger.info('------start copy layout and eg.-----')
         dispath_l = os.path.join(self.dispathpath, 'etc')
         enginepath_l = os.path.join(self.enginepath, 'etc')
         if not os.path.exists(dispath_l):
             os.makedirs(dispath_l)
         if not os.path.exists(enginepath_l):
             os.makedirs(enginepath_l)
         # 清空文件
         self.detele_path(dispath_l)
         self.detele_path(enginepath_l)
         # 复制文件
         dirlist = os.listdir(self.layoutpath)
         for dir in dirlist:
             source = os.path.join(self.layoutpath, dir)
             if (dir == 'docks.xml' or dir == 'layout.xml'):
                 shutil.copy(source, dispath_l)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, dispath_l))
                 shutil.copy(source, enginepath_l)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, enginepath_l))
             else:
                 shutil.copy(source, enginepath_l)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, enginepath_l))
         logger.info('------end copy layout and eg.-----')
     except Exception as e:
         logger.error('copy layout error!原因:{},filename:{},line:{}'.format(
             e, e.__traceback__.tb_frame.f_globals['__file__'],
             e.__traceback__.tb_lineno))
Esempio n. 4
0
    def modify_xml_attribute_value(self, title_list, row_value, agv_node, j):
        try:
            config_title = []
            xmlkeys = list(agv_node[j].attributes.keys())
            for title in title_list:
                rawVal = row_value[title_list.index(title)]
                if isinstance(rawVal, str):
                    value = rawVal
                else:
                    value = float(rawVal)

                if (value == '' or value == None):
                    if (agv_node[j].getAttribute(title)):
                        # agv_node[j].getAttribute(title).parentNode.removeChild(title)
                        agv_node[j].removeAttribute(title)
                else:
                    if (title in [
                            'dock_id', 'id', 'location_type', 'priority',
                            'exit_dock', 'max_tasking_agv_num',
                            'ancestor_node_id', 'distance', 'node_id', 'id',
                            'type', 'port', 'shell_port', 'layout_id',
                            'fts_port', 'simulation', 'jess_port', 'id',
                            'object_type_id', 'fit_location_id', 'error_code',
                            'pallet_type', 'home_node_id', 'current_node_id'
                    ]):
                        value = int(value)
                    agv_node[j].setAttribute(title, str(value))
                    config_title.append(title)
            x = [item for item in xmlkeys if item not in config_title]
            if x:
                for d in x:
                    agv_node[j].removeAttribute(d)
        except Exception as e:
            logger.error('modify xml value error!原因:{}'.format(e))
Esempio n. 5
0
 def copy_layout_to_i_process(self):
     try:
         logger.info('------start copy layout and eg.-----')
         dispath_etc = os.path.join(self.dispathpath, 'etc')
         enginepath_etc = os.path.join(self.enginepath, 'etc')
         #清空文件
         self.detele_path(dispath_etc)
         self.detele_path(enginepath_etc)
         etc_file_name = ['dock.xml', 'layout.xml']
         for x in etc_file_name:
             self.detele_path_files(self.i_monitorpath, x)
         #复制文件
         dirlist = os.listdir(self.layoutpath)
         for dir in dirlist:
             source = os.path.join(self.layoutpath, dir)
             if (dir == 'docks.xml' or dir == 'layout.xml'):
                 shutil.copy(source, dispath_etc)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, dispath_etc))
                 shutil.copy(source, enginepath_etc)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, enginepath_etc))
                 shutil.copy(source, self.i_monitorpath)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, self.i_monitorpath))
             else:
                 shutil.copy(source, enginepath_etc)
                 logger.info('copy dir:{} to "{}"'.format(
                     source, enginepath_etc))
         logger.info('------end copy layout and eg.-----')
     except Exception as e:
         logger.error('copy layout error!原因:{}'.format(e))
Esempio n. 6
0
    def copy_layout_to_old_general_process(self):
        try:
            logger.info('------start copy layout and eg.-----')
            dispath_l = os.path.join(self.dispathpath, 'etc')
            enginepath_l = os.path.join(self.enginepath, 'etc')
            monitor_l = os.path.join(configs.bsmonitorpath, 'configFiles')
            if not os.path.exists(dispath_l):
                os.makedirs(dispath_l)
            if not os.path.exists(enginepath_l):
                os.makedirs(enginepath_l)
            # 清空文件
            self.detele_path(dispath_l)
            self.detele_path(enginepath_l)
            self.detele_path(monitor_l)

            # 复制文件
            dirlist = os.listdir(self.layoutpath)
            for dir in dirlist:
                source = os.path.join(self.layoutpath, dir)
                shutil.copy(source, enginepath_l)
                logger.info('copy dir:{} to "{}"'.format(source, enginepath_l))
                shutil.copy(source, monitor_l)
                logger.info('copy dir:{} to "{}"'.format(source, monitor_l))

                # if (dir == 'docks.xml' or dir == 'layout.xml'):
                #     shutil.copy(source, enginepath_l)
                #     logger.info('copy dir:{} to "{}"'.format(source, enginepath_l))
                #     shutil.copy(source, monitor_l)
                #     logger.info('copy dir:{} to "{}"'.format(source, monitor_l))
                # else:
                #     shutil.copy(source, enginepath_l)
                #     logger.info('copy dir:{} to "{}"'.format(source, enginepath_l))
            logger.info('------end copy layout and eg.-----')
        except Exception as e:
            logger.error('copy layout error!原因:{}'.format(e))
Esempio n. 7
0
 def copy_layout_to_vehicles(self):
     try:
         if os.path.exists(configs.simpath):
             logger.info('------start copy layout to vehicles-----')
             for i in os.listdir(configs.simpath):
                 if os.path.isdir(i):
                     vehiclespath = os.path.join(configs.simpath, i)
                     mappath = os.path.join(vehiclespath, 'etc\map')
                     if not os.path.exists(mappath):
                         os.makedirs(mappath)
                     # 清空文件
                     self.detele_path(mappath)
                     # 复制文件
                     dirlist = os.listdir(self.layoutpath)
                     for dir in dirlist:
                         source = os.path.join(self.layoutpath, dir)
                         if (dir == 'docks.xml' or dir == 'layout.xml'):
                             shutil.copy(source, mappath)
                             logger.info('copy dir:{} to "{}"'.format(
                                 source, mappath))
             logger.info('------end copy layout to vehicles-----')
         else:
             logger.info('path:{} not exists!'.format(configs.simpath))
     except Exception as e:
         logger.error('copy layout to vehicles error!原因:{}'.format(e))
def api_check_object_task_by_status(status_id):
    try:
        new_check_object_task_url = check_object_task_url + '?status_id={}'.format(
            status_id)
        pr = requests.get(url=new_check_object_task_url, headers=pheaders)
        logger.info(
            f'-----url:{ new_check_object_task_url},返回:{pr.status_code}')
        if (pr.status_code == 200):
            return_dict = eval(
                pr.text.replace('null', 'None').replace('false',
                                                        'False').replace(
                                                            'true', 'True'))
            object_task_num = len(return_dict)
            return object_task_num
        else:
            logger.info(
                f'---------------check_id:{current_check_id}---------Failed :api_check_agv_commands! agv_list:{status_id},status_code:{pr.status_code}'
            )
            return None

    except Exception as e:
        logger.error(
            f'---------------check_id:{current_check_id}---------api_check_agv_commands Error!!results:{e}'
        )
        return None
Esempio n. 9
0
 def check_sheet_and_clear_content(self, excel_name, sheet_name,
                                   title_list):
     try:
         isexists = os.path.exists(excel_name)
         if isexists:
             wb = xlrd.open_workbook(excel_name)
             sheet_names = wb.sheet_names()
             # print(f'sheet_names:{sheet_names},{self.sheet_name in sheet_names}')
             if (sheet_name not in sheet_names):
                 logger.info(
                     f'current file:{excel_name} unexists sheet:{sheet_name},need create sheet!'
                 )
                 self.Add_sheet(excel_name, sheet_name)
                 self.write_title_cell(excel_name, sheet_name, title_list)
             else:
                 sheet = wb.sheet_by_name(self.sheet_name)
                 current_title = sheet.row_values(0)
                 current_rows = sheet.nrows
                 checkinfo = [
                     xx for xx in title_list if xx not in current_title
                 ]
                 if (checkinfo != [] or current_rows > 1):
                     logger.info(
                         f'current file:{excel_name} title error or have content,detele sheet and add new!'
                     )
                     self.remove_sheet(excel_name, sheet_name)
                     self.Add_sheet(excel_name, sheet_name)
                     self.write_title_cell(excel_name, sheet_name,
                                           title_list)
     except Exception as e:
         logger.error(
             'check_sheet_and_clear_content error!原因:{},filename:{},line:{}'
             .format(e, e.__traceback__.tb_frame.f_globals['__file__'],
                     e.__traceback__.tb_lineno))
Esempio n. 10
0
 def write_agv_info_excel(self):
     try:
         get_info = self.get_agv_info_from_docks()
         xfile = openpyxl.load_workbook(self.excel_name)
         sheet = xfile.get_sheet_by_name(self.sheet_name)
         start_id = self.start_agv_id
         shell_port = int(configs.shell_port) + start_id
         port = 10000 + start_id
         fts_port = int(configs.fts_port)
         jess_port = int(configs.jess_port)
         for n in range(self.need_get_agv_num):
             self.title = [
                 'id', 'type', 'ip', 'port', 'shell_port', 'layout_id',
                 'fts_port', 'simulation', 'pos_x', 'pos_y', 'pos_angle',
                 'jess_port', 'mac_addr'
             ]
             current_value = [
                 start_id, self.agv_type_id, '127.0.0.1', port, shell_port,
                 1, fts_port, 1, get_info[n - 1][1], get_info[n - 1][2],
                 get_info[n - 1][3], jess_port, None
             ]
             print(f'第{n+2}行数据:{current_value}')
             for i in range(len(self.title)):
                 sheet.cell(n + 2, i + 1).value = current_value[i]
             start_id = start_id + 1
             port = port + 1
             shell_port = shell_port + 1
         xfile.save(self.excel_name)
     except Exception as e:
         logger.error(
             'write_agv_info_excel error!原因:{},filename:{},line:{}'.format(
                 e, e.__traceback__.tb_frame.f_globals['__file__'],
                 e.__traceback__.tb_lineno))
    def copy_layout_to_vehicles(self):
        try:
            if os.path.exists(configs.simpath):
                logger.info('------start copy layout to vehicles-----')

                for i in os.listdir(configs.simpath):
                    vehiclespath = os.path.join(configs.simpath, i)
                    # print(configs.simpath,vehiclespath,os.path.isdir(vehiclespath))
                    if os.path.isdir(vehiclespath):
                        mappath = os.path.join(vehiclespath, 'etc\map')
                        if not os.path.exists(mappath):
                            os.makedirs(mappath)
                        # 清空文件
                        self.detele_path(mappath)
                        # 复制文件
                        dirlist = os.listdir(self.layoutpath)
                        for dir in dirlist:
                            source = os.path.join(self.layoutpath, dir)
                            if (dir == 'docks.xml' or dir == 'layout.xml'):
                                shutil.copy(source, mappath)
                                logger.info('copy dir:{} to "{}"'.format(
                                    source, mappath))
                logger.info('------end copy layout to vehicles-----')
            else:
                logger.info('path:{} not exists!'.format(configs.simpath))
        except Exception as e:
            logger.error(
                'copy layout to vehicles error!原因:{},filename:{},line:{}'.
                format(e, e.__traceback__.tb_frame.f_globals['__file__'],
                       e.__traceback__.tb_lineno))
Esempio n. 12
0
    def modify_om_db_config(self):
        try:
            isexists = os.path.exists(self.om_dbconfigpath)
            if isexists:
                logger.info('Start modify om db config!')
                with open(self.om_dbconfigpath, "r",
                          encoding='utf-8') as jsonFile:
                    data = json.load(jsonFile)
                tmp = data["DBcon"]

                data["DBcon"]["host"] = self.ip
                data["DBcon"]["port"] = self.port
                data["DBcon"]["database"] = self.dbname
                data["DBcon"]["user"] = self.dbuser
                data["DBcon"]["password"] = self.dbpassword
                # logger.info('rest_api db_config:before:{},after:{}'.format(tmp,data))
                with open(self.om_dbconfigpath, "w") as jsonFile:
                    json.dump(data, jsonFile, ensure_ascii=False)
                logger.info('End modify om db config!')
            else:
                logger.info('not exists path:{}'.format(self.om_dbconfigpath))
        except Exception as e:
            logger.error('Modify om db error!原因:{},filename:{},line:{}'.format(
                e, e.__traceback__.tb_frame.f_globals['__file__'],
                e.__traceback__.tb_lineno))
Esempio n. 13
0
 def get_agv_info_from_docks(self):
     try:
         #打开xml文档
         dom = minidom.parse(self.dockspath)
         #得到文档元素对象
         root = dom.documentElement
         docks = root.getElementsByTagName('dock')
         choice_docks = random.sample(docks, int(self.need_get_agv_num))
         agv_info = []
         for sd in choice_docks:
             #dock点
             docks_id = sd.getElementsByTagName("id")[0].childNodes[0].data
             docks_info = sd.getElementsByTagName("pos")[0]
             #x值、y值、坐标
             x = docks_info.getAttribute("x")
             y = docks_info.getAttribute("y")
             angle = docks_info.getAttribute("angle")
             single_dock_info = (docks_id, x, y, angle)
             # print(docks_id,x,y,angle)
             logger.info(f'get docks info:{docks_id},{x},{y},{angle}')
             agv_info.append(single_dock_info)
         return agv_info
     except Exception as e:
         logger.error(
             'get_agv_info_from_docks error!原因:{},filename:{},line:{}'.
             format(e, e.__traceback__.tb_frame.f_globals['__file__'],
                    e.__traceback__.tb_lineno))
Esempio n. 14
0
 def func_engine(self):
     try:
         logger.info('Start open engine process!')
         results = os.startfile(self.engine_process_path)
         logger.info(
             'End open engine process!,return content:{}'.format(results))
     except Exception as e:
         logger.error('open engine process error!原因:{}'.format(e))
Esempio n. 15
0
 def func_gui_web(self):
     try:
         logger.info('start open gui in  web!')
         command = r'cd /d ' + self.chromepath + ' && start chrome.exe http://127.0.0.1:2000'
         results = os.system(command)
         logger.info(
             'End open gui in  web!return content:{}'.format(results))
     except Exception as e:
         logger.error('open gui in web error!原因:{}'.format(e))
Esempio n. 16
0
 def func_rest_api(self):
     try:
         logger.info('start open rest_api process!')
         command1 = r'cd /d ' + self.rest_api_path + ' && start ' + self.rest_api_process_name
         results = os.system(command1)
         logger.info(
             'End open rest_api process!return content:{}'.format(results))
     except Exception as e:
         logger.error('open rest_api error!原因:{}'.format(e))
Esempio n. 17
0
 def Add_sheet(self, excel_name, sheet_name):
     try:
         wb = openpyxl.load_workbook(excel_name)
         wb.create_sheet(sheet_name, index=0)
         wb.save(excel_name)
     except Exception as e:
         logger.error('Add_sheet error!原因:{},filename:{},line:{}'.format(
             e, e.__traceback__.tb_frame.f_globals['__file__'],
             e.__traceback__.tb_lineno))
Esempio n. 18
0
    def func_monitor(self):
        try:
            logger.info('start open monitor process!')
            command = r'cd /d ' + self.i_monitorpath + ' && start ' + self.i_monitor_process_name
            results = os.system(command)
            logger.info(
                'End open monitor process!return content:{}'.format(results))

        except Exception as e:
            logger.error('open monitor error!原因:{}'.format(e))
Esempio n. 19
0
    def func_guiservice(self):
        try:
            logger.info('start guiservice process!')
            command = r'cd /d ' + configs.guiservice_path + ' && start  ' + configs.guiservice_process_name
            results = os.system(command)
            logger.info('End open guiservice process!return content:{}'.format(
                results))

        except Exception as e:
            logger.error('open guiservice error!原因:{}'.format(e))
Esempio n. 20
0
 def func_om(self):
     try:
         logger.info('Start open om process!')
         # results=os.startfile(self.engine_process_path)
         command = r'cd /d ' + self.ompath + ' && start  ' + configs.om_process_name
         results = os.system(command)
         logger.info(
             'End open om process!,return content:{}'.format(results))
     except Exception as e:
         logger.error('open om process error!原因:{}'.format(e))
Esempio n. 21
0
    def func_nginx(self):
        try:
            logger.info('start ngnix process!')
            command = r'cd /d ' + configs.nginx_path + ' && start ' + configs.nginx_process_name
            results = os.system(command)
            logger.info(
                'End open nginx process!return content:{}'.format(results))

        except Exception as e:
            logger.error('open nginx error!原因:{}'.format(e))
Esempio n. 22
0
 def func_dispath(self):
     try:
         logger.info('Start open dispath process!')
         command = r'cd /d ' + self.dispathpath + ' && start ' + self.i_dispath_process_name
         results = os.system(command)
         # results=os.startfile(self.dispath_process_path)
         logger.info(
             'End open dispath process!,return content:{}'.format(results))
     except Exception as e:
         logger.error('open dispath process error!原因:{}'.format(e))
Esempio n. 23
0
 def func_bsmonitor(self):
     try:
         logger.info('start open monitor')
         command = r'cd /d ' + self.webmonitorpath + ' && start  ' + self.monitor_process_name + ' runserver  0.0.0.0:5006 --noreload'
         results = os.system(command)
         print(command)
         # print('monitor_open_process_path:{}'.format(self.monitor_open_process_path))
         logger.info(
             'End open monitor process!return content:{}'.format(results))
     except Exception as e:
         logger.error('open monitor error!原因:{}'.format(e))
Esempio n. 24
0
 def detele_path_files(self, path, de_file):
     try:
         de_path = os.path.join(path, de_file)
         if os.path.exists(de_path):
             os.remove(de_path)
             logger.info('start detele path :{} files:{}!'.format(
                 path, de_file))
         else:
             logger.info('path :{}not exists!'.format(de_path))
     except Exception as e:
         logger.error('detele path :{} files error!原因:{}'.format(path, e))
Esempio n. 25
0
 def func_rest_api(self):
     try:
         logger.info('start open rest_api process!')
         command1 = r'cd /d ' + self.rest_api_path + ' && start /min  ' + self.rest_api_process_name
         results = os.system(command1)
         logger.info(
             'End open rest_api process!return content:{}'.format(results))
     except Exception as e:
         logger.error(
             'open rest_api error!原因:{},filename:{},line:{}'.format(
                 e, e.__traceback__.tb_frame.f_globals['__file__'],
                 e.__traceback__.tb_lineno))
Esempio n. 26
0
 def func_open_webmonitor_web(self):
     try:
         logger.info('start webmonitor in  web!')
         command = r'cd /d ' + self.chromepath + ' && start chrome.exe http://127.0.0.1:5006'
         results = os.system(command)
         logger.info(
             'End webmonitor in  web!return content:{}'.format(results))
     except Exception as e:
         logger.error(
             'open webmonitor in web error!原因:{},filename:{},line:{}'.
             format(e, e.__traceback__.tb_frame.f_globals['__file__'],
                    e.__traceback__.tb_lineno))
Esempio n. 27
0
 def get_excel_info(self):
     try:
         workbook = xlrd.open_workbook(self.excelpath)
         sheet_names = workbook.sheet_names()
         for i in sheet_names:
             sheet = workbook.sheet_by_name(i)
             num = sheet.nrows - 1
             title_list = sheet.row_values(0)
             logger.info('Excel表{}的标题栏是:{},内容有{}行'.format(
                 i, title_list, num))
     except Exception as e:
         logger.error('get_excel_info error!原因:{}'.format(e))
Esempio n. 28
0
 def delete_induct_log(self):
     try:
         logger.info('start delete induct process log!')
         process_path = [
             self.dispathpath, self.enginepath, self.i_monitorpath
         ]
         for i in process_path:
             logpath = os.path.join(i, 'log')
             self.d.detele_path(logpath)
         logger.info('end delete induct process log!')
     except Exception as e:
         logger.error('delete induct process log error!原因:{}'.format(e))
Esempio n. 29
0
 def remove_sheet(self, excel_name, sheet_name):
     try:
         print(f'remove sheet:{sheet_name}')
         wb = openpyxl.load_workbook(excel_name)
         ws = wb[sheet_name]
         wb.remove(ws)
         wb.save(excel_name)
         print("It is over")
     except Exception as e:
         logger.error('remove_sheet error!原因:{},filename:{},line:{}'.format(
             e, e.__traceback__.tb_frame.f_globals['__file__'],
             e.__traceback__.tb_lineno))
Esempio n. 30
0
 def func_bsmonitor(self):
     try:
         logger.info('start open monitor')
         command = r'cd /d ' + self.webmonitorpath + ' && start  /min ' + self.monitor_process_name + ' runserver  0.0.0.0:5006 --noreload'
         results = os.system(command)
         print(command)
         # print('monitor_open_process_path:{}'.format(self.monitor_open_process_path))
         logger.info(
             'End open monitor process!return content:{}'.format(results))
     except Exception as e:
         logger.error('open monitor error!原因:{},filename:{},line:{}'.format(
             e, e.__traceback__.tb_frame.f_globals['__file__'],
             e.__traceback__.tb_lineno))