14

    def GetRealViewIDBySimuViewID(self,p_int_view_id):
        log_manager.GetInstance().CoutLog('begin to exec GetRealViewIDBySimuViewID view_id = %d' % (p_int_view_id),Com_db_tools);
        iResult = oErrorBase.base_succeed;
        sql = '';
        cou = None;
        '''
        sql = "SELECT [symbol_name] FROM [config_db].[imc_config].[tbl_symbol] where symbol_id = %d"%(p_int_view_id);
        try:
            cou = self.conn.cursor();
            cou.execute(sql);
        except Exception, e:
            log_manager.GetInstance().CoutLog('database error:' + str(e),Com_db_tools);
            log_manager.GetInstance().CoutLog('datebase error:ip = ' + self.__str_db_ip + ' user = ' + self.__str_db_user + ' pw= ' + self.__str_db_pw + 'datebase = config_db',Com_db_tools);
            log_manager.GetInstance().CoutLog('sql = ' + sql,Com_db_tools);
            return oErrorBase.base_failed,-1;
        str_simu_view_name = '';
        for symbol_name in cou.fetchall():
            str_simu_view_name = symbol_name[0];
            break;
        if ('' == str_simu_view_name):
            log_manager.GetInstance().CoutLog('simu view name is empty',Com_db_tools);
            return oErrorBase.base_failed,-1;
        '''
        sql = "SELECT [view_id] FROM [config_db].[imc_config].[tbl_inference_view_correspond] where view_name \
        in (SELECT [symbol_name] FROM [config_db].[imc_config].[tbl_symbol] where symbol_id = %d) " % (p_int_view_id);
        try:
            cou = self.conn.cursor();
            cou.execute(sql);
        except Exception, e:
            log_manager.GetInstance().CoutLog('database error:' + str(e),Com_db_tools);
            log_manager.GetInstance().CoutLog('datebase error:ip = ' + self.__str_db_ip + ' user = ' + self.__str_db_user + ' pw= ' + self.__str_db_pw + 'datebase = config_db',Com_db_tools);
            log_manager.GetInstance().CoutLog('sql = ' + sql,Com_db_tools);
            return oErrorBase.base_failed,-1;
        int_view_id = -1;
        for view_id in cou.fetchall():
            int_view_id = view_id[0];
            break;
        if (-1 == int_view_id):
            log_manager.GetInstance().CoutLog('real view id is empty, sql=%s' % (sql),Com_db_tools);
            return oErrorBase.base_failed,-1;
        return oErrorBase.base_succeed,int_view_id;






**********************************


文件名:dev_cfg_manager.py
**********************************
# -*- coding: utf8 -*-
from rest_tools import *;
from db_tools import *;
from user_param_manager import *;
import sys;
sys.path.append("..");
from scdllib import *;
import codecs;
from error_manager import *;
from log_manager import *;


class dev_cfg_manager:
    __instance = None;


    def __init__(self):
        pass;


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


    def GetRealDevCfgByTopoName(self,p_str_topo_name):
        log_manager.GetInstance().CoutLog('begin to exec GetRealDevCfgByTopoName',Com_dev_cfg_manager);
        result = oErrorBase.base_succeed;
        real_db_tool = db_tools();
        real_db_tool.SetDBInfo(param_tool.GetInstance().param_db_real.m_str_db_ip,param_tool.GetInstance().param_db_real.m_str_db_user,param_tool.GetInstance().param_db_real.m_str_db_pw);
        result = real_db_tool.OpenDBCon('config_db');
        if (oErrorBase.base_succeed != result):
            return result;
        result,t_dic_devip_id = real_db_tool.GetDevIPIDDicByTopoName(p_str_topo_name);
        if (oErrorBase.base_succeed != result):
            return result;
        result = real_db_tool.CloseDBCon();
        if (oErrorBase.base_succeed != result):
            return result;
        my_resttool = PublicRestTool();
        my_resttool.InitRestInfo();
        for key in t_dic_devip_id:
            result,str = my_resttool.GetDevCfg(key);
            if (oErrorBase.base_succeed != result):
                return result;
            try:
                file_cfg = codecs.open(dir.src_config_file_dir + t_dic_devip_id[key]+ '.cfg','w+','utf-8');
                file_cfg.write(str[0]);
                file_cfg.close();
            except Exception, e:
                log_manager.GetInstance().CoutLog('open file failed ,file name:' + 'src_config_file/' +t_dic_devip_id[key]+ '.cfg',Com_dev_cfg_manager);
                return oErrorBase.base_failed;
        log_manager.GetInstance().CoutLog('end to exec GetRealDevCfgByTopoName',Com_dev_cfg_manager);
        return result;




**********************************


文件名:dev_label_manager.py
**********************************
# -*- coding: utf8 -*-


import pymssql;
import re;
import sys
import urllib2
import json
from error_manager import *;
from log_manager import *;


class dev_label_manager:


    __instance = None;
    __db_ip = '';
    __db_user = '';
    __db_pw = '';
    __dict_ip_label = {};
    __imc_user = '';
    __imc_pw = '';
    __imc_url = '';
    __http_url='http://';


    def __init__(self):
        pass;


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


    def SetDBInfo(self,p_str_db_ip,p_str_db_user,p_str_db_pw):
        log_manager.GetInstance().CoutLog('begin to exec SetDBInfo',Com_dev_label_manager);
        self.__db_ip = p_str_db_ip;
        self.__db_user = p_str_db_user;
        self.__db_pw = p_str_db_pw;
        log_manager.GetInstance().CoutLog('end to exec SetDBInfo',Com_dev_label_manager);


    def SetRestInfo(self,p_imc_user,p_imc_pw,p_imc_url):
        self.__imc_user = p_imc_user;
        self.__imc_pw = p_imc_pw;
        self.__imc_url = p_imc_url;


    def LoadDevLabelFromFile(self,p_str_file_name):
        log_manager.GetInstance().CoutLog('begin to exec LoadDevLabelFromFile',Com_dev_label_manager);
        file_label = None;
        try:
            file_label = open(p_str_file_name);
        except Exception, e:
            log_manager.GetInstance().CoutLog('open file failed,file name:' + p_str_file_name,Com_dev_label_manager);
            return oErrorBase.base_failed;
        if file_label:
            for line in file_label:
                str_ip = '';
                str_label = '';
                pa_ip = re.compile('.*:');
                ma_ip = pa_ip.search(line);
                if ma_ip:
                    str_ip = ma_ip.group();
                    str_ip = str_ip.replace(':','');
                    str_label = line.replace(ma_ip.group(),'');
                    str_label = str_label.replace('\n','');
                    self.__dict_ip_label[str_ip] = str_label;
        file_label.close();
        log_manager.GetInstance().CoutLog('end to exec LoadDevLabelFromFile',Com_dev_label_manager);
        return oErrorBase.base_succeed;


    def UpdateLabelInDB(self):
        log_manager.GetInstance().CoutLog('begin to exec UpdateLabelInDB',Com_dev_label_manager);
        data = None;
        f_data = None;
        try:
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页