From: <Z3...@us...> - 2012-09-23 21:14:08
|
Revision: 342 http://spd.svn.sourceforge.net/spd/?rev=342&view=rev Author: Z3po Date: 2012-09-23 21:13:56 +0000 (Sun, 23 Sep 2012) Log Message: ----------- Sorry for the broken checkin...I'm doing some work currently to implement different spdStore types. Modified Paths: -------------- branches/spd-ng/src/Interfaces/cli.py branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdCore.py branches/spd-ng/src/spdInterface.py Added Paths: ----------- branches/spd-ng/src/spdStore/devel.py branches/spd-ng/src/spdStore/plain.py Modified: branches/spd-ng/src/Interfaces/cli.py =================================================================== --- branches/spd-ng/src/Interfaces/cli.py 2012-09-13 12:02:44 UTC (rev 341) +++ branches/spd-ng/src/Interfaces/cli.py 2012-09-23 21:13:56 UTC (rev 342) @@ -158,8 +158,7 @@ parser = OptionParser( "%prog [Options] [Keywords]", description = "SPD - Simple Password Displayer - CLI", - version = """spdCore """ + versions['spdCore'] + - """\nspdInterface """ + versions['spdInterface'] + + version = """\nspdInterface """ + versions['spdInterface'] + """\nspdConfig """ + versions['spdConfig'] + """\nspdDefaults """ + versions['spdDefaults'] + """\nConfigFile """ + versions['ConfigFile'] + Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2012-09-13 12:02:44 UTC (rev 341) +++ branches/spd-ng/src/spdConfig.py 2012-09-23 21:13:56 UTC (rev 342) @@ -330,6 +330,28 @@ self.__ErrorHandler(self.ReturnCodes[reval]) # }}} + def getStoreType(self, raw=False): # {{{ + '''get the clientmode. + # return the clientmode option''' + + reval, storetype = self.__getOption('Main', 'storetype') + + if reval > 0 and reval < 64: + self.__ErrorHandler(self.ReturnCodes[reval]) + + if reval > 0: + if raw: + return reval, None + else: + self.__ErrorHandler(self.ReturnCodes[reval]) + + if raw: + return reval, storetype + + return storetype + # }}} + + # }}} # EOF Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2012-09-13 12:02:44 UTC (rev 341) +++ branches/spd-ng/src/spdCore.py 2012-09-23 21:13:56 UTC (rev 342) @@ -9,9 +9,6 @@ import re import random import string -#import spdConfig -import spdStore -__version__ = '0.3-alpha' class Core(object): @@ -20,7 +17,8 @@ def __init__(self,ConfigObject): # {{{ self.ConfigSection = ConfigObject.ConfigSection self.PasswordColumn = ConfigObject.getPasswordfield() - self.db = sqlite3.connect('test.db') + self.storeType = __import__('spdStore.' + ConfigObject.getStoreType()) + self.db = sqlite3.connect(':memory:') self.db.row_factory = self.__sql2dict self.dbc = self.db.cursor() Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2012-09-13 12:02:44 UTC (rev 341) +++ branches/spd-ng/src/spdInterface.py 2012-09-23 21:13:56 UTC (rev 342) @@ -15,188 +15,162 @@ from sys import exit import os import string +import spdConfig +import spdDefaults +import spdCore -try: - import spdConfig - import spdDefaults - import spdCore -except ImportError: - print '##### ERROR #####' - print 'spdInterface: spd not installed. Missing Modules.' - exit(2) - __version__ = '0.3-alpha' class Interface(object): # {{{ - """The Interface Module. - Interface between client and Core.""" - __spddir = os.path.expanduser('~/.spd/') - __client = None - __core = None + """The Interface Module. + Interface between client and Core.""" + __spddir = os.path.expanduser('~/.spd/') + __client = None + __core = None - def __init__(self,clientmode=False): # {{{ - """init procedure""" - initcheck = {} + def __init__(self,clientmode=False): # {{{ + """init procedure""" + initcheck = {} - if not os.access(self.__spddir, os.F_OK): - try: - os.mkdir(self.__spddir) - except Exception, e: - self.__ErrorHandler('__init__','Could not create ' + self.__spddir + ' Exception: ' + str(e)) - - __config = spdConfig.Config() + if not os.access(self.__spddir, os.F_OK): + os.mkdir(self.__spddir) + + __config = spdConfig.Config() - reval, initcheck['version'] = __config.getConfigVersion(raw=True) - - if reval > 0 and reval < 64: - spdDefaults.createDefaultConfig(__config) - return self.__startupCheck() - elif reval == 64: - print 'ConfigVersion not found...setting Default one\n' - __input = raw_input('Press any key') - __config.setConfigVersion('0.3-alpha') - initcheck.update({ 'version' : __config.getConfigVersion() }) + reval, initcheck['version'] = __config.getConfigVersion(raw=True) + + if reval > 0 and reval < 64: + spdDefaults.createDefaultConfig(__config) + return self.__startupCheck() + elif reval == 64: + print 'ConfigVersion not found...setting Default one\n' + __input = raw_input('Press any key') + __config.setConfigVersion('0.3-alpha') + initcheck.update({ 'version' : __config.getConfigVersion() }) - reval, initcheck['clientmode'] = __config.getClientmode(raw=True) + reval, initcheck['clientmode'] = __config.getClientmode(raw=True) - if reval > 0: - print 'Clientmode not found...setting it to CLI\n' - __input = raw_input('Press any key') - __config.setClientmode('CLI') - initcheck.update({ 'clientmode' : __config.getClientmode() }) + if reval > 0: + print 'Clientmode not found...setting it to CLI\n' + __input = raw_input('Press any key') + __config.setClientmode('cli') + initcheck.update({ 'clientmode' : __config.getClientmode() }) - reval, __passwordfield = __config.getPasswordfield(raw=True) + reval, __passwordfield = __config.getPasswordfield(raw=True) - if reval == 0: - initcheck.update({ 'passwordfield' : __passwordfield }) + if reval == 0: + initcheck.update({ 'passwordfield' : __passwordfield }) + if not clientmode: + clientmode = initcheck['clientmode'] - if not clientmode: - clientmode = initcheck['clientmode'] + __tempclient = __import__('Interfaces.' + clientmode.lower()) + self.__client = __tempclient.cli + del __tempclient - try: - __tempclient = __import__('Interfaces.' + clientmode.lower()) - except ImportError: - self.__ErrorHandler('__init__', 'clientmode ' + clientmode + ' not available!') - else: - self.__client = __tempclient.cli - del __tempclient + if 'passwordfield' in initcheck: + self.__client._passwordfield = initcheck['passwordfield'] - if 'passwordfield' in initcheck: - self.__client._passwordfield = initcheck['passwordfield'] + self.__core = spdCore.Core(__config) - self.__core = spdCore.Core(__config) + self.__version = { 'ConfigFile' : initcheck['version'], + 'spdInterface' : __version__, + 'spdDefaults' : spdDefaults.__version__, + 'spdConfig' : spdConfig.__version__ } - self.__version = { 'ConfigFile' : initcheck['version'], - 'spdCore' : spdCore.__version__, - 'spdInterface' : __version__, - 'spdDefaults' : spdDefaults.__version__, - 'spdConfig' : spdConfig.__version__ } + del initcheck + # }}} - del initcheck - # }}} + def __findPasswords(self,args): # {{{ + """Find the passwords by searchlist/searchstring handed. + print the results in CLIENTMODE. + # searchlist: optional string or list of keywords to search for.""" - def __ErrorHandler(self,function,message): # {{{ - """ErrorHandler of the Interface Module. - # message: means the \'Exception\' to throw""" - print "################################################" - print "spdInterface ErrorHandler." - print "ERRORFUNCTION: " + function - print "ERRORMESSAGE: " + message - print "################################################" - exit(2) - # }}} + if 'byid' in args: + byid = args['byid'] + + if 'args' in args: + searchString = args['args'] + else: + searchString = '%' - def __findPasswords(self,args): # {{{ - """Find the passwords by searchlist/searchstring handed. - print the results in CLIENTMODE. - # searchlist: optional string or list of keywords to search for.""" + if type(searchString).__name__ == 'list': + searchlist = searchString + else: + searchlist = string.split(searchString) - if 'byid' in args: - byid = args['byid'] - - if 'args' in args: - searchString = args['args'] - else: - searchString = '%' + if len(searchlist) == 0: + searchlist = ['%',] - if type(searchString).__name__ == 'list': - searchlist = searchString - else: - searchlist = string.split(searchString) + passdict = self.__core.searchEntry(searchlist,byid) - if len(searchlist) == 0: - searchlist = ['%',] + return passdict + # }}} - passdict = self.__core.searchEntry(searchlist,byid) + def printPasswords(self,args): # {{{ + passdict = self.__findPasswords(args) + self.__client.printPasswords(passdict, args) + # }}} - return passdict - # }}} + def deleteEntry(self, args): # {{{ + __passdict = self.__findPasswords(args) + + if len(__passdict) == 0: + raise ValueError('deleteEntry','No matches found') - def printPasswords(self,args): # {{{ - passdict = self.__findPasswords(args) - self.__client.printPasswords(passdict, args) - # }}} + self.__client.printPasswords(__passdict) + ids = self.__client.deleteEntry(__passdict) + self.__core.delEntry(ids) + # }}} - def deleteEntry(self, args): # {{{ - __passdict = self.__findPasswords(args) - - if len(__passdict) == 0: - self.__ErrorHandler('deleteEntry','No matches found') + def editEntry(self,args): # {{{ + __passdict = self.__findPasswords(args) + if len(__passdict) > 0: + __newpassdict = self.__client.editEntry(__passdict) + self.__core.editEntry(__newpassdict) + else: + raise ValueError('no matches for ' + str(args["args"]) + 'found') + # }}} - self.__client.printPasswords(__passdict) - ids = self.__client.deleteEntry(__passdict) - self.__core.delEntry(ids) - # }}} + def deleteColumn(self,args): # {{{ + if 'args' in args: + columns = args['args'] + else: + columns = [] + for column in columns: + if column in self.__core.getColumns(showid=False): + self.__core.delColumn(column) + else: + raise ValueError('deleteColumn','column ' + column + ' is not part of the passwordfile') + # }}} - def editEntry(self,args): # {{{ - __passdict = self.__findPasswords(args) - if len(__passdict) > 0: - __newpassdict = self.__client.editEntry(__passdict) - self.__core.editEntry(__newpassdict) - else: - self.__ErrorHandler('editEntry','no matches for ' + str(args["args"]) + 'found') - # }}} + def addColumn(self,args): # {{{ + if 'args' in args: + columns = args['args'] + else: + columns = [] - def deleteColumn(self,args): # {{{ - if 'args' in args: - columns = args['args'] - else: - columns = [] - for column in columns: - if column in self.__core.getColumns(showid=False): - self.__core.delColumn(column) - else: - self.__ErrorHandler('deleteColumn','column ' + column + ' is not part of the passwordfile') - # }}} + for column in columns: + self.__core.addColumn(column) + # }}} - def addColumn(self,args): # {{{ - if 'args' in args: - columns = args['args'] - else: - columns = [] + def addEntry(self, args): # {{{ + Entry = self.__client.createEntry(self.__core.getColumns(showid=False)) + self.__core.addEntry(Entry) + # }}} - for column in columns: - self.__core.addColumn(column) - # }}} + def main(self): # {{{ + function, args = self.__client.parseArgs(self.__version) + getattr(self, function)(args) + # }}} - def addEntry(self, args): # {{{ - Entry = self.__client.createEntry(self.__core.getColumns(showid=False)) - self.__core.addEntry(Entry) - # }}} - - def main(self): # {{{ - function, args = self.__client.parseArgs(self.__version) - getattr(self, function)(args) - # }}} - # }}} if __name__ == '__main__': - Iface = Interface() - Iface.main() + Iface = Interface() + Iface.main() # EOF -# vim:foldmethod=marker:tabstop=3:autoindent:noexpandtab:shiftwidth=3 +# vim:filetype=python:foldmethod=marker:autoindent:expandtab:tabstop=4 Added: branches/spd-ng/src/spdStore/devel.py =================================================================== --- branches/spd-ng/src/spdStore/devel.py (rev 0) +++ branches/spd-ng/src/spdStore/devel.py 2012-09-23 21:13:56 UTC (rev 342) @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# + +import sqlite3 + +testdb = '/home/scabrera/Projects/spd/branches/spd-ng/test.db' + +def __sql2dict(self,cursor,row): # {{{ + result = {} + for ColumnNr, Column in enumerate(cursor.description): + result[Column[0]] = row[ColumnNr] + + return result + +# }}} + +def getData(): # {{{ + db = sqlite3.connect(testdb) + db.row_factory = __sql2dict + dbc = db.cursor() + + query = 'SELECT * FROM Main' + dbc.execute(query) + print str(dbc) + + Property changes on: branches/spd-ng/src/spdStore/devel.py ___________________________________________________________________ Added: svn:keywords + Author Date Id Rev URL Added: svn:eol-style + native Added: branches/spd-ng/src/spdStore/plain.py =================================================================== --- branches/spd-ng/src/spdStore/plain.py (rev 0) +++ branches/spd-ng/src/spdStore/plain.py 2012-09-23 21:13:56 UTC (rev 342) @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# + +pass Property changes on: branches/spd-ng/src/spdStore/plain.py ___________________________________________________________________ Added: svn:keywords + Author Date Id Rev URL Added: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |