1 Star 0 Fork 24

walkskyer / SerialGenius

forked from edwinfound / SerialGenius 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
IniFile.py 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
Eamon 提交于 2015-08-30 03:05 . feature: 初始化版本
#coding:utf-8
import ConfigParser, os
import Config;
import Global;
### 增加模块这里需要添加 -----------------------------------------------------------
sections=[ 'setting','module_recv','module_send',
'module_terminal','module_variable','module_variable_track',
'module_video',];
class IniFile:
def __init__(self, filename):
self.filename = filename
self.cfg = None
if not os.path.exists(filename):
f = open(filename, 'w');
f.close();
Save();
def Init(self):
self.cfg = ConfigParser.ConfigParser()
try:
readhandle = open(self.filename, 'r')
self.cfg.readfp(readhandle)
readhandle.close()
except:
ELog.Trace();
def Save(self):
try:
writehandle = open(self.filename, 'w')
self.cfg.write(writehandle)
writehandle.close()
except:
ELog.Trace();
def Get(self, Section, Key, Default = ""):
try:
value = self.cfg.get(Section, Key)
except:
value = Default
return value
def Set(self, Section, Key, Value):
try:
self.cfg.set(Section, Key, Value)
except:
self.cfg.add_section(Section)
self.cfg.set(Section, Key, Value)
def Save():
setting=IniFile(Global.env['app_root']+"setting.ini");
setting.Init();
for section in sections:
for key, value in Config.APP_CONFIG[section].items():
setting.Set(section,key,value);
setting.Save();
def Load():
setting=IniFile(Global.env['app_root']+"setting.ini");
setting.Init();
for section in sections:
for key, value in Config.APP_CONFIG[section].items():
Config.APP_CONFIG[section][key] = setting.Get(section, key, Config.APP_CONFIG[section][key])
1
https://gitee.com/walkskyer/SerialGenius.git
git@gitee.com:walkskyer/SerialGenius.git
walkskyer
SerialGenius
SerialGenius
master

搜索帮助