Beispiel #1
0
 def get_def_conn(db="qa_share_base"):
     conf_o = cofConf.MyCfg("cfg.ini")
     conf_o.set_section("mysql")
     host = conf_o.get("host")
     port = conf_o.get("port")
     user = conf_o.get("user")
     password = conf_o.get("pass")
     mysql_o = MysqlConn(host, port, user, password)
     conn = mysql_o.get_connection(db)
     return conn
Beispiel #2
0
    def set_db_cfg(self, cfg_name='mydb', sec_name='mysql'):
        """
        set_db_cfg_type 设置类型

        .. doctest::
            mysql_o.set_db_cfg_type('debug')
            mysql_o.set_db_cfg()

        """
        # 获取数据库配置
        app_loc = cofFile.get_app_loc()

        if not self.db_cfg_type:
            cfg_obj = cofConf.MyCfg(app_loc + os.sep + 'cfgtype.ini')
            cfg_obj.set_section('cfg')
            cfg_type = cfg_obj.get('type')
        else:
            cfg_type = self.db_cfg_type

        db_cfg_obj = cofConf.MyCfg(os.sep + cfg_name + '.ini')
        db_cfg_obj.set_section(sec_name)

        self.host = db_cfg_obj.get('host')
        self.port = int(db_cfg_obj.get('port'))
        self.user = db_cfg_obj.get('user')
        self.passwd = db_cfg_obj.get('passwd')
        self.dbname = db_cfg_obj.get('db')

        self.db = MySQLdb.connect(host=self.host,
                                  port=self.port,
                                  user=self.user,
                                  passwd=self.passwd,
                                  db=self.dbname)
        self.cursor = self.db.cursor()

        pre_sql = "SET NAMES 'utf8'"
        self.exec_sql(pre_sql)
Beispiel #3
0
    def __init__(self):
        cfg_o = CoConfM.MyCfg('cfg.ini')
        cfg_o.set_section('log')
        log_type = cfg_o.get('type')

        logger = logging.getLogger('test01')

        if log_type == 'file':
            pass
        else:
            # 初始化一个日志处理器
            # 连接到日志服务器
            self.scribe_handler = ScribeHandler()
            self.scribe_handler.set_appid(9997)
            self.scribe_handler.set_filepath('/LogTest/Test01/error.log')
            logger.addHandler(self.scribe_handler)

        logger.setLevel(logging.DEBUG)

        self.logger = logger
Beispiel #4
0
    def get_def_conn(db="qa_share_base"):
        conf_o = cofConf.MyCfg("cfg.ini")
        conf_o.set_section("mysql")
        host = conf_o.get("host")
        port = conf_o.get("port")
        user = conf_o.get("user")
        password = conf_o.get("pass")
        mysql_o = MysqlConn(host, port, user, password)
        conn = mysql_o.get_connection(db)
        return conn


if __name__ == "__main__":
    print "start..."
    import cof.conf as CoConfM
    conf_o = CoConfM.MyCfg("cfg.ini")
    conf_o.set_section("mysql")
    host = conf_o.get("host")
    port = conf_o.get("port")
    user = conf_o.get("user")
    password = conf_o.get("pass")
    mysql_o = MysqlConn(host, port, user, password)
    conn = mysql_o.get_connection("qa_share_log")
    conn.set_table("db_info")
    data = dict()
    import cof.rand as CoRandM
    rand_o = CoRandM.CoRand()
    uuid_str = rand_o.uuid()
    data["db_info_id"] = uuid_str
    # data["info"] = "hello,world"
    conn.save(data)
Beispiel #5
0
操作memcache缓存
"""
__author__ = 'Administrator'

import memcache


class CoMemcache(object):
    def __init__(self, host, port):
        link_info = host + ':' + port
        conn = memcache.Client([link_info], debug=0)
        self.conn = conn

    def set(self, k, v):
        self.conn.set(k, v)

    def get(self, k):
        return self.conn.get(k)


if __name__ == "__main__":
    import cof.conf as CoConfM
    conf_o = CoConfM.MyCfg('cfg.ini')
    conf_o.set_section('memcache')
    host = conf_o.get('host')
    port = conf_o.get('port')

    mc = CoMemcache(host, port)
    mc.set("hello", "world")
    print mc.get("hello")