From: <Z3...@us...> - 2011-06-28 20:24:29
|
Revision: 337 http://spd.svn.sourceforge.net/spd/?rev=337&view=rev Author: Z3po Date: 2011-06-28 20:24:22 +0000 (Tue, 28 Jun 2011) Log Message: ----------- think i found the right structure :) Modified Paths: -------------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Added Paths: ----------- branches/spd-ng/src/Interfaces/ branches/spd-ng/src/Interfaces/cli.py branches/spd-ng/src/spdInterface.py Removed Paths: ------------- branches/spd-ng/src/Interfaces/__init__.py branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdInterface/ Deleted: branches/spd-ng/src/Interfaces/__init__.py =================================================================== --- branches/spd-ng/src/spdInterface/__init__.py 2011-06-27 20:31:22 UTC (rev 336) +++ branches/spd-ng/src/Interfaces/__init__.py 2011-06-28 20:24:22 UTC (rev 337) @@ -1,201 +0,0 @@ -'''spdInterface Module. - -The Modules handles all the exchange between user and spdCore. -Usage: - import spdInterface - Interface = spdInterface.Interface() - Interface.main() - -or force a clientmode with: - Interface = spdInterface.Interface('CLI') - -if building your own interface, name it spd"whatever" and pass "whatever" -to the Interface Class. The Module must be in pythons include path.''' - -from sys import exit -import os -import string - -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/') - __version = None - __client = None - __core = None - - def __init__(self,clientmode=False): # {{{ - """init procedure""" - - initcheck = self.__startupCheck() - - self.__version = initcheck['version'] - - if not clientmode: - clientmode = initcheck['clientmode'] - - try: - __tempclient = __import__('spd' + clientmode) - 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'] - - del initcheck - - self.__core = spdCore.Core(ConfigSection='Main') - # }}} - - 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) - # }}} - - def __startupCheck(self): # {{{ - """Do initial checks""" - __initargs = {} - - if not os.access(self.__spddir, os.F_OK): - try: - os.mkdir(self.__spddir) - except Exception, e: - self.__ErrorHandler('__startupCheck','Could not create ' + self.__spddir + ' Exception: ' + str(e)) - - __config = spdConfig.Config() - - reval, __initargs['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') - __initargs.update({ 'version' : __config.getConfigVersion() }) - - reval, __initargs['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') - __initargs.update({ 'clientmode' : __config.getClientmode() }) - - reval, __passwordfield = __config.getPasswordfield(raw=True) - - if reval == 0: - __initargs.update({ 'passwordfield' : __passwordfield }) - - return(__initargs) - # }}} - - 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 'byid' in args: - byid = args['byid'] - - if 'args' in args: - searchString = args['args'] - else: - searchString = '%' - - if type(searchString).__name__ == 'list': - searchlist = searchString - else: - searchlist = string.split(searchString) - - if len(searchlist) == 0: - searchlist = ['%',] - - passdict = self.__core.searchEntry(searchlist,byid) - - return passdict - # }}} - - def printPasswords(self,args): # {{{ - passdict = self.__findPasswords(args) - self.__client.printPasswords(passdict, args) - # }}} - - def deleteEntry(self, args): # {{{ - __passdict = self.__findPasswords(args) - - if len(__passdict) == 0: - self.__ErrorHandler('deleteEntry','No matches found') - - self.__client.printPasswords(__passdict) - ids = self.__client.deleteEntry(__passdict) - self.__core.delEntry(ids) - # }}} - - 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 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') - # }}} - - def addColumn(self,args): # {{{ - if 'args' in args: - columns = args['args'] - else: - columns = [] - - for column in columns: - self.__core.addColumn(column) - # }}} - - 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) - # }}} - -# }}} - - -# EOF -# vim:foldmethod=marker:tabstop=3:autoindent:noexpandtab:shiftwidth=3 Copied: branches/spd-ng/src/Interfaces/cli.py (from rev 336, branches/spd-ng/src/spdCLI.py) =================================================================== --- branches/spd-ng/src/Interfaces/cli.py (rev 0) +++ branches/spd-ng/src/Interfaces/cli.py 2011-06-28 20:24:22 UTC (rev 337) @@ -0,0 +1,265 @@ +"""Client Interfaces Module + +This is the Cli Module. +Resistance is futile""" + + +from optparse import OptionParser, OptionGroup +from sys import stdout +from re import sub, search + +__version__ = '0.3-alpha' +_passwordfield = 'Password' + +def __ErrorHandler(function,message): # {{{ + """ErrorHandler of the Client Module. + # function: the function which throws the error + # message: means the \'Exception\' to throw""" + print "################################################" + print "Cli ErrorHandler." + print "ERRORFUNCTION: " + function + print "ERRORMESSAGE: " + message + print "################################################" + exit(2) +# }}} + +def printPasswords(passdict,args=None): # {{{ + """Print the passwords out of a dictionary. + # passdict: the dictionary full of passwords""" + __keylength = {} + pwonly = False + + if args is not None: + if 'pwonly' in args: + pwonly = args['pwonly'] + if 'outmode' in args: + __outmode = args['outmode'] + + if type(passdict).__name__ != 'NoneType' and len(passdict) != 0: + if pwonly: + if len(passdict['__ID']) > 1: + __ErrorHandler('printPasswords', 'pwonly selected but more than one result returned') + else: + print passdict[_passwordfield][0] + + elif __outmode == 'line': + length = 0 + for key in passdict.keys(): + if length < len(key): + length = len(key) + print "" + for i in range(0,len(passdict.values()[0])): + print "__ID".ljust(length) + ':' + str(passdict["__ID"][i]) + for key in passdict: + if key == '__ID': + continue + if type(passdict[key][i]).__name__ != 'NoneType': + print key.ljust(length) + ': ' + sub('\n','\n ' + ' '.ljust(length),passdict[key][i]) + else: + print key.ljust(length) + ': ' + print "" + elif __outmode == 'wide': + for key in passdict: + __keylength.update({ key : 0 }) + + if len(key) > __keylength[key]: + __keylength[key] = len(key) + for value in passdict[key]: + if value is not None: + if search('\n',str(value)): + for partvalue in value.split('\n'): + if len(str(partvalue)) > __keylength[key]: + __keylength[key] = len(str(partvalue)) + else: + if len(str(value)) > __keylength[key]: + __keylength[key] = len(str(value)) + + for key in passdict: + stdout.write(key.ljust(__keylength[key]) + '|') + stdout.write('\n') + + __entries = len(passdict.values()[0]) + + for i in range(0,__entries): + __space = '' + for key in passdict: + if passdict[key][i] is None: + passdict[key][i] = '' + __count = 0 + for line in str(passdict[key][i]).split('\n'): + if __count > 0: + stdout.write('\n' + __space) + stdout.write(line.ljust(__keylength[key]) + '|') + __count += 1 + __space = __space + ''.ljust(__keylength[key],'>') + '>' + stdout.write('\n') + else: + __ErrorHandler('printPasswords', 'output mode unknown: ' + str(__outmode)) + else: + print "No Results found" +# }}} + +def editEntry(__passdict): # {{{ + __count = len(__passdict['__ID']) + for i in range(0, __count): + print '---------------------------' + print 'Changing Entry with ID: ' + str(__passdict['__ID'][i]) + '\nENTER for no changes.' + for __column in __passdict: + __input = '' + if __column != '__ID': + if __passdict[__column][i] is None: + __passdict[__column][i] = '' + __input = raw_input(__column + ' (' + str(__passdict[__column][i]) + '): ') + if search('^"""',__input): + tempinput = sub('^"""','',__input) + '\n' + __input = raw_input(' '.ljust(len(__column),'>') + ':') + while not search('"""$',__input): + tempinput = tempinput + __input + '\n' + __input = raw_input(' '.ljust(len(__column),'>') + ':') + tempinput = tempinput + sub('"""$','',__input) + __passdict[__column][i] = tempinput + elif __input != '': + __passdict[__column][i] = __input + return __passdict +# }}} + +def deleteEntry(__passdict): # {{{ + __count = len(__passdict['__ID']) + __ids = [] + print '\n---------------------------' + for i in range(0, __count): + __input = None + while __input != 'y' and __input != 'n': + __input = raw_input('Delete Entry with ID ' + str(__passdict['__ID'][i]) + ' (y|n)?') + if __input == 'y': + __ids.append(__passdict['__ID'][i]) + return __ids +# }}} + +def createEntry(columns): # {{{ + Entry = {} + print "Adding a new Entry to our passfile" + for column in columns: + value = raw_input(column + ': ') + if search('^"""',value): + tempval = sub('^"""','',value) + '\n' + value = raw_input(column + ': ') + while not search('"""$',value): + tempval = tempval + value + '\n' + value = raw_input(column + ': ') + tempval = tempval + sub('"""$','',value) + value = tempval + Entry.update({ column : value }) + return Entry +# }}} + +def parseArgs(version): # {{{ + __optionsdict = {} + + parser = OptionParser( "%prog [Options] [Keywords]", + description = "SPD - Simple Password Displayer - CLI", + version = """spdCore """ + version + + """\nspdCLI """ + __version__, + epilog = """With no parameters it will print out everything! + Please report Bugs or Feature Request at http://spd.sourceforge.net""") + + parser.add_option( "-a", "--add", + action="store_true", + dest = "addEntry", + default=False, + help = "Add an Entry") + + parser.add_option( "-e", "--edit", + action = "store_true", + dest ="editEntry", + help ="Edit given Entries (IDs)") + + parser.add_option( "-d", "--delete", + action = "store_true", + dest ="deleteEntry", + default = False, + help ="Delete given Entries") + + group = OptionGroup(parser, "Input Manipulation") + + group.add_option( "--id", + action="store_true", + dest ="byid", + default=False, + help ="Handle Input given as ID(s)") + + parser.add_option_group(group) + + group = OptionGroup(parser, "Output Manipulation") + + group.add_option( "-w", "--wide", + action="store_true", + dest = "widemode", + default=False, + help = "print output in wide mode (means as a table)") + + + group.add_option( "-p", "--password-only", + action="store_true", + dest = "pwonly", + default=False, + help = "print Password only of first match, usefull for piping (e.g. in rdesktop)") + + parser.add_option_group(group) + + + #parser.add_option( "-l", "--local", + # action="store_true", + # dest = "localStore", + # default=False, + # help = "do not operate on the configured RCS, only use the local password container") + # + #parser.add_option( "--passfile", + # dest = "passfile", + # help = "do not use the confgured passfile but the one given here") + + group = OptionGroup(parser, "Columns Manipulation") + + group.add_option( "--add-columns", + action="store_true", + dest = "addColumn", + default=False, + help = "Add given Column(s)") + + group.add_option( "--delete-columns", + action = "store_true", + dest ="deleteColumn", + default = False, + help ="Delete Columns given") + + parser.add_option_group(group) + + (options, args) = parser.parse_args() + + if options.widemode: + __outmode = 'wide' + else: + __outmode = 'line' + + __optionsdict.update({ 'args' : args, + 'byid' : options.byid, + 'outmode' : __outmode, + 'pwonly' : options.pwonly }) + + if options.addEntry: + return ["addEntry", __optionsdict] + elif options.deleteEntry: + return ["deleteEntry", __optionsdict] + elif options.editEntry: + return ["editEntry", __optionsdict] + + elif options.deleteColumn: + return ["deleteColumn", __optionsdict] + elif options.addColumn: + return ["addColumn", __optionsdict] + + return ["printPasswords", __optionsdict] +# }}} + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:noexpandtab:shiftwidth=3 Deleted: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2011-06-27 20:31:22 UTC (rev 336) +++ branches/spd-ng/src/spdCLI.py 2011-06-28 20:24:22 UTC (rev 337) @@ -1,261 +0,0 @@ -#!/usr/bin/python - -from optparse import OptionParser, OptionGroup -from sys import stdout -from re import sub, search - -__version__ = '0.3-alpha' - - -class Cli(object): # {{{ - """This is the Cli Module. - Resistance is futile""" - __outmode = None - __version__ = '0.3-alpha' - _passwordfield = 'Password' - - def __ErrorHandler(self,function,message): # {{{ - """ErrorHandler of the Client Module. - # function: the function which throws the error - # message: means the \'Exception\' to throw""" - print "################################################" - print "spdCli ErrorHandler." - print "ERRORFUNCTION: " + function - print "ERRORMESSAGE: " + message - print "################################################" - exit(2) - # }}} - - def printPasswords(self,passdict,args=None): # {{{ - """Print the passwords out of a dictionary. - # passdict: the dictionary full of passwords""" - __keylength = {} - pwonly = False - - if args is not None: - if 'pwonly' in args: - pwonly = args['pwonly'] - - if type(passdict).__name__ != 'NoneType' and len(passdict) != 0: - if pwonly: - if len(passdict['__ID']) > 1: - self.__ErrorHandler('printPasswords', 'pwonly selected but more than one result returned') - else: - print passdict[self._passwordfield][0] - - elif self.__outmode == 'line': - length = 0 - for key in passdict.keys(): - if length < len(key): - length = len(key) - print "" - for i in range(0,len(passdict.values()[0])): - print "__ID".ljust(length) + ':' + str(passdict["__ID"][i]) - for key in passdict: - if key == '__ID': - continue - if type(passdict[key][i]).__name__ != 'NoneType': - print key.ljust(length) + ': ' + sub('\n','\n ' + ' '.ljust(length),passdict[key][i]) - else: - print key.ljust(length) + ': ' - print "" - elif self.__outmode == 'wide': - for key in passdict: - __keylength.update({ key : 0 }) - - if len(key) > __keylength[key]: - __keylength[key] = len(key) - for value in passdict[key]: - if value is not None: - if search('\n',str(value)): - for partvalue in value.split('\n'): - if len(str(partvalue)) > __keylength[key]: - __keylength[key] = len(str(partvalue)) - else: - if len(str(value)) > __keylength[key]: - __keylength[key] = len(str(value)) - - for key in passdict: - stdout.write(key.ljust(__keylength[key]) + '|') - stdout.write('\n') - - __entries = len(passdict.values()[0]) - - for i in range(0,__entries): - __space = '' - for key in passdict: - if passdict[key][i] is None: - passdict[key][i] = '' - __count = 0 - for line in str(passdict[key][i]).split('\n'): - if __count > 0: - stdout.write('\n' + __space) - stdout.write(line.ljust(__keylength[key]) + '|') - __count += 1 - __space = __space + ''.ljust(__keylength[key],'>') + '>' - stdout.write('\n') - else: - self.__ErrorHandler('printPasswords', 'output mode unknown') - else: - print "No Results found" - # }}} - - def editEntry(self,__passdict): # {{{ - __count = len(__passdict['__ID']) - for i in range(0, __count): - print '---------------------------' - print 'Changing Entry with ID: ' + str(__passdict['__ID'][i]) + '\nENTER for no changes.' - for __column in __passdict: - __input = '' - if __column != '__ID': - if __passdict[__column][i] is None: - __passdict[__column][i] = '' - __input = raw_input(__column + ' (' + str(__passdict[__column][i]) + '): ') - if search('^"""',__input): - tempinput = sub('^"""','',__input) + '\n' - __input = raw_input(' '.ljust(len(__column),'>') + ':') - while not search('"""$',__input): - tempinput = tempinput + __input + '\n' - __input = raw_input(' '.ljust(len(__column),'>') + ':') - tempinput = tempinput + sub('"""$','',__input) - __passdict[__column][i] = tempinput - elif __input != '': - __passdict[__column][i] = __input - return __passdict - # }}} - - def deleteEntry(self,__passdict): # {{{ - __count = len(__passdict['__ID']) - __ids = [] - print '\n---------------------------' - for i in range(0, __count): - __input = None - while __input != 'y' and __input != 'n': - __input = raw_input('Delete Entry with ID ' + str(__passdict['__ID'][i]) + ' (y|n)?') - if __input == 'y': - __ids.append(__passdict['__ID'][i]) - return __ids - # }}} - - def createEntry(self,columns): # {{{ - Entry = {} - print "Adding a new Entry to our passfile" - for column in columns: - value = raw_input(column + ': ') - if search('^"""',value): - tempval = sub('^"""','',value) + '\n' - value = raw_input(column + ': ') - while not search('"""$',value): - tempval = tempval + value + '\n' - value = raw_input(column + ': ') - tempval = tempval + sub('"""$','',value) - value = tempval - Entry.update({ column : value }) - return Entry - # }}} - - def parseArgs(self,version): # {{{ - parser = OptionParser( "%prog [Options] [Keywords]", - description = "SPD - Simple Password Displayer - CLI", - version = """spdCore """ + version + - """\nspdCLI """ + self.__version__, - epilog = """With no parameters it will print out everything! - Please report Bugs or Feature Request at http://spd.sourceforge.net""") - - parser.add_option( "-a", "--add", - action="store_true", - dest = "addEntry", - default=False, - help = "Add an Entry") - - parser.add_option( "-e", "--edit", - action = "store_true", - dest ="editEntry", - help ="Edit given Entries (IDs)") - - parser.add_option( "-d", "--delete", - action = "store_true", - dest ="deleteEntry", - default = False, - help ="Delete given Entries") - - group = OptionGroup(parser, "Input Manipulation") - - group.add_option( "--id", - action="store_true", - dest ="byid", - default=False, - help ="Handle Input given as ID(s)") - - parser.add_option_group(group) - - group = OptionGroup(parser, "Output Manipulation") - - group.add_option( "-w", "--wide", - action="store_true", - dest = "widemode", - default=False, - help = "print output in wide mode (means as a table)") - - - group.add_option( "-p", "--password-only", - action="store_true", - dest = "pwonly", - default=False, - help = "print Password only of first match, usefull for piping (e.g. in rdesktop)") - - parser.add_option_group(group) - - - #parser.add_option( "-l", "--local", - # action="store_true", - # dest = "localStore", - # default=False, - # help = "do not operate on the configured RCS, only use the local password container") - # - #parser.add_option( "--passfile", - # dest = "passfile", - # help = "do not use the confgured passfile but the one given here") - - group = OptionGroup(parser, "Columns Manipulation") - - group.add_option( "--add-columns", - action="store_true", - dest = "addColumn", - default=False, - help = "Add given Column(s)") - - group.add_option( "--delete-columns", - action = "store_true", - dest ="deleteColumn", - default = False, - help ="Delete Columns given") - - parser.add_option_group(group) - - (options, args) = parser.parse_args() - - if options.widemode: - self.__outmode = 'wide' - else: - self.__outmode = 'line' - - if options.addEntry: - return ["addEntry", { 'args' : args }] - elif options.deleteEntry: - return ["deleteEntry", { 'byid' : options.byid, 'args' : args }] - elif options.editEntry: - return ["editEntry", { 'byid' : options.byid, 'args' : args }] - - elif options.deleteColumn: - return ["deleteColumn", { 'args' : args }] - elif options.addColumn: - return ["addColumn", { 'args' : args }] - - return ["printPasswords", { 'byid' : options.byid, 'pwonly' : options.pwonly, 'args' : args }] - # }}} - -# }}} - -# EOF -# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2011-06-27 20:31:22 UTC (rev 336) +++ branches/spd-ng/src/spdCore.py 2011-06-28 20:24:22 UTC (rev 337) @@ -191,4 +191,4 @@ # }}} # EOF -# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 +# vim:foldmethod=marker:tabstop=3:autoindent:noexpandtab:shiftwidth=3 Copied: branches/spd-ng/src/spdInterface.py (from rev 336, branches/spd-ng/src/spdInterface/__init__.py) =================================================================== --- branches/spd-ng/src/spdInterface.py (rev 0) +++ branches/spd-ng/src/spdInterface.py 2011-06-28 20:24:22 UTC (rev 337) @@ -0,0 +1,201 @@ +'''spdInterface Module. + +The Modules handles all the exchange between user and spdCore. +Usage: + import spdInterface + Interface = spdInterface.Interface() + Interface.main() + +or force a clientmode with: + Interface = spdInterface.Interface('CLI') + +if building your own interface, name it spd"whatever" and pass "whatever" +to the Interface Class. The Module must be in pythons include path.''' + +from sys import exit +import os +import string + +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/') + __version = None + __client = None + __core = None + + def __init__(self,clientmode=False): # {{{ + """init procedure""" + + initcheck = self.__startupCheck() + + self.__version = initcheck['version'] + + if not clientmode: + clientmode = initcheck['clientmode'] + + 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'] + + del initcheck + + self.__core = spdCore.Core(ConfigSection='Main') + # }}} + + 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) + # }}} + + def __startupCheck(self): # {{{ + """Do initial checks""" + __initargs = {} + + if not os.access(self.__spddir, os.F_OK): + try: + os.mkdir(self.__spddir) + except Exception, e: + self.__ErrorHandler('__startupCheck','Could not create ' + self.__spddir + ' Exception: ' + str(e)) + + __config = spdConfig.Config() + + reval, __initargs['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') + __initargs.update({ 'version' : __config.getConfigVersion() }) + + reval, __initargs['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') + __initargs.update({ 'clientmode' : __config.getClientmode() }) + + reval, __passwordfield = __config.getPasswordfield(raw=True) + + if reval == 0: + __initargs.update({ 'passwordfield' : __passwordfield }) + + return(__initargs) + # }}} + + 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 'byid' in args: + byid = args['byid'] + + if 'args' in args: + searchString = args['args'] + else: + searchString = '%' + + if type(searchString).__name__ == 'list': + searchlist = searchString + else: + searchlist = string.split(searchString) + + if len(searchlist) == 0: + searchlist = ['%',] + + passdict = self.__core.searchEntry(searchlist,byid) + + return passdict + # }}} + + def printPasswords(self,args): # {{{ + passdict = self.__findPasswords(args) + self.__client.printPasswords(passdict, args) + # }}} + + def deleteEntry(self, args): # {{{ + __passdict = self.__findPasswords(args) + + if len(__passdict) == 0: + self.__ErrorHandler('deleteEntry','No matches found') + + self.__client.printPasswords(__passdict) + ids = self.__client.deleteEntry(__passdict) + self.__core.delEntry(ids) + # }}} + + 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 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') + # }}} + + def addColumn(self,args): # {{{ + if 'args' in args: + columns = args['args'] + else: + columns = [] + + for column in columns: + self.__core.addColumn(column) + # }}} + + 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) + # }}} + +# }}} + + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:noexpandtab:shiftwidth=3 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. |