From: <tre...@us...> - 2009-09-06 15:35:45
|
Revision: 269 http://spd.svn.sourceforge.net/spd/?rev=269&view=rev Author: treibholz Date: 2009-09-06 15:35:32 +0000 (Sun, 06 Sep 2009) Log Message: ----------- removed the class config. PasswordContainer now gets the configuration by its constructor. Modified Paths: -------------- trunk/src/spd trunk/src/spdCore.py Modified: trunk/src/spd =================================================================== --- trunk/src/spd 2009-09-05 11:05:52 UTC (rev 268) +++ trunk/src/spd 2009-09-06 15:35:32 UTC (rev 269) @@ -47,9 +47,8 @@ (options, args) = parser.parse_args() # }}} -config = spdCore.config('~/.spd/config') -pc = spdCore.PasswordContainer() -pc.importPasswordsPlain(config.file,"\t",config.encryption,config.vcs) +pc = spdCore.PasswordContainer('~/.spd/config') +pc.importPasswordsPlain() pc.fillSQLite() pc.flushPasswordsPlain() @@ -61,13 +60,13 @@ pc.addEntry(interface.newEntry(pc.getCollumns())) pc.recipients = config.users pc.dumpSQLite() - pc.exportPasswordsPlain(config.file,"\t",config.encryption,config.vcs) + pc.exportPasswordsPlain() elif options.delete: pc.delEntry(options.delete) pc.recipients = config.users pc.dumpSQLite() - pc.exportPasswordsPlain(config.file,"\t",config.encryption,config.vcs) + pc.exportPasswordsPlain() elif options.pwonly: searchPatterns = sys.argv Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-05 11:05:52 UTC (rev 268) +++ trunk/src/spdCore.py 2009-09-06 15:35:32 UTC (rev 269) @@ -46,21 +46,61 @@ # The Constructor # creates an internal memory-based SQLite database and declares a # a the self.__table dictionary - def __init__(self): #{{{ + # file: string, the config-file + def __init__(self,file): #{{{ + self.__sql = sqlite3.connect(":memory:") self.__table = {} - self.passwordField = "Password" + # read the config + file = os.path.expanduser(file) + c = ConfigParser.RawConfigParser() + + if os.access(file,os.F_OK): + c.read(file) + else: # generate the config if not there # {{{ + c.add_section('Main') + c.set('Main','file','~/.spd/spd_data.gpg') + c.set('Main','passwordField','Password') + c.set('Main','encryption','GnuPG') + c.set('Main','vcs','none') + + c.add_section('Users') + c.set('Users', 'User1', "Klaus Umbach") + c.set('Users', 'User2', "Klaus Windows") + + c.add_section('Colors') + c.set('Colors','passwordFG','brightblue') + c.set('Colors','passwordBG','blue') + configfile = open(file, 'wb') + c.write(configfile) + # }}} + + # set the configuration variables + self.file = os.path.expanduser(c.get('Main','file')) + self.encryption = c.get('Main','encryption') + self.passwordField = c.get('Main', 'passwordField') + self.separator = '\t' + + self.vcs = c.get('Main','vcs') + + + self.users=[] + for i in c.items('Users'): + self.users.append(i[1]) + + + #}}} - # Read what-ever-separated passwordfile - # file: string - # separator: string - # encryption: string - # currently either "GnuPG" or "none" - # vcs: string - # currently either "SVN" or "none" - def importPasswordsPlain(self,file,separator,encryption,vcs): #{{{ + # read passwordfile + def importPasswordsPlain(self): #{{{ + vcs = self.vcs + encryption = self.encryption + file = self.file + separator = self.separator + + if (vcs == "svn"): svn = pysvn.Client() svn.update(file) @@ -116,14 +156,15 @@ return True #}}} - # write as what-ever-separated passwordfile - # file: string - # separator: string - # encryption: string - # currently either "GnuPG" or "none" - # vcs: string - # currently either "SVN" or "none" - def exportPasswordsPlain(self,file,separator,encryption,vcs): #{{{ + # write passwordfile + def exportPasswordsPlain(self): #{{{ + vcs = self.vcs + encryption = self.encryption + + file = self.file + separator = self.separator + + if (encryption == "GnuPG"): fobj = GPGFile() fobj.open(file,"w",self.recipients) @@ -350,50 +391,5 @@ # }}} -class config(object): # {{{ - - def __init__(self,file): # {{{ - - file = os.path.expanduser(file) - - c = ConfigParser.RawConfigParser() - - if os.access(file,os.F_OK): - c.read(file) - else: - c.add_section('Main') - c.set('Main','file','~/.spd/spd_data.gpg') - c.set('Main','passwordField','Password') - c.set('Main','encryption','GnuPG') - c.set('Main','vcs','none') - - c.add_section('Users') - c.set('Users', 'User1', "Klaus Umbach") - c.set('Users', 'User2', "Klaus Windows") - - c.add_section('Colors') - c.set('Colors','passwordFG','brightblue') - c.set('Colors','passwordBG','blue') - configfile = open(file, 'wb') - c.write(configfile) - - # set the configuration variables - self.file = os.path.expanduser(c.get('Main','file')) - self.encryption = c.get('Main','encryption') - - self.vcs = c.get('Main','vcs') - - - self.users=[] - for i in c.items('Users'): - self.users.append(i[1]) - - - # }}} - - - -# }}} - # EOF # vim:foldmethod=marker:tabstop=3:autoindent This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2009-09-06 21:03:09
|
Revision: 270 http://spd.svn.sourceforge.net/spd/?rev=270&view=rev Author: treibholz Date: 2009-09-06 21:02:57 +0000 (Sun, 06 Sep 2009) Log Message: ----------- * internal database now has a primary key (__ID) (not used for anything yet) * code cleanup * fixed a bug when deleting an entry Modified Paths: -------------- trunk/src/spd trunk/src/spdCLI.py trunk/src/spdCore.py Modified: trunk/src/spd =================================================================== --- trunk/src/spd 2009-09-06 15:35:32 UTC (rev 269) +++ trunk/src/spd 2009-09-06 21:02:57 UTC (rev 270) @@ -58,13 +58,14 @@ if options.add: pc.addEntry(interface.newEntry(pc.getCollumns())) - pc.recipients = config.users pc.dumpSQLite() pc.exportPasswordsPlain() elif options.delete: - pc.delEntry(options.delete) - pc.recipients = config.users + searchPatterns = sys.argv + del searchPatterns[0] + del searchPatterns[0] + pc.delEntry(searchPatterns) pc.dumpSQLite() pc.exportPasswordsPlain() @@ -81,4 +82,4 @@ # EOF -# vim:foldmethod=marker:tabstop=3:autoindent +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2009-09-06 15:35:32 UTC (rev 269) +++ trunk/src/spdCLI.py 2009-09-06 21:02:57 UTC (rev 270) @@ -109,38 +109,6 @@ return entry # }}} -def main(clientoptions, config, pc): - interface = cli() - - # check if it is a search or not. - - if clientoptions.add: - pc.importPasswordsPlain(config.file,"\t",config.encryption,config.vcs) - pc.fillSQLite() - pc.flushPasswordsPlain() - pc.addEntry(interface.newEntry(pc.getCollumns())) - pc.recipients = config.users - pc.dumpSQLite() - pc.exportPasswordsPlain(config.file,"\t",config.encryption,config.vcs) - - elif clientoptions.delete: - pc.importPasswordsPlain(config.file,"\t",config.encryption,config.vcs) - pc.fillSQLite() - pc.flushPasswordsPlain() - pc.delEntry(clientoptions.delete) - pc.recipients = config.users - pc.dumpSQLite() - pc.exportPasswordsPlain(config.file,"\t",config.encryption,config.vcs) - - else: - pc.importPasswordsPlain(config.file,"\t",config.encryption,config.vcs) - pc.fillSQLite() - pc.flushPasswordsPlain() - searchPatterns = sys.argv - del searchPatterns[0] - interface.listOutput(pc.findPassword(searchPatterns)) - - # EOF -# vim:foldmethod=marker:tabstop=3:autoindent +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-06 15:35:32 UTC (rev 269) +++ trunk/src/spdCore.py 2009-09-06 21:02:57 UTC (rev 270) @@ -47,9 +47,13 @@ # creates an internal memory-based SQLite database and declares a # a the self.__table dictionary # file: string, the config-file - def __init__(self,file): #{{{ + def __init__(self,file,debug=0): #{{{ - self.__sql = sqlite3.connect(":memory:") + if not debug: + self.__sql = sqlite3.connect(":memory:") + else: + self.__sql = sqlite3.connect("/tmp/spd_debug.db") + self.__table = {} # read the config @@ -167,7 +171,7 @@ if (encryption == "GnuPG"): fobj = GPGFile() - fobj.open(file,"w",self.recipients) + fobj.open(file,"w",self.users) else: fobj = open(file,"w") @@ -207,30 +211,35 @@ cursor = self.__sql.cursor() count = 0 - # cursor.execute("IF EXISTS DROP TABLE passwords") - query = "CREATE TABLE passwords (" - insertStatement = "INSERT into passwords VALUES ( " + query = "CREATE TABLE passwords ( __ID INTEGER PRIMARY KEY," + self.__insertStatement = "INSERT into passwords ( " + insertValues = "" for collumns in self.__table: # first create the table count += 1 query += collumns + " TEXT" - insertStatement += ":" + collumns + insertValues += ":" + collumns + self.__insertStatement += collumns if (count == len(self.__table)): # write ) if last collumn query += ")" - insertStatement += ")" + self.__insertStatement += ")" + insertValues += ")" else: # otherwise write a , query += ", " - insertStatement += ", " + self.__insertStatement += ", " + insertValues += ", " cursor.execute(query) - + + self.__insertStatement += ' VALUES (' + insertValues + for i in range(0,len(self.__table[collumns])): values = {} for collumns in self.__table: values[collumns] = self.__table[collumns][i] try: - cursor.execute(insertStatement, values) + cursor.execute(self.__insertStatement, values) except sqlite3.OperationalError: #DEBUG print values @@ -253,17 +262,14 @@ # create the query count = 0 - query = "select * from passwords where (" - - for filter in patterns: - for collumns in self.__table: - if (collumns != self.passwordField): - query += collumns + " like '%" + filter + "%' or " - count += 1 - - query = re.sub(r'or $',') and (',query) # delete the last - query = re.sub(r'\) and \($',')',query) # delet the last + searchCollumns = '' + for i in self.__table: + searchCollumns += i + ',' + searchCollumns = re.sub(r',$','',searchCollumns) + + query = "select " + searchCollumns + " from passwords where " + self.__buildWhere(patterns) + cursor.execute(query) # convert the result in a Dictionary @@ -284,28 +290,12 @@ self.__table[collumns] = [] #}}} - # defines the receipients for encryption - # recipients: list of strings - def setRecipients(self,recipients): # {{{ - self.recipients = recipients - # }}} - # add a new entry # entry: dictionary like self.__table def addEntry(self, entry): # {{{ cursor = self.__sql.cursor() - insertStatement = "INSERT into passwords VALUES ( " count = 0 - for i in entry: - count += 1 - insertStatement += ":" + i - if (count != len(entry)): - insertStatement += ", " - else: - insertStatement +=')' - - #print insertStatement - cursor.execute(insertStatement, entry) + cursor.execute(self.__insertStatement, entry) self.__sql.commit() del entry @@ -315,11 +305,17 @@ # patterns: list of strings def delEntry(self,patterns): #{{{ cursor = self.__sql.cursor() - + # create the query - count = 0 - query = "delete from passwords where (" + query = "delete from passwords where " + self.__buildWhere(patterns) + cursor.execute(query) + #}}} + + # internal to build the WHERE + def __buildWhere(self,patterns): # {{{ + count = 0 + query = '(' for filter in patterns: for collumns in self.__table: if (collumns != self.passwordField): @@ -329,10 +325,9 @@ query = re.sub(r'or $',') and (',query) # delete the last query = re.sub(r'\) and \($',')',query) # delet the last - cursor.execute(query) - - #}}} - + return query + #}}} + # return a list of used collumns def getCollumns(self): # {{{ return self.__table.keys() @@ -392,4 +387,4 @@ # }}} # EOF -# vim:foldmethod=marker:tabstop=3:autoindent +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2009-09-06 22:22:40
|
Revision: 271 http://spd.svn.sourceforge.net/spd/?rev=271&view=rev Author: treibholz Date: 2009-09-06 21:20:39 +0000 (Sun, 06 Sep 2009) Log Message: ----------- simplified the API a little bit creating the PasswordContainer now automatically calls importPasswordsPlain, fillSQLite and flushPasswordsPlain (if you don't set autoload=False) also exportPasswordsPlain now calls dumpSQL alone (if you don't set autoload=False) Modified Paths: -------------- trunk/src/spd trunk/src/spdCore.py Modified: trunk/src/spd =================================================================== --- trunk/src/spd 2009-09-06 21:02:57 UTC (rev 270) +++ trunk/src/spd 2009-09-06 21:20:39 UTC (rev 271) @@ -48,9 +48,6 @@ # }}} pc = spdCore.PasswordContainer('~/.spd/config') -pc.importPasswordsPlain() -pc.fillSQLite() -pc.flushPasswordsPlain() interface = spdCLI.cli() @@ -58,7 +55,6 @@ if options.add: pc.addEntry(interface.newEntry(pc.getCollumns())) - pc.dumpSQLite() pc.exportPasswordsPlain() elif options.delete: @@ -66,16 +62,15 @@ del searchPatterns[0] del searchPatterns[0] pc.delEntry(searchPatterns) - pc.dumpSQLite() pc.exportPasswordsPlain() elif options.pwonly: searchPatterns = sys.argv del searchPatterns[0] del searchPatterns[0] - print pc.findPassword(searchPatterns)['Password'][0] + print pc.findPassword(searchPatterns)[pc.passwordField][0] -else: +else: # regular search searchPatterns = sys.argv del searchPatterns[0] interface.listOutput(pc.findPassword(searchPatterns)) Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-06 21:02:57 UTC (rev 270) +++ trunk/src/spdCore.py 2009-09-06 21:20:39 UTC (rev 271) @@ -43,11 +43,13 @@ class PasswordContainer(object): # {{{ - # The Constructor - # creates an internal memory-based SQLite database and declares a - # a the self.__table dictionary - # file: string, the config-file - def __init__(self,file,debug=0): #{{{ + '''The Constructor + creates an internal memory-based SQLite database and declares a + a the self.__table dictionary + file: string, the config-file + debug: if set to true, the database /tmp/spd_debug.db + autoload: if set to False, the data is not loaded automatically''' + def __init__(self,file,debug=False,autoload=True): #{{{ if not debug: self.__sql = sqlite3.connect(":memory:") @@ -92,6 +94,11 @@ self.users=[] for i in c.items('Users'): self.users.append(i[1]) + + if autoload: + self.importPasswordsPlain() + self.fillSQLite() + self.flushPasswordsPlain() @@ -161,7 +168,10 @@ #}}} # write passwordfile - def exportPasswordsPlain(self): #{{{ + def exportPasswordsPlain(self,autoload=True): #{{{ + if autoload: + self.dumpSQLite() + vcs = self.vcs encryption = self.encryption This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2009-09-07 18:43:27
|
Revision: 272 http://spd.svn.sourceforge.net/spd/?rev=272&view=rev Author: treibholz Date: 2009-09-07 18:43:16 +0000 (Mon, 07 Sep 2009) Log Message: ----------- extended the API a little bit for IDs, so editing and specific deletion will be possible. TODO: spdCLI needs to sort its output now. Modified Paths: -------------- trunk/src/spdCLI.py trunk/src/spdCore.py Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2009-09-06 21:20:39 UTC (rev 271) +++ trunk/src/spdCLI.py 2009-09-07 18:43:16 UTC (rev 272) @@ -86,7 +86,7 @@ output += table[j][i] output += self.colorReset else: - output += table[j][i] + output += str(table[j][i]) print output print "" Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-06 21:20:39 UTC (rev 271) +++ trunk/src/spdCore.py 2009-09-07 18:43:16 UTC (rev 272) @@ -261,30 +261,40 @@ # dump SQLite in self.__table def dumpSQLite(self): #{{{ # quite easy, eh? :-) - self.__table = self.findPassword("%") + self.__table = self.findPassword("%",output='noID') #}}} # find a password in SQLite # patterns: list of strings (filter) - def findPassword(self,patterns): #{{{ + def findPassword(self,patterns,output='table'): #{{{ cursor = self.__sql.cursor() # create the query count = 0 searchCollumns = '' - for i in self.__table: - searchCollumns += i + ',' + if (output == 'id'): + searchCollumns = '__ID' + result = { "ID" : []} - searchCollumns = re.sub(r',$','',searchCollumns) + else: + result = {} + + if (output != "noID" ): + result.update({'__ID' : [] }) + result.update(self.__table) + + for i in result: + searchCollumns += i + ',' + + searchCollumns = re.sub(r',$','',searchCollumns) + query = "select " + searchCollumns + " from passwords where " + self.__buildWhere(patterns) - cursor.execute(query) # convert the result in a Dictionary # this looks a little bit unelegant.... FIXME - result = self.__table # make a copy for row in cursor: count = 0 for i in row: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2009-09-08 20:42:44
|
Revision: 273 http://spd.svn.sourceforge.net/spd/?rev=273&view=rev Author: Z3po Date: 2009-09-08 20:42:34 +0000 (Tue, 08 Sep 2009) Log Message: ----------- added possibility to not give any keywords (backwards compatible?) Modified Paths: -------------- trunk/src/spdCLI.py trunk/src/spdCore.py Added Paths: ----------- trunk/src/spd-cli Removed Paths: ------------- trunk/src/spd Deleted: trunk/src/spd =================================================================== --- trunk/src/spd 2009-09-07 18:43:16 UTC (rev 272) +++ trunk/src/spd 2009-09-08 20:42:34 UTC (rev 273) @@ -1,80 +0,0 @@ -#!/usr/bin/python -# Copyright (C) 2009 Klaus Umbach {{{ -# <tre...@us...> -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# }}} - -import sys -import spdCore -import spdCLI -from optparse import OptionParser - -# {{{ OptionParser stuff -parser = OptionParser( "%prog [Optionen] Search", - description = "SPD - Simple Password Displayer", - version = "0.3-alpha", - epilog = "With no parameters it will print out nothing!") - -parser.add_option( "-d", "--delete", - dest ="delete", - help ="Entry to delete") - -parser.add_option( "-a", "--add", - action="store_true", - dest = "add", - default=False, - help = "Add an Entry") - -parser.add_option( "-p", "--password-only", - dest = "pwonly", - help = "print Password only of first match, usefull for piping (e.g. in rdesktop)") - - - -(options, args) = parser.parse_args() -# }}} - -pc = spdCore.PasswordContainer('~/.spd/config') - -interface = spdCLI.cli() - -# check if it is a search or not. - -if options.add: - pc.addEntry(interface.newEntry(pc.getCollumns())) - pc.exportPasswordsPlain() - -elif options.delete: - searchPatterns = sys.argv - del searchPatterns[0] - del searchPatterns[0] - pc.delEntry(searchPatterns) - pc.exportPasswordsPlain() - -elif options.pwonly: - searchPatterns = sys.argv - del searchPatterns[0] - del searchPatterns[0] - print pc.findPassword(searchPatterns)[pc.passwordField][0] - -else: # regular search - searchPatterns = sys.argv - del searchPatterns[0] - interface.listOutput(pc.findPassword(searchPatterns)) - - -# EOF -# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Copied: trunk/src/spd-cli (from rev 272, trunk/src/spd) =================================================================== --- trunk/src/spd-cli (rev 0) +++ trunk/src/spd-cli 2009-09-08 20:42:34 UTC (rev 273) @@ -0,0 +1,94 @@ +#!/usr/bin/python +# Copyright (C) 2009 Klaus Umbach {{{ +# <tre...@us...> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# }}} + +import sys +import spdCore +import spdCLI +from optparse import OptionParser + +# {{{ OptionParser stuff +parser = OptionParser( "%prog [Optionen] Search", + description = "SPD - Simple Password Displayer", + version = "0.3-alpha", + epilog = "With no parameters it will print out nothing!") + +parser.add_option( "-d", "--delete", + dest ="delete", + help ="Entry to delete") + +parser.add_option( "-a", "--add", + action="store_true", + dest = "add", + default=False, + help = "Add an Entry") + +parser.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( "-w", "--wide", +# action="store_true", +# dest = "widemode", +# default=False, +# help = "print output in wide mode (means as a table)") + + + +(options, args) = parser.parse_args() +# }}} + +pc = spdCore.PasswordContainer('~/.spd/config') + +interface = spdCLI.cli() + +# check if it is a search or not. + +if options.add: + pc.addEntry(interface.newEntry(pc.getCollumns())) + pc.exportPasswordsPlain() + +elif options.delete: + searchPatterns = sys.argv + del searchPatterns[0] + del searchPatterns[0] + pc.delEntry(searchPatterns) + pc.exportPasswordsPlain() + +elif options.pwonly: + searchPatterns = sys.argv + del searchPatterns[0] + del searchPatterns[0] + print pc.findPassword(searchPatterns)[pc.passwordField][0] + +#elif options.widemode: +# searchPatterns = sys.argv +# del searchPatterns[0] +# interface.tableOutput(pc.findPassword(searchPatterns)) + + +else: # regular search + searchPatterns = sys.argv + del searchPatterns[0] + interface.listOutput(pc.findPassword(searchPatterns)) + + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2009-09-07 18:43:16 UTC (rev 272) +++ trunk/src/spdCLI.py 2009-09-08 20:42:34 UTC (rev 273) @@ -1,29 +1,6 @@ import sys import platform -from optparse import OptionParser -# {{{ OptionParser stuff -def CreateParser(): - - parser = OptionParser( "%prog [Optionen] Search", - description = "SPD - Simple Password Displayer", - version = "0.3-alpha", - epilog = "With no parameters it will print out nothing!") - - parser.add_option( "-d", "--delete", - dest ="delete", - help ="Entry to delete") - - parser.add_option( "-a", "--add", - action="store_true", - dest = "add", - default=False, - help = "Add an Entry") - - return parser -# }}} - - class cli(object): def __init__(self): # {{{ Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-07 18:43:16 UTC (rev 272) +++ trunk/src/spdCore.py 2009-09-08 20:42:34 UTC (rev 273) @@ -149,7 +149,7 @@ for j in collumns: try: self.__table[j].append(line[collumnCount]) - + except IndexError: # Debug print j print collumnCount @@ -269,6 +269,9 @@ # patterns: list of strings (filter) def findPassword(self,patterns,output='table'): #{{{ cursor = self.__sql.cursor() + + if not patterns: + patterns='%' # create the query count = 0 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2009-09-09 07:23:26
|
Revision: 274 http://spd.svn.sourceforge.net/spd/?rev=274&view=rev Author: treibholz Date: 2009-09-09 07:23:13 +0000 (Wed, 09 Sep 2009) Log Message: ----------- fixed a unicode-bug Modified Paths: -------------- trunk/src/spdCLI.py trunk/src/spdCore.py Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2009-09-08 20:42:34 UTC (rev 273) +++ trunk/src/spdCLI.py 2009-09-09 07:23:13 UTC (rev 274) @@ -1,3 +1,4 @@ +# -*- coding: UTF-8 -*- import sys import platform @@ -62,8 +63,8 @@ output += self.colorFG[self.config["passwordFG"]] + self.colorBG[self.config["passwordBG"]] output += table[j][i] output += self.colorReset - else: - output += str(table[j][i]) + else: + output += unicode(table[j][i]) print output print "" Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-08 20:42:34 UTC (rev 273) +++ trunk/src/spdCore.py 2009-09-09 07:23:13 UTC (rev 274) @@ -1,3 +1,4 @@ +# -*- coding: UTF-8 -*- ''' Copyright (C) 2009 Klaus Umbach {{{ <tre...@us...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2009-09-13 17:27:58
|
Revision: 282 http://spd.svn.sourceforge.net/spd/?rev=282&view=rev Author: treibholz Date: 2009-09-13 17:27:49 +0000 (Sun, 13 Sep 2009) Log Message: ----------- implemented the feature, to change the symlink to the political party you like, and SPD changes it's names. Not all parties are implemented yet... Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCore.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2009-09-09 13:10:16 UTC (rev 281) +++ trunk/src/spd-cli 2009-09-13 17:27:49 UTC (rev 282) @@ -24,9 +24,11 @@ import spdCLI from optparse import OptionParser +pp = spdCore.name(sys.argv[0]) + # {{{ OptionParser stuff -parser = OptionParser( "%prog [Optionen] Search", - description = "SPD - Simple Password Displayer", +parser = OptionParser( "%prog [Options] Search", + description = pp.acronym + ' - ' + pp.name, version = "0.3-alpha", epilog = "With no parameters it will print out nothing!") Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2009-09-09 13:10:16 UTC (rev 281) +++ trunk/src/spdCore.py 2009-09-13 17:27:49 UTC (rev 282) @@ -414,5 +414,30 @@ # }}} +class name(object): # {{{ + def __init__(self,acronym): + list = { 'spd' : 'Simple Password Displayer', + 'npd' : 'No Password Displayer', + 'piraten' : 'Professional Inspired Random Accessory To Ensure Nobodycanseeyourpasswords', + 'cdu' : 'Cryptical Data Unit', + 'fdp' : 'Fast Display Password', + 'pbc' : 'Passwords Brotected by Cheesus', + 'mlpd' : 'Mean, Lean Password Displayer', + 'rep' : 'Racists Encrypt their Passwords', + 'dvu' : 'Digital Viewing Unit', + 'grüne' : 'Generic Reasonable ÜberNext Encryption', + 'linke' : 'no idea...', + } + + acronym = re.split('/',acronym)[len(re.split('/',acronym))-1] + + # default to spd + if acronym not in list: + acronym = "spd" + + self.acronym = acronym.upper() + self.name = list[acronym] +# }}} + # EOF # vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2009-11-28 11:04:04
|
Revision: 286 http://spd.svn.sourceforge.net/spd/?rev=286&view=rev Author: Z3po Date: 2009-11-28 11:03:52 +0000 (Sat, 28 Nov 2009) Log Message: ----------- added widemode output and changed some of help information Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCLI.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2009-10-04 07:23:59 UTC (rev 285) +++ trunk/src/spd-cli 2009-11-28 11:03:52 UTC (rev 286) @@ -24,13 +24,15 @@ import spdCLI from optparse import OptionParser +version = "0.3-alpha" + pp = spdCore.name(sys.argv[0]) # {{{ OptionParser stuff parser = OptionParser( "%prog [Options] Search", description = pp.acronym + ' - ' + pp.name, - version = "0.3-alpha", - epilog = "With no parameters it will print out nothing!") + version = version, + epilog = "With no parameters it will print out everything!") parser.add_option( "-d", "--delete", metavar="Keyword", @@ -55,11 +57,11 @@ default=False, help = "print Password only of first match, usefull for piping (e.g. in rdesktop)") -#parser.add_option( "-w", "--wide", -# action="store_true", -# dest = "widemode", -# default=False, -# help = "print output in wide mode (means as a table)") +parser.add_option( "-w", "--wide", + action="store_true", + dest = "widemode", + default=False, + help = "print output in wide mode (means as a table)") @@ -97,10 +99,11 @@ except: pass -#elif options.widemode: -# searchPatterns = sys.argv -# del searchPatterns[0] -# interface.tableOutput(pc.findPassword(searchPatterns)) +elif options.widemode: + searchPatterns = sys.argv + del searchPatterns[0] + del searchPatterns[0] + interface.tableOutput(pc.findPassword(searchPatterns)) else: # regular search Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2009-10-04 07:23:59 UTC (rev 285) +++ trunk/src/spdCLI.py 2009-11-28 11:03:52 UTC (rev 286) @@ -23,28 +23,73 @@ # }}} def tableOutput(self,table): # {{{ - hits = len(table['Password']) # Password always exists :-) - length = {} + collumns = len(table) + entries = len(table.values()[0]) + maxlength = {} header = "|" - for i in table: - if (len(max(table[i])) > len(i)): - length[i] = len(max(table[i])) - else: - length[i] = len(i) - - header += i.ljust(length[i]) + "|" + # Ride through all columns and find the maximal length a line can have + for i in range(0,collumns): + maxlength[i] = 0 + # First for the keys + if ( maxlength[i] < len(table.keys()[i]) ): + maxlength[i] = len(table.keys()[i]) + # Secondary for the values + for j in table.values()[i]: + if ( table.keys()[i] == "__ID" ): + j = str(j) + try: + if ( maxlength[i] < len(j)): + maxlength[i] = len(j) + except Exception, e: + print e - print header + # Now Print the Entries in WIDE mode :) + output = "| " + table.keys()[0].ljust(maxlength[0]) + for i in range(1,collumns): + output = output + " | " + table.keys()[i].ljust(maxlength[i]) - for i in range(0,hits): - result = "|" - for j in table: - result += table[j][i].ljust(length[j]) + "|" - print result + print output - # }}} + if ( table.keys()[0] == self.config['passwordField'] ): + output = "| " + self.colorFG[self.config["passwordFG"]] + self.colorBG[self.config["passwordBG"]] + output = table.values()[0][0].ljust(maxlength[0]) + output = self.colorReset + " | " + else: + output = "| " + table.values()[0][0].ljust(maxlength[0]) + " | " + for i in range(1,collumns): + if ( table.keys()[i] == "__ID" ): + table.values()[i][0] = str(table.values()[i][0]) + if ( table.keys()[i] == self.config['passwordField'] ): + output += self.colorFG[self.config["passwordFG"]] + self.colorBG[self.config["passwordBG"]] + output += table.values()[i][0].ljust(maxlength[i]) + output += self.colorReset + " | " + else: + output += table.values()[i][0].ljust(maxlength[i]) + " | " + + print output + + for j in range(1,entries): + if ( table.keys()[0] == self.config['passwordField'] ): + output = "| " + self.colorFG[self.config["passwordFG"]] + self.colorBG[self.config["passwordBG"]] + output = table.values()[0][j].ljust(maxlength[0]) + output = self.colorReset + " | " + else: + output = "| " + table.values()[0][j].ljust(maxlength[0]) + " | " + + for i in range(1,collumns): + if ( table.keys()[i] == "__ID" ): + table.values()[i][j] = str(table.values()[i][j]) + if ( table.keys()[i] == self.config['passwordField'] ): + output += self.colorFG[self.config["passwordFG"]] + self.colorBG[self.config["passwordBG"]] + output += table.values()[i][j].ljust(maxlength[i]) + output += self.colorReset + " | " + else: + output += table.values()[i][j].ljust(maxlength[i]) + " | " + print output + + def listOutput(self,table): # {{{ hits = len(table.values()[0]) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2010-05-26 12:01:49
|
Revision: 290 http://spd.svn.sourceforge.net/spd/?rev=290&view=rev Author: treibholz Date: 2010-05-26 12:01:43 +0000 (Wed, 26 May 2010) Log Message: ----------- Quick&Dirty fix to use colors from the config Modified Paths: -------------- trunk/src/spdCLI.py trunk/src/spdCore.py Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2010-05-25 17:01:30 UTC (rev 289) +++ trunk/src/spdCLI.py 2010-05-26 12:01:43 UTC (rev 290) @@ -1,6 +1,7 @@ # -*- coding: UTF-8 -*- import sys import platform +import spdCore class cli(object): @@ -17,12 +18,14 @@ return k def __init__(self): # {{{ - self.config = { "passwordField" : "Password", - "passwordFG" : "brightblue", - "passwordBG" : "blue", + FooBar = spdCore.PasswordContainer('.spd/config') + self.config = { "passwordField" : FooBar.passwordField, + "passwordFG" : FooBar.passwordFG, + "passwordBG" : FooBar.passwordBG, "listSeparator" : ":", } + # This has to be somehow simpler... self.colorFG = { "red" : '\033[31m', "blue": '\033[34m', "brightblue": '\033[1;34m' Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2010-05-25 17:01:30 UTC (rev 289) +++ trunk/src/spdCore.py 2010-05-26 12:01:43 UTC (rev 290) @@ -89,6 +89,9 @@ self.passwordField = c.get('Main', 'passwordField') self.separator = '\t' + self.passwordFG = c.get('Colors', 'passwordFG') + self.passwordBG = c.get('Colors', 'passwordBG') + self.vcs = c.get('Main','vcs') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2010-05-27 16:20:22
|
Revision: 291 http://spd.svn.sourceforge.net/spd/?rev=291&view=rev Author: treibholz Date: 2010-05-27 16:20:14 +0000 (Thu, 27 May 2010) Log Message: ----------- Hotfix * Bug with double decrypt * removed embarassing FooBar Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCLI.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2010-05-26 12:01:43 UTC (rev 290) +++ trunk/src/spd-cli 2010-05-27 16:20:14 UTC (rev 291) @@ -25,6 +25,7 @@ from optparse import OptionParser version = "0.3-alpha" +ConfigFile = '~/.spd/config' pp = spdCore.name(sys.argv[0]) @@ -68,9 +69,9 @@ (options, args) = parser.parse_args() # }}} -pc = spdCore.PasswordContainer('~/.spd/config') +pc = spdCore.PasswordContainer(ConfigFile) -interface = spdCLI.cli() +interface = spdCLI.cli(ConfigFile) # check if it is a search or not. Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2010-05-26 12:01:43 UTC (rev 290) +++ trunk/src/spdCLI.py 2010-05-27 16:20:14 UTC (rev 291) @@ -1,7 +1,8 @@ # -*- coding: UTF-8 -*- import sys +import os import platform -import spdCore +from ConfigParser import RawConfigParser class cli(object): @@ -17,11 +18,18 @@ # print k.keys() return k - def __init__(self): # {{{ - FooBar = spdCore.PasswordContainer('.spd/config') - self.config = { "passwordField" : FooBar.passwordField, - "passwordFG" : FooBar.passwordFG, - "passwordBG" : FooBar.passwordBG, + def __init__(self,ConfigFile): # {{{ + ConfigFile = os.path.expanduser(ConfigFile) + + Config = RawConfigParser() + if os.access(ConfigFile,os.F_OK): + Config.read(ConfigFile) + else: + print "HELP" + + self.config = { "passwordField" : Config.get('Main','passwordField'), + "passwordFG" : Config.get('Colors','passwordFG'), + "passwordBG" : Config.get('Colors','passwordBG'), "listSeparator" : ":", } @@ -35,6 +43,7 @@ } self.colorReset = '\033[0m' + # }}} def tableOutput(self,table): # {{{ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2010-06-23 14:22:35
|
Revision: 292 http://spd.svn.sourceforge.net/spd/?rev=292&view=rev Author: treibholz Date: 2010-06-23 14:22:29 +0000 (Wed, 23 Jun 2010) Log Message: ----------- added --local option Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCore.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2010-05-27 16:20:14 UTC (rev 291) +++ trunk/src/spd-cli 2010-06-23 14:22:29 UTC (rev 292) @@ -64,12 +64,18 @@ default=False, help = "print output in wide mode (means as a table)") +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") + (options, args) = parser.parse_args() # }}} -pc = spdCore.PasswordContainer(ConfigFile) +pc = spdCore.PasswordContainer(ConfigFile,options.localStore) interface = spdCLI.cli(ConfigFile) Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2010-05-27 16:20:14 UTC (rev 291) +++ trunk/src/spdCore.py 2010-06-23 14:22:29 UTC (rev 292) @@ -50,7 +50,7 @@ debug: if set to true, the database is /tmp/spd_debug.db autoload: if set to False, the data is not loaded automatically""" - def __init__(self,file,debug=False,autoload=True): #{{{ + def __init__(self,file,localStore=False,debug=False,autoload=True): #{{{ if not debug: self.__sql = sqlite3.connect(":memory:") @@ -92,7 +92,10 @@ self.passwordFG = c.get('Colors', 'passwordFG') self.passwordBG = c.get('Colors', 'passwordBG') - self.vcs = c.get('Main','vcs') + if localStore: + self.vcs = 'none' + else: + self.vcs = c.get('Main','vcs') self.users=[] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-06-27 10:17:11
|
Revision: 294 http://spd.svn.sourceforge.net/spd/?rev=294&view=rev Author: Z3po Date: 2010-06-27 10:17:05 +0000 (Sun, 27 Jun 2010) Log Message: ----------- fixed some bugs in spd-cli and added --passfile functionality to use any file as passwordfile (maybe to use in conjunction with --local if a Store is configured?) Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCore.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2010-06-23 14:41:34 UTC (rev 293) +++ trunk/src/spd-cli 2010-06-27 10:17:05 UTC (rev 294) @@ -70,12 +70,17 @@ 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") + + (options, args) = parser.parse_args() # }}} -pc = spdCore.PasswordContainer(ConfigFile,options.localStore) +pc = spdCore.PasswordContainer(ConfigFile,options.localStore,options.passfile) interface = spdCLI.cli(ConfigFile) @@ -86,19 +91,17 @@ pc.exportPasswordsPlain() elif options.delete: - searchPatterns = sys.argv + searchPatterns = args del searchPatterns[0] del searchPatterns[0] pc.delEntry(searchPatterns) pc.exportPasswordsPlain() elif options.deleteID: - id = int(sys.argv[2]) + id = options.deleteID pc.delEntry('nix', id=id) pc.exportPasswordsPlain() - - elif options.pwonly: searchPatterns = args try: @@ -107,15 +110,13 @@ pass elif options.widemode: - searchPatterns = sys.argv - del searchPatterns[0] - del searchPatterns[0] + searchPatterns = args interface.tableOutput(pc.findPassword(searchPatterns)) else: # regular search - searchPatterns = sys.argv - del searchPatterns[0] + searchPatterns = args + print str(searchPatterns) + "\n\n" if options.localStore: try: del searchPatterns[searchPatterns.index('-l')] Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2010-06-23 14:41:34 UTC (rev 293) +++ trunk/src/spdCore.py 2010-06-27 10:17:05 UTC (rev 294) @@ -50,7 +50,7 @@ debug: if set to true, the database is /tmp/spd_debug.db autoload: if set to False, the data is not loaded automatically""" - def __init__(self,file,localStore=False,debug=False,autoload=True): #{{{ + def __init__(self,file,localStore=False,passfile=False,debug=False,autoload=True): #{{{ if not debug: self.__sql = sqlite3.connect(":memory:") @@ -84,7 +84,10 @@ # }}} # set the configuration variables - self.file = os.path.expanduser(c.get('Main','file')) + if not passfile: + self.file = os.path.expanduser(c.get('Main','file')) + else: + self.file = passfile self.encryption = c.get('Main','encryption') self.passwordField = c.get('Main', 'passwordField') self.separator = '\t' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-06-27 11:51:54
|
Revision: 295 http://spd.svn.sourceforge.net/spd/?rev=295&view=rev Author: Z3po Date: 2010-06-27 11:51:48 +0000 (Sun, 27 Jun 2010) Log Message: ----------- added functionality to add key (collumn) to passfile Modified Paths: -------------- trunk/src/spd-cli trunk/src/spdCore.py Modified: trunk/src/spd-cli =================================================================== --- trunk/src/spd-cli 2010-06-27 10:17:05 UTC (rev 294) +++ trunk/src/spd-cli 2010-06-27 11:51:48 UTC (rev 295) @@ -52,6 +52,13 @@ default=False, help = "Add an Entry") +parser.add_option( "--add-key", + metavar="Keyword", + dest = "addkey", + default=False, + help = "Add a Keyword") + + parser.add_option( "-p", "--password-only", action="store_true", dest = "pwonly", @@ -74,9 +81,6 @@ dest = "passfile", help = "do not use the confgured passfile but the one given here") - - - (options, args) = parser.parse_args() # }}} @@ -90,6 +94,10 @@ pc.addEntry(interface.newEntry(pc.getCollumns())) pc.exportPasswordsPlain() +elif options.addkey: + pc.addCollumn(options.addkey) + pc.exportPasswordsPlain() + elif options.delete: searchPatterns = args del searchPatterns[0] @@ -116,7 +124,6 @@ else: # regular search searchPatterns = args - print str(searchPatterns) + "\n\n" if options.localStore: try: del searchPatterns[searchPatterns.index('-l')] Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2010-06-27 10:17:05 UTC (rev 294) +++ trunk/src/spdCore.py 2010-06-27 11:51:48 UTC (rev 295) @@ -209,7 +209,10 @@ count=0 for collumns in self.__table: # now we are writing the data count += 1 - fobj.write(self.__table[collumns][i]) # <- here + if not self.__table[collumns][1]: + fobj.write('') # <- here + else: + fobj.write(self.__table[collumns][i]) # <- and here if (count == len(self.__table)): # write \n if last collumn fobj.write('\n') else: # otherwise write the separator @@ -259,9 +262,15 @@ def dumpSQLite(self): #{{{ """dump SQLite in self.__table""" + # First get Collumns of SQL Database...maybe they are changed + cursor = self.__sql.cursor() + cursor.execute("PRAGMA TABLE_INFO(passwords)") + for row in cursor: + if row[1] != "__ID": + self.__table[str(row[1])] = [] + # quite easy, eh? :-) self.__table = self.findPassword("%",output='noID') - #}}} def findPassword(self,patterns,output='table'): #{{{ @@ -374,7 +383,7 @@ """add a collumn to passfile name: name of new collumn""" cursor = self.__sql.cursor() - + query = "ALTER TABLE passwords ADD `" + name + "` TEXT" cursor.execute(query) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <Z3...@us...> - 2010-09-04 21:52:50
|
Revision: 298 http://spd.svn.sourceforge.net/spd/?rev=298&view=rev Author: Z3po Date: 2010-09-04 21:52:44 +0000 (Sat, 04 Sep 2010) Log Message: ----------- fixed bugs in --add 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-28 11:33:34 UTC (rev 297) +++ trunk/src/spd-cli 2010-09-04 21:52:44 UTC (rev 298) @@ -43,7 +43,7 @@ parser.add_option( "-e", "--edit", metavar="ID", dest ="edit", - help ="Entry to edit") + help ="ID to edit") parser.add_option( "-i", "--delete-id", metavar="ID", @@ -52,9 +52,8 @@ parser.add_option( "--id", dest ="id", - help ="Search Password by ID") + help ="Show Password by ID") - parser.add_option( "-a", "--add", action="store_true", dest = "add", @@ -102,7 +101,7 @@ pc.addEntry(interface.newEntry(pc.getCollumns())) pc.exportPasswordsPlain() -if options.edit: +elif options.edit: updates = interface.editEntry(pc.findPassword(options.edit,id=True)) pc.updateEntry(updates) pc.exportPasswordsPlain() Modified: trunk/src/spdCLI.py =================================================================== --- trunk/src/spdCLI.py 2010-06-28 11:33:34 UTC (rev 297) +++ trunk/src/spdCLI.py 2010-09-04 21:52:44 UTC (rev 298) @@ -161,7 +161,6 @@ return table # }}} - def setConfig(self,var,value): # {{{ self.config[var] = value # }}} @@ -174,7 +173,6 @@ entry = {} for i in collumns: entry[i] = raw_input(i + ': ') - return entry # }}} Modified: trunk/src/spdCore.py =================================================================== --- trunk/src/spdCore.py 2010-06-28 11:33:34 UTC (rev 297) +++ trunk/src/spdCore.py 2010-09-04 21:52:44 UTC (rev 298) @@ -209,7 +209,7 @@ count=0 for collumns in self.__table: # now we are writing the data count += 1 - if not self.__table[collumns][1]: + if not self.__table[collumns][i]: fobj.write('') # <- here else: fobj.write(self.__table[collumns][i]) # <- and here @@ -289,7 +289,6 @@ result = { "ID" : []} else: - result = {} if (output != "noID" ): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |