当前位置: 首页 > 工具软件 > tootgroup.py > 使用案例 >

common_tools.py

向泽语
2023-12-01
import re;
from log_manager import *;
from error_manager import *;

class common_tools:
    __instance = None;

    def __init__(self):
        pass;

    @staticmethod
    def GetInstance():
        if (None == common_tools.__instance):
            common_tools.__instance = common_tools();
        return common_tools.__instance;

    def IsSiMuIfHasLink(self,p_str_if_name):
        log_manager.GetInstance().CoutLog('begin to exec IsSiMuIfHasLink',Com_common_tools);
        pa_pre_if = re.compile('.*/');
        ma_pre_if = pa_pre_if.search(p_str_if_name);
        if ma_pre_if:
            str_pre_if = ma_pre_if.group();
            str_if_order = p_str_if_name.replace(str_pre_if,'');
            int_if_order = int(str_if_order);
            if (int_if_order <= 6):
                log_manager.GetInstance().CoutLog('common_tools:begin to exec IsSiMuIfHasLink',Com_common_tools);
                return True;
            else:
                log_manager.GetInstance().CoutLog('common_tools:end to exec IsSiMuIfHasLink',Com_common_tools);
                return False;

    def GetIPRelationDic(self,p_dict_ip_relation,p_list_real_ip,p_str_start_ip,p_str_end_ip,p_str_mask):
        log_manager.GetInstance().CoutLog('begin to exec GetIPRelationDic',Com_common_tools);
        t_int_start_num = -1;
        t_int_end_num = -1;
        t_str_ip_pre = '';
        pa_start = re.compile('.*\..*\..*\.');
        ma_start_num = pa_start.search(p_str_start_ip);
        if ma_start_num:
            str_start_num = ma_start_num.group();
            t_str_ip_pre = str_start_num;
            str_start_num = p_str_start_ip.replace(str_start_num,'');
            t_int_start_num = int(str_start_num);
        pa_end = re.compile('.*\..*\..*\.');
        ma_end_num = pa_end.search(p_str_end_ip);
        if ma_end_num:
            str_end_num = ma_end_num.group();
            str_end_num = p_str_end_ip.replace(str_end_num,'');
            t_int_end_num = int(str_end_num);
        if (t_int_start_num != -1 and t_int_end_num != -1):
            num = t_int_end_num - t_int_start_num + 1;
            if (num >= len(p_list_real_ip)):
                int_ip_last = t_int_start_num;
                for elem in p_list_real_ip:
                    str_simu_ip = t_str_ip_pre + str(int_ip_last);
                    int_ip_last = int_ip_last + 1;
                    str_real_ip = elem;
                    p_dict_ip_relation[str_real_ip] = str_simu_ip;
        log_manager.GetInstance().CoutLog('end to exec GetIPRelationDic',Com_common_tools);

    def DecimalToInt(self,Decimal):
        str_num = str(Decimal);
        pa_num = re.compile('\d+');
        ma_num = pa_num.search(str_num);
        if ma_num:
            str_num = ma_num.group();
            int_num = int(str_num);
            return int_num;

    def GetDevIDAndIfIndex(self,p_str_param,list_traffic_dev):
        log_manager.GetInstance().CoutLog(p_str_param,Com_common_tools);
        list_param = re.split(';',p_str_param);
        #if (0 == len(list_param)):
            #list_param.append(p_str_param);
        del list_param[0];
        for elem in list_param:
            int_dev_id = '';
            pa_dev_id = re.compile('.*?,');
            ma_dev_id = pa_dev_id.search(elem);
            if ma_dev_id:
                int_dev_id = ma_dev_id.group();
                int_dev_id = int_dev_id.replace(',','');
                param_index = elem.replace(ma_dev_id.group(),'');
                list_param_index = re.split(';',param_index);
                my_traffic_dev = traffic_dev();
                my_traffic_dev.dev_id = int(int_dev_id);
                my_traffic_dev.list_if_index = list_param_index;
                list_traffic_dev.append(my_traffic_dev);
            else:
                int_dev_id = elem;
                my_traffic_dev = traffic_dev();
                my_traffic_dev.dev_id = int(int_dev_id);
                list_traffic_dev.append(my_traffic_dev);
        return oErrorBase.base_succeed;
 类似资料:

相关阅读

相关文章

相关问答