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代码
原文地址:https://www.cnblogs.com/laosun0204/p/9267966.html