From: <Z3...@us...> - 2010-12-25 00:35:29
|
Revision: 324 http://spd.svn.sourceforge.net/spd/?rev=324&view=rev Author: Z3po Date: 2010-12-25 00:35:22 +0000 (Sat, 25 Dec 2010) Log Message: ----------- little code cleanup Modified Paths: -------------- branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdDefaults.py branches/spd-ng/src/spdInterface.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-12-24 14:33:23 UTC (rev 323) +++ branches/spd-ng/src/spdConfig.py 2010-12-25 00:35:22 UTC (rev 324) @@ -7,6 +7,7 @@ class Config(object): # {{{ '''This is the Configuration Module You can read or set config options''' + __configfile = None ReturnCodes = { 2 : 'Missing ConfigFile', 4 : 'ConfigFile not Readable', @@ -15,8 +16,8 @@ 32 : 'Section not found', 64 : 'Option not found' } - def __init__(self, conffile='~/.spd/config'): # {{{ - self.configfile = os.path.expanduser(conffile) + def __init__(self, configfile='~/.spd/config'): # {{{ + self.__configfile = os.path.expanduser(configfile) # }}} def __ErrorHandler(self,message): # {{{ @@ -24,7 +25,7 @@ # message: means the \'Exception\' to throw""" print "################################################" print "spdConfig ErrorHandler." - print "Configfile: " + self.configfile + print "Configfile: " + self.__configfile print "ERRORMESSAGE: " + message print "################################################" sys.exit(2) @@ -33,7 +34,7 @@ def __checkConfigFileExist(self): # {{{ """Does the Config file exist?""" - if os.access(self.configfile, os.F_OK): + if os.access(self.__configfile, os.F_OK): return 0 else: return 2 @@ -49,8 +50,8 @@ return reval, config - if os.access(self.configfile,os.R_OK): - config.read(self.configfile) + if os.access(self.__configfile,os.R_OK): + config.read(self.__configfile) return 0,config else: return 4, config @@ -63,14 +64,14 @@ if reval > 0: try: - configfile = open(self.configfile, 'wb') + configfile = open(self.__configfile, 'wb') except IOError: return 8, configfile else: return 0, configfile - if os.access(self.configfile,os.W_OK): - configfile = open(self.configfile, 'wb') + if os.access(self.__configfile,os.W_OK): + configfile = open(self.__configfile, 'wb') else: return 8, None Modified: branches/spd-ng/src/spdDefaults.py =================================================================== --- branches/spd-ng/src/spdDefaults.py 2010-12-24 14:33:23 UTC (rev 323) +++ branches/spd-ng/src/spdDefaults.py 2010-12-25 00:35:22 UTC (rev 324) @@ -24,17 +24,30 @@ def __oldSPDCheck(self): # {{{ __oldspdconfig = '~/.spd/spd.conf' if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): - print 'old config found' + print 'old config found!' + return True, __oldspdconfig + return False, None # }}} def createDefaultConfig(self,config): # {{{ """Create the default config here. # config: the configparser to use""" - self.__oldSPDCheck() - config.addConfigSection('Main') - config.setConfigVersion('0.3-alpha') - config.setClientmode('CLI') + print 'Checking if we are an upgrade first...' + __found, __oldconfig = self.__oldSPDCheck() + if __found == True: + __input = '' + while __input is not 'y' and __input is not 'n': + __input = raw_input('Shall i try to convert the old Configfile?(y|n):') + if __input == 'y': + print 'Trying to convert...' + print 'NOT YET IMPLEMENTED' + else: + __input = raw_input('Going to create default config now...[ENTER]') + config.addConfigSection('Main') + config.setConfigVersion('0.3-alpha') + config.setClientmode('CLI') + __input = raw_input('Done. Back to normal. [ENTER]') # }}} # }}} Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-12-24 14:33:23 UTC (rev 323) +++ branches/spd-ng/src/spdInterface.py 2010-12-25 00:35:22 UTC (rev 324) @@ -10,33 +10,32 @@ class Interface(object): # {{{ """The Interface Module. Connection between Output and Core.""" - spddir = os.path.expanduser('~/.spd/') - config = spdConfig.Config() - version = None - client = None - core = None + __spddir = os.path.expanduser('~/.spd/') + __version = None + __client = None + __core = None def __init__(self,clientmode=False): # {{{ """init procedure""" initcheck = self.__startupCheck() - self.version = initcheck['version'] + self.__version = initcheck['version'] + if not clientmode: clientmode = initcheck['clientmode'] del initcheck try: - __client = __import__('spd' + clientmode) + __tempclient = __import__('spd' + clientmode) except ImportError: - print 'clientmode \"' + clientmode + '\" not available' - exit(2) + self.__ErrorHandler('__init__', 'clientmode ' + clientmode + ' not available!') else: - self.client = __client.Cli() - del __client + self.__client = __tempclient.Cli() + del __tempclient - self.core = spdCore.Core() + self.__core = spdCore.Core() # }}} def __ErrorHandler(self,function,message): # {{{ @@ -53,31 +52,31 @@ def __startupCheck(self): # {{{ """Do initial checks""" - if not os.access(self.spddir, os.F_OK): - os.mkdir(spddir) + if not os.access(self.__spddir, os.F_OK): + os.mkdir(self.__spddir) + + __config = spdConfig.Config() + + reval, __version = __config.getConfigVersion(raw=True) - config = self.config - - reval, version = config.getConfigVersion(raw=True) - if reval > 0 and reval < 64: Defaults = spdDefaults.Defaults() - Defaults.createDefaultConfig(config) + Defaults.createDefaultConfig(__config) return self.__startupCheck() elif reval == 64: print 'ConfigVersion not found...setting Default one\n' - config.setConfigVersion('0.3-alpha') - version = config.getConfigVersion() + __config.setConfigVersion('0.3-alpha') + __version = __config.getConfigVersion() - reval, clientmode = config.getClientmode(raw=True) + reval, clientmode = __config.getClientmode(raw=True) if reval > 0: print 'Clientmode not found...setting it to CLI\n' - config.setClientmode('CLI') - clientmode = config.getClientmode() + __config.setClientmode('CLI') + clientmode = __config.getClientmode() - return({ 'version' : version, + return({ 'version' : __version, 'clientmode' : clientmode }) # }}} @@ -93,13 +92,13 @@ if len(searchlist) == 0: searchlist = ['%',] - passdict = self.core.searchEntry(searchlist) + passdict = self.__core.searchEntry(searchlist) return passdict # }}} def printPasswords(self,searchString='%'): # {{{ passdict = self.findPasswords(searchString) - self.client.printPasswords(passdict) + self.__client.printPasswords(passdict) # }}} def deleteID(self,ids): # {{{ @@ -110,23 +109,23 @@ ids = str(ids) ids = string.split(ids) for id in ids: - self.core.delEntry(id) + self.__core.delEntry(id) # }}} def deleteEntry(self,searchString): # {{{ passdict = self.findPasswords(searchString) print str(passdict) for id in passdict["__ID"]: - self.core.delEntry(id) + self.__core.delEntry(id) # }}} def addEntry(self, args): # {{{ - Entry = self.client.createEntry(self.core.getColumns(showid=False)) - self.core.addEntry(Entry) + Entry = self.__client.createEntry(self.__core.getColumns(showid=False)) + self.__core.addEntry(Entry) # }}} def main(self): # {{{ - function, value = self.client.parseArgs(self.version) + function, value = self.__client.parseArgs(self.__version) getattr(self, function)(value) # }}} Modified: branches/spd-ng/src/test.db =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |