|
From: <Z3...@us...> - 2010-09-05 10:17:53
|
Revision: 306
http://spd.svn.sourceforge.net/spd/?rev=306&view=rev
Author: Z3po
Date: 2010-09-05 10:17:46 +0000 (Sun, 05 Sep 2010)
Log Message:
-----------
changed modules to be more scalable
Modified Paths:
--------------
branches/spd-ng/src/spdCheck.py
branches/spd-ng/src/spdConfig.py
Modified: branches/spd-ng/src/spdCheck.py
===================================================================
--- branches/spd-ng/src/spdCheck.py 2010-09-05 01:47:55 UTC (rev 305)
+++ branches/spd-ng/src/spdCheck.py 2010-09-05 10:17:46 UTC (rev 306)
@@ -5,21 +5,40 @@
class CHECK(object):
-# def __init__(self,module):
-# if module = "spdInterface":
-# self.checkConfigFile()
-# elif module = "spdCore":
-# pass
+ def __init__(self,module):
+ if module == "spdInterface":
+ self.checkConfigFile()
+ elif module == "spdCore":
+ pass
def checkConfigFile(self):
config = spdConfig.CONFIG()
- if os.access(self,config.configfile,os.F_OK):
- if config.checkConfigFileReadable(raw=True):
+ if config.checkConfigFileExist():
+ if config.checkConfigFileReadable():
if config.hasSection("Main"):
- version = config.getSPDversion(raw=True)
- if not version:
- pass
- else:
+ if config.getOption("Main","version"):
+ version = config.getSPDversion()
if version == "0.3":
pass
-
+ else:
+ config.ErrorHandler("Where you got THIS version from???\nCannot work with")
+ else:
+ config.setSPDversion("0.3")
+ else:
+ config.setSection("Main")
+ else:
+ config.ErrorHandler("CONFIGFILE THERE BUT NOT READABLE")
+ else:
+ if config.checkConfigFileWriteable():
+ newconfig = DEFAULTS()
+ newconfig.createDefaultConfig(config)
+ else:
+ config.ErrorHandler("CONFIGFILE PATH NOT WRITEABLE")
+
+class DEFAULTS(object):
+
+ def createDefaultConfig(self,config):
+ config.setSection("Main")
+ config.setSPDversion("0.3")
+
+test = CHECK("spdInterface")
Modified: branches/spd-ng/src/spdConfig.py
===================================================================
--- branches/spd-ng/src/spdConfig.py 2010-09-05 01:47:55 UTC (rev 305)
+++ branches/spd-ng/src/spdConfig.py 2010-09-05 10:17:46 UTC (rev 306)
@@ -3,42 +3,47 @@
from ConfigParser import RawConfigParser
import os
import sys
-import spdCheck
class CONFIG(object): # {{{
"""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
+ print "################################################"
+ print "spdConfig ErrorHandler."
+ print "Configfile: " + self.configfile
+ print "ERRORMESSAGE: " + message
+ print "################################################"
sys.exit(2)
# }}}
- def checkConfigFileWriteable(self,raw=False): # {{{
+ def checkConfigFileExist(self): # {{{
+ if os.access(self.configfile, os.F_OK):
+ return True
+ else:
+ return False
+ # }}}
+
+ def checkConfigFileWriteable(self): # {{{
+ if not self.checkConfigFileExist():
+ open(self.configfile, 'w').close()
if os.access(self.configfile,os.W_OK):
return True
else:
- if not raw:
- self.ErrorHandler(self.configfile + " Not WRITEABLE")
- else:
- return False
+ return False
# }}}
- def checkConfigFileReadable(self,raw=False): # {{{
+ def checkConfigFileReadable(self): # {{{
+ config = RawConfigParser()
+ if not self.checkConfigFileExist():
+ self.ErrorHandler("CONFIGFILE MISSING")
if os.access(self.configfile,os.R_OK):
- self.config.read(self.configfile)
- if not raw:
- return self.config
- else:
- return True
+ config.read(self.configfile)
+ return config
else:
- if not raw:
- self.ErrorHandler(configfile + " NOT READABLE")
- else:
- return False
+ return False
# }}}
def writeConfigFile(self,config): # {{{
@@ -50,33 +55,82 @@
# }}}
def hasSection(self,section): # {{{
- config = slf.checkConfigFileReadable()
- return config.has_section(section)
+ config = self.checkConfigFileReadable()
+ if not config:
+ self.ErrorHandler("CONFIGFILE NOT READABLE")
+ if config.has_section(section):
+ return config
# }}}
- def getSPDversion(self,raw=False): # {{{
- config = self.checkConfigFileReadable()
- if config.has_section("Main"):
+ def setSection(self,section): # {{{
+ if not self.checkConfigFileWriteable():
+ self.ErrorHandler("CONFIGFILE NOT WRITEABLE")
+ config = self.hasSection(section)
+ if not config:
+ config = self.checkConfigFileReadable()
+ config.add_section(section)
+ self.writeConfigFile(config)
+ return True
+ else:
+ self.ErrorHandler("SECTION " + section + " already there")
+ # }}}
+
+ def delSection(self,section): # {{{
+ if not self.checkConfigFileWriteable():
+ self.ErrorHandler("CONFIGFILE NOT WRITEABLE")
+ config = self.hasSection(section)
+ if config:
+ config.remove_section(section)
+ return True
+ else:
+ return False
+ # }}}
+
+ def getOption(self,section,option): # {{{
+ config = self.hasSection(section)
+ if config:
if config.has_option("Main","version"):
return config.get("Main","version")
else:
- if not raw:
- self.ErrorHandler("Option version missing")
- else:
- return False
+ return False
else:
- self.ErrorHandler("Section Main missing")
+ self.ErrorHandler("SECTION " + section + " MISSING")
# }}}
- def setSPDversion(self,version): # {{{
- self.checkConfigFileWriteable()
- config = self.checkConfigFileReadable()
- if config.has_section("Main"):
- config.set("Main","version",version)
+ def setOption(self,section,option,value): # {{{
+ config = self.hasSection(section)
+ if config:
+ config.set(section,option,value)
+ self.writeConfigFile(config)
+ return True
else:
- self.ErrorHandler("Section Main missing")
- self.writeConfigFile(config)
+ self.ErrorHandler("SECTION " + section + " MISSING")
# }}}
+
+ def delOption(self,section,option): # {{{
+ config = self.hasSection(section)
+ if config:
+ if self.getOption(section,option):
+ config.remove_option(section,option)
+ self.writeConfigFile(config)
+ return True
+ else:
+ return False
+ else:
+ return False
+ # }}}
+
+ def getSPDversion(self): # {{{
+ option = self.getOption("Main","version")
+ if option:
+ return option
+ else:
+ self.ErrorHandler("Option version missing")
+ # }}}
+
+ def setSPDversion(self,version): # {{{
+ self.setOption("Main","version",version)
+ # }}}
# }}}
# EOF
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|