#!/usr/bin/python
# -*- coding:gbk -*-
# Author: Droeny.zhao
# Version: 2010-04-08
import sys
import ConfigParser
def getinfo(COLUMN,ITEM):
conf=ConfigParser.ConfigParser()
CONFIGNAME = 'game.ini'
if os.path.isfile(CONFIGNAME):
conf.read(CONFIGNAME)
conf.sections()
try:
return conf.get(COLUMN,ITEM)
except ConfigParser.NoOptionError, e:
print 'Wanning:',e
sys.exit()
else:
print 'Wanning: "%s" is not exists, you must appoint the absolute path of config file with -p or -c.'%(CONFIGNAME)
sys.exit()
def setinfo(COLUMN,ITEM,VALUE):
conf=ConfigParser.ConfigParser()
CONFIGNAME = 'game.ini'
if os.path.isfile(CONFIGNAME):
conf.read(CONFIGNAME)
conf.sections()
try:
conf.set(COLUMN,ITEM,VALUE)
conf.write(open(CONFIGNAME, 'w'))
except ConfigParser.NoOptionError, e:
print 'Wanning:',e
sys.exit()
else:
print 'Wanning: "%s" is not exists, you must appoint the absolute path of config file with -p or -c.'%(CONFIGNAME)
sys.exit()
if __name__ == '__main__':
print getinfo('Account','DBName')
setinfo('Account','DBName','GameDB')
print getinfo('Account','DBName')
|