From: <Z3...@us...> - 2012-09-26 21:59:03
|
Revision: 344 http://spd.svn.sourceforge.net/spd/?rev=344&view=rev Author: Z3po Date: 2012-09-26 21:58:52 +0000 (Wed, 26 Sep 2012) Log Message: ----------- did some work on spdStore Modified Paths: -------------- branches/spd-ng/src/spd branches/spd-ng/src/spd-cli branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdCore.py branches/spd-ng/src/spdDefaults.py branches/spd-ng/src/spdInterface.py branches/spd-ng/src/spdInterfaces/__init__.py branches/spd-ng/src/spdInterfaces/cli.py branches/spd-ng/src/spdStore/__init__.py branches/spd-ng/src/spdStore/devel.py branches/spd-ng/src/spdStore/plain.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spd =================================================================== --- branches/spd-ng/src/spd 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spd 2012-09-26 21:58:52 UTC (rev 344) @@ -2,6 +2,5 @@ import spdInterface - Interface = spdInterface.Interface() Interface.main() Modified: branches/spd-ng/src/spd-cli =================================================================== --- branches/spd-ng/src/spd-cli 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spd-cli 2012-09-26 21:58:52 UTC (rev 344) @@ -1,4 +1,6 @@ #!/usr/bin/python +# -*- coding: utf-8 -*- +# import spdInterface Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdConfig.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,39 +1,31 @@ -#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + from ConfigParser import RawConfigParser import os #import sys -__version__ = '0.3-alpha' - class Config(object): # {{{ '''This is the Configuration Module You can read or set config options''' __configfile = None ReturnCodes = { 2 : 'Missing ConfigFile', - 4 : 'ConfigFile not Readable', - 8 : 'ConfigFile not Writeable', - 16 : 'Configfile Writeable but another Error Occured', - 32 : 'Section not found', - 64 : 'Option not found' } + 4 : 'ConfigFile not Readable', + 8 : 'ConfigFile not Writeable', + 16 : 'Configfile Writeable but another Error Occured', + 32 : 'Section not found', + 64 : 'Option not found' } ConfigSection = 'Main' def __init__(self, configfile='~/.spd/config'): # {{{ self.__configfile = os.path.expanduser(configfile) # }}} - def __ErrorHandler(self,message): # {{{ - """ErrorHandler of the Config Module. - # message: means the \'Exception\' to throw""" - print "################################################" - print "spdConfig ErrorHandler." - print "Configfile: " + self.__configfile - print "ERRORMESSAGE: " + message - print "################################################" - exit(2) - # }}} - def __checkConfigFileExist(self): # {{{ """Does the Config file exist?""" @@ -222,7 +214,7 @@ reval, config = self.__checkConfigFileReadable() if reval > 0: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if raw: return 0, config.sections() @@ -235,7 +227,7 @@ reval = self.__addSection(section) if reval > 0: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) # }}} def getConfigVersion(self, raw=False): # {{{ @@ -244,13 +236,13 @@ reval, option = self.__getOption("Main","version") if reval > 2 and reval < 32: - self.__ErrorHandler(self.ReturnCodes[reval]) # don't tolerate These + raise KeyError(self.ReturnCodes[reval]) # don't tolerate These if reval > 0: if raw: return reval, None - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if raw: return reval, option @@ -265,7 +257,7 @@ reval = self.__setOption("Main","version",version) if reval > 0: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) # }}} def getClientmode(self, raw=False): # {{{ @@ -275,13 +267,13 @@ reval, clientmode = self.__getOption('Main', 'clientmode') if reval > 0 and reval < 64: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if reval > 0: if raw: return reval, None else: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if raw: return reval, clientmode @@ -296,7 +288,7 @@ reval = self.__setOption("Main","clientmode",clientmode) if reval > 0: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) # }}} def getPasswordfield(self, raw=False): # {{{ @@ -306,13 +298,13 @@ reval, clientmode = self.__getOption('Main', 'passwordfield') if reval > 0 and reval < 64: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if reval > 0: if raw: return reval, None else: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if raw: return reval, clientmode @@ -327,23 +319,23 @@ reval = self.__setOption("Main","passwordfield",passcolumn) if reval > 0: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) # }}} - def getStoreType(self, raw=False): # {{{ + 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]) + raise KeyError(self.ReturnCodes[reval]) if reval > 0: if raw: return reval, None else: - self.__ErrorHandler(self.ReturnCodes[reval]) + raise KeyError(self.ReturnCodes[reval]) if raw: return reval, storetype @@ -351,7 +343,27 @@ return storetype # }}} + def getPasswordfile(self, raw=False): # {{{ + '''get the password field. + # return the password field''' + reval, storetype = self.__getOption('Main', 'file') + + if reval > 0 and reval < 64: + raise KeyError(self.ReturnCodes[reval]) + + if reval > 0: + if raw: + return reval, None + else: + raise KeyError(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-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdCore.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,3 +1,10 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + + '''spdCore Module. Handles the Datastore of SPD. @@ -3,37 +10,25 @@ Usage: import spdCore -coreobject = spdCore.Core()''' +coreobject = spdCore.Core(ConfigObject)''' import re import random import string - class Core(object): + version = '0.3-alpha' + # create the database from the stuff out of the store def __init__(self,ConfigObject): # {{{ - self.ConfigSection = ConfigObject.ConfigSection + self.PasswordPreset = ConfigObject.ConfigSection self.PasswordColumn = ConfigObject.getPasswordfield() - self.spdStore = __import__('spdStore.' + ConfigObject.getStoreType(), fromlist=['',]) - self.db = self.spdStore.getData() + self.PasswordFile = ConfigObject.getPasswordfile() + self.spdStore = __import__('spdStore.' + ConfigObject.getStoretype(), fromlist=['',]) + self.db = self.spdStore.getData(self.PasswordFile) self.db.row_factory = self.__sql2dict self.dbc = self.db.cursor() - - self.deletedColumns = [] # }}} - 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 = {} @@ -42,12 +37,11 @@ result[Column[0]] = row[ColumnNr] return result - # }}} def searchEntry(self,SearchList,byid=False): # {{{ - query = 'select * from ' + self.ConfigSection + ' where ' + query = 'select * from ' + self.PasswordPreset + ' where ' # search by ID if byid: @@ -55,7 +49,7 @@ if re.match('\d+',__id): query += '__ID = ' + __id + ' or ' else: - self.__ErrorHandler('searchEntry', 'Searching for ID but no valid ID given: ' + __id) + raise LookupError('Searching for ID but no valid ID given: ' + __id) query = query[0:-3] else: # Build the where-clause @@ -78,13 +72,13 @@ result[j].append(i[j]) except KeyError: result[j] = [i[j]] - + return result # }}} def addEntry(self,NewDict): # {{{ - query = 'insert into ' + self.ConfigSection + '( ' - + query = 'insert into ' + self.PasswordPreset + '( ' + cols = '' vals = '' for i in NewDict.keys(): @@ -98,14 +92,14 @@ def delEntry(self,ID): # {{{ for __id in ID: - query = 'delete from '+ self.ConfigSection +' where __ID=\'' + str(__id) + '\'' + query = 'delete from '+ self.PasswordPreset +' where __ID=\'' + str(__id) + '\'' self.dbc.execute(query) self.db.commit() # }}} def editEntry(self,__passdict): # {{{ - query = 'UPDATE ' + self.ConfigSection + ' SET ' + query = 'UPDATE ' + self.PasswordPreset + ' SET ' for i in range(0, len(__passdict['__ID'])): for __column in __passdict: if __column != '__ID': @@ -113,32 +107,31 @@ query = query[0:-2] query += ' WHERE __ID = ' + str(__passdict['__ID'][i]) self.dbc.execute(query) - query = 'UPDATE ' + self.ConfigSection + ' SET ' + query = 'UPDATE ' + self.PasswordPreset + ' SET ' self.db.commit() # }}} def getColumns(self,showid=True): # {{{ - query = "pragma Table_info('" + self.ConfigSection + "')" + query = "pragma Table_info('" + self.PasswordPreset + "')" self.dbc.execute(query) result = [] for i in self.dbc: if not showid and i['name'] == "__ID": continue - if i['name'] not in self.deletedColumns: - result.append(i['name']) + result.append(i['name']) return result # }}} def addColumn(self,columnname): # {{{ if columnname in self.getColumns(showid=True): - self.__ErrorHandler('addColumn','Column \"' + columnname + '\" already exists') - query='alter table ' + self.ConfigSection + ' add column ' + columnname + ' text ' + raise KeyError('Column \"' + columnname + '\" already exists') + query='alter table ' + self.PasswordPreset + ' add column ' + columnname + ' text ' self.db.execute(query) self.db.commit() # }}} - - def delColumn(self,columnname): # {{{ + + def delColumn(self,columnname): # {{{ __columns = '' __newcolumns = '' for __column in self.getColumns(showid=True): @@ -162,27 +155,27 @@ # it's not that easy, to delete a column in SQLite self.dbc.executescript(""" - CREATE TEMPORARY TABLE """ + self.ConfigSection + """_backup(""" + __newcolumns + """); - INSERT INTO """ + self.ConfigSection + """_backup SELECT """ + __columns + """ FROM """ + self.ConfigSection + """; - DROP TABLE """ + self.ConfigSection + """; - CREATE TABLE """ + self.ConfigSection + """(""" + __newcolumns + """); - INSERT INTO """ + self.ConfigSection + """ SELECT """ + __columns + """ FROM """ + self.ConfigSection + """_backup; - DROP TABLE """ + self.ConfigSection + """_backup; + CREATE TEMPORARY TABLE """ + self.PasswordPreset + """_temp(""" + __newcolumns + """); + INSERT INTO """ + self.PasswordPreset + """_temp SELECT """ + __columns + """ FROM """ + self.PasswordPreset + """; + DROP TABLE """ + self.PasswordPreset + """; + CREATE TABLE """ + self.PasswordPreset + """(""" + __newcolumns + """); + INSERT INTO """ + self.PasswordPreset + """ SELECT """ + __columns + """ FROM """ + self.PasswordPreset + """_temp; + DROP TABLE """ + self.PasswordPreset + """_temp; """) self.db.commit() - # }}}a - + # }}} + def makepass(self,size=16): # {{{ chars = [] chars.extend([i for i in string.ascii_letters]) chars.extend([i for i in string.digits]) chars.extend([i for i in '\'"!@#$%&*()-_=+[{}]~^,<.>;:/?']) - + passwd = '' - + for i in range(size): passwd += random.choice(chars) - + return passwd # }}} Modified: branches/spd-ng/src/spdDefaults.py =================================================================== --- branches/spd-ng/src/spdDefaults.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdDefaults.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + """This is the Defaults Configuration Module Trying to create the defaults""" Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdInterface.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + '''spdInterface Module. The Modules handles all the exchange between user and spdCore. @@ -12,33 +18,32 @@ if building your own interface, name it "whatever" and pass "whatever" to the Interface Class. The Module must be in spds spdInterfaces path.''' -from sys import exit import os import string import spdConfig import spdDefaults import spdCore -__version__ = '0.3-alpha' - class Interface(object): # {{{ """The Interface Module. Interface between client and Core.""" - __spddir = os.path.expanduser('~/.spd/') - __client = None - __core = None + spddir = os.path.expanduser('~/.spd/') + client = None + core = None def __init__(self,clientmode=False): # {{{ """init procedure""" initcheck = {} - if not os.access(self.__spddir, os.F_OK): - os.mkdir(self.__spddir) - self.ConfigObject = spdConfig.Config() - reval, initcheck['version'] = self.ConfigObject.getConfigVersion(raw=True) - + self.core = spdCore.Core(self.ConfigObject) + + if not os.access(self.spddir, os.F_OK): + os.mkdir(self.spddir) + + reval, self.configversion = self.ConfigObject.getConfigVersion(raw=True) + if reval > 0 and reval < 64: spdDefaults.createDefaultConfig(self.ConfigObject) return self.__startupCheck() @@ -46,7 +51,7 @@ print 'ConfigVersion not found...setting Default one\n' __blackhole = raw_input('Press any key') self.ConfigObject.setConfigVersion('0.3-alpha') - initcheck.update({ 'version' : self.ConfigObject.getConfigVersion() }) + self.configversion = self.ConfigObject.getConfigVersion() reval, initcheck['clientmode'] = self.ConfigObject.getClientmode(raw=True) @@ -64,21 +69,11 @@ if not clientmode: clientmode = initcheck['clientmode'] - __tempclient = __import__('spdInterfaces.' + clientmode.lower(), fromlist=['',]) - self.__client = __tempclient - del __tempclient + self.client = __import__('spdInterfaces.' + clientmode.lower(), fromlist=['',]) if 'passwordfield' in initcheck: - self.__client._passwordfield = initcheck['passwordfield'] + self.client._passwordfield = initcheck['passwordfield'] - - self.__core = spdCore.Core(self.ConfigObject) - - self.__version = { 'ConfigFile' : initcheck['version'], - 'spdInterface' : __version__, - 'spdDefaults' : spdDefaults.__version__, - 'spdConfig' : spdConfig.__version__ } - del initcheck # }}} @@ -103,14 +98,14 @@ if len(searchlist) == 0: searchlist = ['%',] - passdict = self.__core.searchEntry(searchlist,byid) + passdict = self.core.searchEntry(searchlist,byid) return passdict # }}} def printPasswords(self,args): # {{{ passdict = self.__findPasswords(args) - self.__client.printPasswords(passdict, args) + self.client.printPasswords(passdict, args) # }}} def deleteEntry(self, args): # {{{ @@ -119,16 +114,16 @@ if len(__passdict) == 0: raise ValueError('deleteEntry','No matches found') - self.__client.printPasswords(__passdict) - ids = self.__client.deleteEntry(__passdict) - self.__core.delEntry(ids) + 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) + __newpassdict = self.client.editEntry(__passdict) + self.core.editEntry(__newpassdict) else: raise ValueError('no matches for ' + str(args["args"]) + 'found') # }}} @@ -139,8 +134,8 @@ else: columns = [] for column in columns: - if column in self.__core.getColumns(showid=False): - self.__core.delColumn(column) + if column in self.core.getColumns(showid=False): + self.core.delColumn(column) else: raise ValueError('deleteColumn','column ' + column + ' is not part of the passwordfile') # }}} @@ -152,16 +147,16 @@ columns = [] for column in columns: - self.__core.addColumn(column) + self.core.addColumn(column) # }}} def addEntry(self, args): # {{{ - Entry = self.__client.createEntry(self.__core.getColumns(showid=False)) - self.__core.addEntry(Entry) + Entry = self.client.createEntry(self.core.getColumns(showid=False)) + self.core.addEntry(Entry) # }}} def main(self): # {{{ - function, args = self.__client.parseArgs(self.__version) + function, args = self.client.parseArgs(self.core.version) getattr(self, function)(args) # }}} Modified: branches/spd-ng/src/spdInterfaces/__init__.py =================================================================== --- branches/spd-ng/src/spdInterfaces/__init__.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdInterfaces/__init__.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,4 +1,9 @@ # -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + '''spdInterfaces Module This Module takes Care of the Interface used by SPD.''' Modified: branches/spd-ng/src/spdInterfaces/cli.py =================================================================== --- branches/spd-ng/src/spdInterfaces/cli.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdInterfaces/cli.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + """Client Interfaces Module This is the Cli Module. @@ -8,7 +14,6 @@ from sys import stdout from re import sub, search -__version__ = '0.3-alpha' passwordfield = 'Password' def __ErrorHandler(function,message): # {{{ @@ -153,16 +158,12 @@ return Entry # }}} -def parseArgs(versions): # {{{ +def parseArgs(coreversion): # {{{ __optionsdict = {} parser = OptionParser( "%prog [Options] [Keywords]", description = "SPD - Simple Password Displayer - CLI", - version = """\nspdInterface """ + versions['spdInterface'] + - """\nspdConfig """ + versions['spdConfig'] + - """\nspdDefaults """ + versions['spdDefaults'] + - """\nConfigFile """ + versions['ConfigFile'] + - """\nCLI """ + __version__, + version = coreversion, epilog = """With no parameters it will print out everything! Please report Bugs or Feature Request at http://spd.sourceforge.net""") Modified: branches/spd-ng/src/spdStore/__init__.py =================================================================== --- branches/spd-ng/src/spdStore/__init__.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdStore/__init__.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,3 +1,9 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + '''spdStore Module This Modules takes Care of the storage Engine used by SPD.''' Modified: branches/spd-ng/src/spdStore/devel.py =================================================================== --- branches/spd-ng/src/spdStore/devel.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdStore/devel.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,4 +1,9 @@ # -*- coding: utf-8 -*- +# +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> + '''spdStore.devel This module is just for development. No real data should be written into that database''' @@ -7,7 +12,7 @@ testdb = '/home/scabrera/Projects/spd/branches/spd-ng/src/test.db' -def getData(): # {{{ +def getData(passwordfile): # {{{ db = sqlite3.connect(testdb) return db # }}} Modified: branches/spd-ng/src/spdStore/plain.py =================================================================== --- branches/spd-ng/src/spdStore/plain.py 2012-09-24 21:12:21 UTC (rev 343) +++ branches/spd-ng/src/spdStore/plain.py 2012-09-26 21:58:52 UTC (rev 344) @@ -1,5 +1,45 @@ # -*- coding: utf-8 -*- # +# Copyright (C) 2009 +# Klaus Umbach <tre...@us...> +# Sebastian Cabrera <z3...@us...> -pass +import sqlite3 + +separator = '\t' + +def getData(passwordfile): #{{{ + """This function reads the password file""" + + passfile = open(passwordfile,"r") + sqlitedb = sqlite3.connect(":memory:") + sqlitecursor = sqlitedb.cursor() + query = "CREATE TABLE passwords ( __ID INTEGER PRIMARY KEY," + + for linecount, i in enumerate(passfile): + line = i.strip('\n').split(separator) + + if linecount == 0: # the first line defines the collumns + for column in line: + query += '`' + column + "` TEXT, " + query = query[0:-2] + ' )' + sqlitecursor.execute(query) + query = "INSERT INTO passwords ( " + for column in line: + query += column + ', ' + query = query[0:-2] + ' ) VALUES ( ' + next + + inserts = "" + for column in line: + inserts += column + ', ' + inserts = inserts[0:-2] + ' )' + print str(query + inserts) + sqlitecursor.execute(query + inserts) + + sqlitedb.commit() + + return sqlitedb +#}}} + # vim:filetype=python:foldmethod=marker:autoindent:expandtab:tabstop=4 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. |