码迷,mamicode.com
首页 > Web开发 > 详细

UI自动化web端框架config.py代码

时间:2018-07-05 14:53:22      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:.config   conf   port   turn   class   mil   mysq   obj   charset   

import json
from lib.core.path import CONFPATH
class ConfigType(object):
MYSQL = ‘mysql‘
REDIS = ‘redis‘

class Config(object):
def __init__(self):
self.config = {}

def make(self):
# mysql 配置信息
self.config[ConfigType.MYSQL] = {}
self.config[ConfigType.MYSQL][‘host‘] = ‘127.0.0.1‘
self.config[ConfigType.MYSQL][‘port‘] = 3306
self.config[ConfigType.MYSQL][‘user‘] = ‘sky‘
self.config[ConfigType.MYSQL][‘passwd‘] = ‘123456‘
self.config[ConfigType.MYSQL][‘db‘] = ‘ssj‘
self.config[ConfigType.MYSQL][‘charset‘] = ‘utf8‘

# redis 配置信息
self.config[ConfigType.MYSQL] = {}
self.config[ConfigType.MYSQL][‘host‘] = ‘127.0.0.1‘
self.config[ConfigType.MYSQL][‘port‘] = 3306
self.config[ConfigType.MYSQL][‘user‘] = ‘sky‘
self.config[ConfigType.MYSQL][‘passwd‘] = ‘123456‘
self.config[ConfigType.MYSQL][‘db‘] = ‘ssj‘
self.config[ConfigType.MYSQL][‘charset‘] = ‘utf8‘

fw = open(CONFPATH,‘w‘)
fw.write(json.dumps(self.config))
fw.flush()
fw.close()

def read(self,config):
fr = open(CONFPATH)
data = json.load(fr)
if config == ConfigType.MYSQL:
return data[ConfigType.MYSQL]
elif config == ConfigType.REDIS:
return data[ConfigType.REDIS]

if __name__ == ‘__main__‘:
Config().make()
print(Config().read(ConfigType.MYSQL))

UI自动化web端框架config.py代码

标签:.config   conf   port   turn   class   mil   mysq   obj   charset   

原文地址:https://www.cnblogs.com/laosun0204/p/9267966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!