From: <Z3...@us...> - 2010-09-05 00:47:43
|
Revision: 302 http://spd.svn.sourceforge.net/spd/?rev=302&view=rev Author: Z3po Date: 2010-09-05 00:47:33 +0000 (Sun, 05 Sep 2010) Log Message: ----------- first import of Config Module Added Paths: ----------- branches/spd-ng/src/Config.py Added: branches/spd-ng/src/Config.py =================================================================== --- branches/spd-ng/src/Config.py (rev 0) +++ branches/spd-ng/src/Config.py 2010-09-05 00:47:33 UTC (rev 302) @@ -0,0 +1,59 @@ +from ConfigParser import RawConfigParser +import os +import sys + +class CONFIG: # {{{ + """This is the Configuration Module + You can read or set config options""" + + configfile = os.path.expanduser('~/.spd/config') + config = RawConfigParser() + + def ErrorHandler(self,message): + print message + sys.exit(2) + + def checkConfigFileWriteable(self): + if os.access(self.configfile,os.W_OK): + return True + else: + self.ErrorHandler(self.configfile + " Not WRITEABLE") + + def checkConfigFileReadable(self): + if os.access(self.configfile,os.R_OK): + self.config.read(self.configfile) + return self.config + else: + self.ErrorHandler(configfile + " NOT READABLE") + + def writeConfigFile(self,config): + configfile = open(self.configfile, 'wb') + try: + config.write(configfile) + except Exception, e: + self.ErrorHandler("An Error Occured" + str(e)) + + + def getSPDversion(self): + config = self.checkConfigFileReadable() + config.sections + if config.has_section("Main"): + if config.has_option("Main","version"): + return config.get("Main","version") + else: + self.ErrorHandler("Option version missing") + else: + self.ErrorHandler("Section Main missing") + + def setSPDversion(self,version): + self.checkConfigFileWriteable() + config = self.checkConfigFileReadable() + if config.has_section("Main"): + config.set("Main","version",version) + else: + self.ErrorHandler("Section Main missing") + self.writeConfigFile(config) +# }}} + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |