From: <Z3...@us...> - 2010-06-27 13:04:37
|
Revision: 296 http://spd.svn.sourceforge.net/spd/?rev=296&view=rev Author: Z3po Date: 2010-06-27 13:04:31 +0000 (Sun, 27 Jun 2010) Log Message: ----------- added "edit Entry" functionality Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCLI.py trunk/src/spdCore.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2010-06-27 11:51:48 UTC (rev 295) +++ trunk/src/spd-cli 2010-06-27 13:04:31 UTC (rev 296) @@ -36,16 +36,25 @@ epilog = "With no parameters it will print out everything!") parser.add_option( "-d", "--delete", - metavar="Keyword", + metavar="Keywords", dest ="delete", - help ="Entry to delete") + help ="Entries to delete") +parser.add_option( "-e", "--edit", + metavar="ID", + dest ="edit", + help ="Entry to edit") + parser.add_option( "-i", "--delete-id", metavar="ID", dest ="deleteID", help ="ID to delete") +parser.add_option( "--id", + dest ="id", + help ="Search Password by ID") + parser.add_option( "-a", "--add", action="store_true", dest = "add", @@ -58,7 +67,6 @@ default=False, help = "Add a Keyword") - parser.add_option( "-p", "--password-only", action="store_true", dest = "pwonly", @@ -94,14 +102,17 @@ pc.addEntry(interface.newEntry(pc.getCollumns())) pc.exportPasswordsPlain() +if options.edit: + updates = interface.editEntry(pc.findPassword(options.edit,id=True)) + pc.updateEntry(updates) + pc.exportPasswordsPlain() + elif options.addkey: pc.addCollumn(options.addkey) pc.exportPasswordsPlain() elif options.delete: searchPatterns = args - del searchPatterns[0] - del searchPatterns[0] pc.delEntry(searchPatterns) pc.exportPasswordsPlain() @@ -113,26 +124,28 @@ elif options.pwonly: searchPatterns = args try: - print pc.findPassword(searchPatterns)[pc.passwordField][0] + if options.id: + print pc.findPassword(options.id,id=True)[pc.passwordField][0] + else: + print pc.findPassword(searchPatterns)[pc.passwordField][0] except: pass elif options.widemode: searchPatterns = args - interface.tableOutput(pc.findPassword(searchPatterns)) + if options.id: + interface.tableOutput(pc.findPassword(options.id,id=True)) + else: + interface.tableOutput(pc.findPassword(searchPatterns)) else: # regular search searchPatterns = args - if options.localStore: - try: - del searchPatterns[searchPatterns.index('-l')] - except: - del searchPatterns[searchPatterns.index('--local')] - + if options.id: + interface.listOutput(pc.findPassword(options.id,id=True)) + else: + interface.listOutput(pc.findPassword(searchPatterns)) - interface.listOutput(pc.findPassword(searchPatterns)) - # EOF # vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2010-06-27 11:51:48 UTC (rev 295) +++ trunk/src/spdCLI.py 2010-06-27 13:04:31 UTC (rev 296) @@ -143,6 +143,25 @@ # }}} + def editEntry(self,table): # {{{ + + hits = len(table.values()[0]) + + if hits > 1: + print "AN ERROR OCCURED...ID MUST BE UNIQUE" + sys.exit(2) + + print "Change value of Keys. Nothing for unchanged" + for collumn in table: + if collumn != "__ID": + value = raw_input(collumn + " (" + table[collumn][0] + ")" + ": ") + if value: + table[collumn][0] = value + + return table + # }}} + + def setConfig(self,var,value): # {{{ self.config[var] = value # }}} Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2010-06-27 11:51:48 UTC (rev 295) +++ trunk/src/spdCore.py 2010-06-27 13:04:31 UTC (rev 296) @@ -270,10 +270,10 @@ self.__table[str(row[1])] = [] # quite easy, eh? :-) - self.__table = self.findPassword("%",output='noID') + self.__table = self.findPassword("%",id=False,output='noID') #}}} - def findPassword(self,patterns,output='table'): #{{{ + def findPassword(self,patterns,id=False,output='table'): #{{{ """Function helps you to find a password in SQLite Database patterns: list of strings (filter)""" cursor = self.__sql.cursor() @@ -301,7 +301,10 @@ searchCollumns = re.sub(r',$','',searchCollumns) - query = "select " + searchCollumns + " from passwords where " + self.__buildWhere(patterns) + if id: + query = "select " + searchCollumns + " from passwords where __ID = " + patterns + else: + query = "select " + searchCollumns + " from passwords where " + self.__buildWhere(patterns) cursor.execute(query) # convert the result in a Dictionary @@ -358,6 +361,31 @@ cursor.execute(query) #}}} + def updateEntry(self,table): #{{{ + """Updates an Entry + patterns: list of strings""" + setStatement = "" + cursor = self.__sql.cursor() + + for collumn in table: + if collumn != "__ID": + if setStatement: + if not table[collumn][0]: + setStatement = setStatement + ", '" + collumn + "' = ''" + else: + setStatement = setStatement + ", '" + collumn + "' = '" + str(table[collumn][0]) + "'" + else: + if not table[collumn][0]: + setStatement = "SET '" + collumn + "' = ''" + else: + setStatement = "SET '" + collumn + "' = '" + str(table[collumn][0]) + "'" + + query = "UPDATE passwords " + setStatement + " where __ID = " + str(table["__ID"][0]) + + cursor.execute(query) + #}}} + + def __buildWhere(self,patterns): # {{{ """internal function to build the SQL WHERE Statement""" count = 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |