From: <Z3...@us...> - 2010-12-28 21:46:12
|
Revision: 327 http://spd.svn.sourceforge.net/spd/?rev=327&view=rev Author: Z3po Date: 2010-12-28 21:46:06 +0000 (Tue, 28 Dec 2010) Log Message: ----------- added function to delete and add columns Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdCore.py branches/spd-ng/src/spdInterface.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-12-27 22:31:11 UTC (rev 326) +++ branches/spd-ng/src/spdCLI.py 2010-12-28 21:46:06 UTC (rev 327) @@ -75,7 +75,6 @@ print "No Results found" # }}} - def createEntry(self,columns): # {{{ Entry = {} print "Adding a new Entry to our passfile" @@ -108,7 +107,7 @@ dest ="deleteID", default = False, help ="ID(s) to delete") - + #parser.add_option( "--id", # dest ="id", # help ="Show Password by ID") @@ -118,7 +117,7 @@ dest = "add", default=False, help = "Add an Entry") - + #parser.add_option( "--add-column", # metavar="Collumn", # dest = "addcolumn", @@ -147,6 +146,18 @@ # dest = "passfile", # help = "do not use the confgured passfile but the one given here") + parser.add_option( "--add-columns", + action="store_true", + dest = "addColumn", + default=False, + help = "Add Column(s)") + + parser.add_option( "--delete-columns", + action = "store_true", + dest ="deleteColumn", + default = False, + help ="Column(s) to delete") + (options, args) = parser.parse_args() if options.add: @@ -155,7 +166,12 @@ return ["deleteEntry", args] elif options.deleteID: return ["deleteID", args] + elif options.deleteColumn: + return ["deleteColumn", args] + elif options.addColumn: + return ["addColumn", args] + elif options.widemode: self.__outmode = 'wide' else: Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-12-27 22:31:11 UTC (rev 326) +++ branches/spd-ng/src/spdCore.py 2010-12-28 21:46:06 UTC (rev 327) @@ -27,6 +27,18 @@ atexit.register(self.__commit) # Make Sure to Write back changes to sqldb exiting # }}} + def __ErrorHandler(self,function,message): # {{{ + """ErrorHandler of the Core Module. + # function: the function which throws the error + # message: means the \'Exception\' to throw""" + print "################################################" + print "spdCore ErrorHandler." + print "ERRORFUNCTION: " + function + print "ERRORMESSAGE: " + message + print "################################################" + exit(2) + # }}} + def __sql2dict(self,cursor,row): # {{{ result = {} for ColumnNr, Column in enumerate(cursor.description): @@ -102,16 +114,33 @@ # }}} - def addColumn(self,Name): # {{{ - query='alter table ' + self.ConfigSection + ' add column ' + Name + ' text ' + def addColumn(self,columnname): # {{{ + if columnname in self.getColumns(showid=True): + self.__ErrorHandler('addColumn','Column already exists') + query='alter table ' + self.ConfigSection + ' add column ' + columnname + ' text ' self.db.execute(query) # }}} - def delColumn(self,Name): # {{{ - # it's not possible, to delete a column in SQLite - self.deletedColumns.append(Name) + def delColumn(self,columnname): # {{{ + __columns = '' + for __column in self.getColumns(showid=True): + if __column == columnname and columnname != '__ID': + continue + if __columns == '': + __columns = __column + else: + __columns = __columns + ',' + __column + # it's not that easy, to delete a column in SQLite + self.dbc.executescript(""" + CREATE TEMPORARY TABLE """ + self.ConfigSection + """_backup(""" + __columns + """); + INSERT INTO """ + self.ConfigSection + """_backup SELECT """ + __columns + """ FROM """ + self.ConfigSection + """; + DROP TABLE """ + self.ConfigSection + """; + CREATE TABLE """ + self.ConfigSection + """(""" + __columns + """); + INSERT INTO """ + self.ConfigSection + """ SELECT """ + __columns + """ FROM """ + self.ConfigSection + """_backup; + DROP TABLE """ + self.ConfigSection + """_backup; + """) # }}} # EOF Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-12-27 22:31:11 UTC (rev 326) +++ branches/spd-ng/src/spdInterface.py 2010-12-28 21:46:06 UTC (rev 327) @@ -141,6 +141,16 @@ self.__ErrorHandler('deleteEntry','No matches found') # }}} + def deleteColumn(self,columns): # {{{ + for column in columns: + self.__core.delColumn(column) + # }}} + + def addColumn(self,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) 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. |