36

                                if (elem_hcl_dev.str_dev_ip == elem_tunnel.m_str_left_ip and elem_hcl_dev.str_dev_content.find('        ' + elem_tunnel.m_str_left_inter) != -1):
                                    elem_hcl_dev.str_dev_content = elem_hcl_dev.str_dev_content.replace((elem_tunnel.m_str_right_ip + ' ' + elem_tunnel.m_str_right_inter),(elem_remote_dev.m_str_dev_name + ' ' + elem_tunnel.m_str_tunnel_name));
        log_manager.GetInstance().CoutLog('end to exec SetRemoteInfo',Com_remote_manager);
                        


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


文件名:rest_tools.py
**********************************
import sys;
import urllib2;
import json;
from error_manager import *;
from log_manager import *;


class rest_tools:
    __instance = None;
    __http_url='http://';
    __imc_user = '';
    __imc_pw = '';
    __imc_url = '';
    __api_url = '';


    def __init__(self):
        pass;
    
    @staticmethod
    def GetInstance():
        if (None == rest_tools.__instance):
            rest_tools.__instance = rest_tools();
        return rest_tools.__instance;


    def SetRestInfo(self,p_imc_user,p_imc_pw,p_imc_url):
        log_manager.GetInstance().CoutLog('begin to  exec SetRestInfo',Com_rest_tools);
        rest_tools.__imc_user = p_imc_user;
        rest_tools.__imc_pw = p_imc_pw;
        rest_tools.__imc_url = p_imc_url;
        log_manager.GetInstance().CoutLog('end to  exec SetRestInfo',Com_rest_tools);


    def SendRestOperation(self,p_oper_type,p_api_url,p_data,p_data_type = "application/xml"):
        log_manager.GetInstance().CoutLog('begin to  exec SendRestOperation',Com_rest_tools);
        if ('GET' == p_oper_type):
            log_manager.GetInstance().CoutLog('end to  exec SendRestOperation',Com_rest_tools);
            return self.__RestGet(p_api_url);
        elif ('PUT' == p_oper_type):
            log_manager.GetInstance().CoutLog('end to  exec SendRestOperation',Com_rest_tools);
            return self.__RestPut(p_api_url,p_data,p_data_type);
        elif ('POST' == p_oper_type):
            log_manager.GetInstance().CoutLog('end to  exec SendRestOperation',Com_rest_tools);
            return self.__RestPost(p_api_url,p_data,p_data_type);


    def __RestGet(self,p_api_url):
        log_manager.GetInstance().CoutLog('begin to  exec __RestGet',Com_rest_tools);
        authhandler = urllib2.HTTPDigestAuthHandler();
        authhandler.add_password("iMC RESTful Web Services", rest_tools.__imc_url, rest_tools.__imc_user, rest_tools.__imc_pw);
        opener = urllib2.build_opener(authhandler);
        urllib2.install_opener(opener);
        pagehandle=urllib2.Request(rest_tools.__http_url+rest_tools.__imc_url+p_api_url);
        pagehandle.add_header('Accept', 'application/json');
        result = None;
        try:
            result = urllib2.urlopen(pagehandle);
        except Exception, e:
            log_manager.GetInstance().CoutLog('error:get dev cfg file from imc failed\n' + rest_tools.__http_url+rest_tools.__imc_url+p_api_url,Com_rest_tools);
            return oErrorBase.base_failed,'';
        log_manager.GetInstance().CoutLog('end to  exec __RestGet',Com_rest_tools);
        return oErrorBase.base_succeed,json.loads(result.read()).values();


    def __RestPut(self,p_api_url,p_data,p_data_type = "application/xml"):
        log_manager.GetInstance().CoutLog('begin to  exec __RestPut',Com_rest_tools);
        log_manager.GetInstance().CoutLog('user = ' + rest_tools.__imc_user,Com_rest_tools);
        log_manager.GetInstance().CoutLog('pw = ' + rest_tools.__imc_pw,Com_rest_tools);
        log_manager.GetInstance().CoutLog('url = ' +  rest_tools.__http_url + rest_tools.__imc_url + p_api_url,Com_rest_tools);
        log_manager.GetInstance().CoutLog('data = ' + p_data,Com_rest_tools);
        try:
            authhandler = urllib2.HTTPDigestAuthHandler();
            authhandler.add_password("iMC RESTful Web Services", rest_tools.__imc_url, rest_tools.__imc_user, rest_tools.__imc_pw);
            opener = urllib2.build_opener(authhandler);
            urllib2.install_opener(opener);
            pagehandle=urllib2.Request(rest_tools.__http_url+rest_tools.__imc_url + p_api_url,data = p_data);
            pagehandle.get_method = lambda: 'PUT';
            pagehandle.add_header('accept', '*/*');
            pagehandle.add_header('Content-Type', p_data_type);
            result = urllib2.urlopen(pagehandle);
        except Exception,e:
            log_manager.GetInstance().CoutLog(str(e),Com_rest_tools);
            return oErrorBase.base_failed,'';
        log_manager.GetInstance().CoutLog('end to  exec __RestPut',Com_rest_tools);
        return oErrorBase.base_succeed,'';


    def __RestPost(self,p_api_url,p_data,p_data_type = "application/xml"):
        log_manager.GetInstance().CoutLog('begin to  exec __RestPut',Com_rest_tools);
        log_manager.GetInstance().CoutLog('user = ' + rest_tools.__imc_user,Com_rest_tools);
        log_manager.GetInstance().CoutLog('pw = ' + rest_tools.__imc_pw,Com_rest_tools);
        log_manager.GetInstance().CoutLog('url = ' +  rest_tools.__http_url + rest_tools.__imc_url + p_api_url,Com_rest_tools);
        log_manager.GetInstance().CoutLog('data = ' + p_data,Com_rest_tools);
        try:
            authhandler = urllib2.HTTPDigestAuthHandler();
            authhandler.add_password("iMC RESTful Web Services", rest_tools.__imc_url, rest_tools.__imc_user, rest_tools.__imc_pw);
            opener = urllib2.build_opener(authhandler);
            urllib2.install_opener(opener);
            pagehandle=urllib2.Request(rest_tools.__http_url+rest_tools.__imc_url + p_api_url,data = p_data);
            pagehandle.get_method = lambda: 'POST';
            pagehandle.add_header('accept', '*/*');
            pagehandle.add_header('Content-Type', p_data_type);
            result = urllib2.urlopen(pagehandle);
        except Exception,e:
            log_manager.GetInstance().CoutLog(str(e),Com_rest_tools);
            return oErrorBase.base_failed,'';
        log_manager.GetInstance().CoutLog('end to  exec __RestPut',Com_rest_tools);
        return oErrorBase.base_succeed,'';




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


文件名:scdl_client.py
**********************************
# -*- coding: utf8 -*-
import sys;
import socket
from log_manager import *;
from error_manager import *;


def PassParam():
    int_num = len(sys.argv);
    log_manager.GetInstance().CoutLog('params are below:',Com_scdl_client);
    for i in range(0,int_num):
        log_manager.GetInstance().CoutLog('param' + str(i) + ':' + sys.argv[i],Com_scdl_client);
    str_param = '';
    for i in range(1,int_num-1):
        str_param = str_param + sys.argv[i] + '@_@';
    str_param = str_param + sys.argv[len(sys.argv) - 1];
    log_manager.GetInstance().CoutLog('str_param:' + str_param,Com_scdl_client);
    HOST='127.0.0.1'
    PORT=60007


    try:
        s =socket.socket(socket.AF_INET,socket.SOCK_STREAM)      #定义socket类型,网络通信,TCP
        s.connect((HOST,PORT))       #要连接的IP与端口
        s.send(str_param);
        s.close();
    except Exception,e:
        log_manager.GetInstance().CoutLog('error:' + str(e),Com_foreground_interface);
阅读更多
个人分类: cocos2dx
上一篇35
下一篇37
想对作者说点什么? 我来说一句

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

关闭
关闭
关闭