From: <tre...@us...> - 2010-09-05 00:23:15
|
Revision: 301 http://spd.svn.sourceforge.net/spd/?rev=301&view=rev Author: treibholz Date: 2010-09-05 00:23:06 +0000 (Sun, 05 Sep 2010) Log Message: ----------- initial CoreStuff (naked!) Added Paths: ----------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Added: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py (rev 0) +++ branches/spd-ng/src/spdCore.py 2010-09-05 00:23:06 UTC (rev 301) @@ -0,0 +1,32 @@ +#!/usr/bin/python + +class Core(object): + + def __init__(ConfigSection='Main'): + pass + + def __del__(): + pass + + + def searchEntry(SearchList): + pass + + def addEntry(NewDict): + pass + + def delEntry(ID): + pass + + + def getCollumns(): + pass + + def addCollumn(Name): + pass + + def delCollumn(Name): + pass + + + Property changes on: branches/spd-ng/src/spdCore.py ___________________________________________________________________ Added: svn:eol-style + native Added: branches/spd-ng/src/test.db =================================================================== (Binary files differ) Property changes on: branches/spd-ng/src/test.db ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-09-05 00:48:15
|
Revision: 303 http://spd.svn.sourceforge.net/spd/?rev=303&view=rev Author: Z3po Date: 2010-09-05 00:48:09 +0000 (Sun, 05 Sep 2010) Log Message: ----------- change name of ConfigMofule Added Paths: ----------- branches/spd-ng/src/spdConfig.py Removed Paths: ------------- branches/spd-ng/src/Config.py Deleted: branches/spd-ng/src/Config.py =================================================================== --- branches/spd-ng/src/Config.py 2010-09-05 00:47:33 UTC (rev 302) +++ branches/spd-ng/src/Config.py 2010-09-05 00:48:09 UTC (rev 303) @@ -1,59 +0,0 @@ -from ConfigParser import RawConfigParser -import os -import sys - -class CONFIG: # {{{ - """This is the Configuration Module - You can read or set config options""" - - configfile = os.path.expanduser('~/.spd/config') - config = RawConfigParser() - - def ErrorHandler(self,message): - print message - sys.exit(2) - - def checkConfigFileWriteable(self): - if os.access(self.configfile,os.W_OK): - return True - else: - self.ErrorHandler(self.configfile + " Not WRITEABLE") - - def checkConfigFileReadable(self): - if os.access(self.configfile,os.R_OK): - self.config.read(self.configfile) - return self.config - else: - self.ErrorHandler(configfile + " NOT READABLE") - - def writeConfigFile(self,config): - configfile = open(self.configfile, 'wb') - try: - config.write(configfile) - except Exception, e: - self.ErrorHandler("An Error Occured" + str(e)) - - - def getSPDversion(self): - config = self.checkConfigFileReadable() - config.sections - if config.has_section("Main"): - if config.has_option("Main","version"): - return config.get("Main","version") - else: - self.ErrorHandler("Option version missing") - else: - self.ErrorHandler("Section Main missing") - - def setSPDversion(self,version): - self.checkConfigFileWriteable() - config = self.checkConfigFileReadable() - if config.has_section("Main"): - config.set("Main","version",version) - else: - self.ErrorHandler("Section Main missing") - self.writeConfigFile(config) -# }}} - -# EOF -# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Copied: branches/spd-ng/src/spdConfig.py (from rev 302, branches/spd-ng/src/Config.py) =================================================================== --- branches/spd-ng/src/spdConfig.py (rev 0) +++ branches/spd-ng/src/spdConfig.py 2010-09-05 00:48:09 UTC (rev 303) @@ -0,0 +1,59 @@ +from ConfigParser import RawConfigParser +import os +import sys + +class CONFIG: # {{{ + """This is the Configuration Module + You can read or set config options""" + + configfile = os.path.expanduser('~/.spd/config') + config = RawConfigParser() + + def ErrorHandler(self,message): + print message + sys.exit(2) + + def checkConfigFileWriteable(self): + if os.access(self.configfile,os.W_OK): + return True + else: + self.ErrorHandler(self.configfile + " Not WRITEABLE") + + def checkConfigFileReadable(self): + if os.access(self.configfile,os.R_OK): + self.config.read(self.configfile) + return self.config + else: + self.ErrorHandler(configfile + " NOT READABLE") + + def writeConfigFile(self,config): + configfile = open(self.configfile, 'wb') + try: + config.write(configfile) + except Exception, e: + self.ErrorHandler("An Error Occured" + str(e)) + + + def getSPDversion(self): + config = self.checkConfigFileReadable() + config.sections + if config.has_section("Main"): + if config.has_option("Main","version"): + return config.get("Main","version") + else: + self.ErrorHandler("Option version missing") + else: + self.ErrorHandler("Section Main missing") + + def setSPDversion(self,version): + self.checkConfigFileWriteable() + config = self.checkConfigFileReadable() + if config.has_section("Main"): + config.set("Main","version",version) + else: + self.ErrorHandler("Section Main missing") + self.writeConfigFile(config) +# }}} + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Property changes on: branches/spd-ng/src/spdConfig.py ___________________________________________________________________ Added: svn:mergeinfo + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-09-05 01:46:50
|
Revision: 304 http://spd.svn.sourceforge.net/spd/?rev=304&view=rev Author: Z3po Date: 2010-09-05 01:46:43 +0000 (Sun, 05 Sep 2010) Log Message: ----------- first import of spdCheck module Modified Paths: -------------- branches/spd-ng/src/spdConfig.py Added Paths: ----------- branches/spd-ng/src/spdCheck.py Added: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py (rev 0) +++ branches/spd-ng/src/spdCheck.py 2010-09-05 01:46:43 UTC (rev 304) @@ -0,0 +1,25 @@ +#!/usr/bin/python + +import spdConfig +import os + +class CHECK(object): + +# def __init__(self,module): +# if module = "spdInterface": +# self.checkConfigFile() +# elif module = "spdCore": +# pass + + def checkConfigFile(self): + config = spdConfig.CONFIG() + if os.access(self,config.configfile,os.F_OK): + if config.checkConfigFileReadable(raw=True): + if config.hasSection("Main"): + version = config.getSPDversion(raw=True) + if not version: + pass + else: + if version == "0.3": + pass + Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-09-05 00:48:09 UTC (rev 303) +++ branches/spd-ng/src/spdConfig.py 2010-09-05 01:46:43 UTC (rev 304) @@ -1,51 +1,74 @@ +#!/usr/bin/python + from ConfigParser import RawConfigParser import os import sys +import spdCheck -class CONFIG: # {{{ +class CONFIG(object): # {{{ """This is the Configuration Module You can read or set config options""" configfile = os.path.expanduser('~/.spd/config') config = RawConfigParser() - def ErrorHandler(self,message): + def ErrorHandler(self,message): # {{{ print message sys.exit(2) + # }}} - def checkConfigFileWriteable(self): + def checkConfigFileWriteable(self,raw=False): # {{{ if os.access(self.configfile,os.W_OK): return True else: - self.ErrorHandler(self.configfile + " Not WRITEABLE") + if not raw: + self.ErrorHandler(self.configfile + " Not WRITEABLE") + else: + return False + # }}} - def checkConfigFileReadable(self): + def checkConfigFileReadable(self,raw=False): # {{{ if os.access(self.configfile,os.R_OK): self.config.read(self.configfile) - return self.config + if not raw: + return self.config + else: + return True else: - self.ErrorHandler(configfile + " NOT READABLE") + if not raw: + self.ErrorHandler(configfile + " NOT READABLE") + else: + return False + # }}} - def writeConfigFile(self,config): + def writeConfigFile(self,config): # {{{ configfile = open(self.configfile, 'wb') try: config.write(configfile) except Exception, e: self.ErrorHandler("An Error Occured" + str(e)) + # }}} + def hasSection(self,section): # {{{ + config = slf.checkConfigFileReadable() + return config.has_section(section) + # }}} - def getSPDversion(self): + def getSPDversion(self,raw=False): # {{{ config = self.checkConfigFileReadable() - config.sections if config.has_section("Main"): if config.has_option("Main","version"): return config.get("Main","version") else: - self.ErrorHandler("Option version missing") + if not raw: + self.ErrorHandler("Option version missing") + else: + return False else: self.ErrorHandler("Section Main missing") + # }}} - def setSPDversion(self,version): + def setSPDversion(self,version): # {{{ self.checkConfigFileWriteable() config = self.checkConfigFileReadable() if config.has_section("Main"): @@ -53,6 +76,7 @@ else: self.ErrorHandler("Section Main missing") self.writeConfigFile(config) + # }}} # }}} # EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2010-09-05 01:48:01
|
Revision: 305 http://spd.svn.sourceforge.net/spd/?rev=305&view=rev Author: treibholz Date: 2010-09-05 01:47:55 +0000 (Sun, 05 Sep 2010) Log Message: ----------- first bunch of methods Modified Paths: -------------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Added Paths: ----------- branches/spd-ng/src/spdStore.py Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-09-05 01:46:43 UTC (rev 304) +++ branches/spd-ng/src/spdCore.py 2010-09-05 01:47:55 UTC (rev 305) @@ -1,32 +1,58 @@ #!/usr/bin/python +import sqlite3 + class Core(object): - - def __init__(ConfigSection='Main'): - pass - def __del__(): - pass + # create the database from the stuff out of the store + def __init__(self,ConfigSection='Main'): # {{{ + self.ConfigSection = ConfigSection + self.db = sqlite3.connect('test.db') + self.dbc = self.db.cursor() + self.deletedColumns = [] - def searchEntry(SearchList): + # }}} + + + # Writes back to the Store + def __del__(self): + self.db.commit() + + + def searchEntry(self,SearchList): pass - def addEntry(NewDict): + def addEntry(self,NewDict): pass - def delEntry(ID): + def delEntry(self,ID): pass + def getColumns(self): # {{{ + query = "pragma Table_info('" + self.ConfigSection + "')" + self.dbc.execute(query) - def getCollumns(): - pass + result = [] + for i in self.dbc: + if i[1] not in self.deletedColumns: + result.append(i[1]) - def addCollumn(Name): - pass + return result + + # }}} + + def addColumn(self,Name): # {{{ + query='alter table ' + self.ConfigSection + ' add column ' + Name + ' text ' + self.db.execute(query) + + # }}} - def delCollumn(Name): - pass + def delColumn(self,Name): # {{{ + # it's not possible, to delete a column in SQLite + self.deletedColumns.append(Name) + # }}} - +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Property changes on: branches/spd-ng/src/spdStore.py ___________________________________________________________________ Added: svn:eol-style + native 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. |
From: <Z3...@us...> - 2010-09-05 10:17:53
|
Revision: 306 http://spd.svn.sourceforge.net/spd/?rev=306&view=rev Author: Z3po Date: 2010-09-05 10:17:46 +0000 (Sun, 05 Sep 2010) Log Message: ----------- changed modules to be more scalable Modified Paths: -------------- branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdConfig.py Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-09-05 01:47:55 UTC (rev 305) +++ branches/spd-ng/src/spdCheck.py 2010-09-05 10:17:46 UTC (rev 306) @@ -5,21 +5,40 @@ class CHECK(object): -# def __init__(self,module): -# if module = "spdInterface": -# self.checkConfigFile() -# elif module = "spdCore": -# pass + def __init__(self,module): + if module == "spdInterface": + self.checkConfigFile() + elif module == "spdCore": + pass def checkConfigFile(self): config = spdConfig.CONFIG() - if os.access(self,config.configfile,os.F_OK): - if config.checkConfigFileReadable(raw=True): + if config.checkConfigFileExist(): + if config.checkConfigFileReadable(): if config.hasSection("Main"): - version = config.getSPDversion(raw=True) - if not version: - pass - else: + if config.getOption("Main","version"): + version = config.getSPDversion() if version == "0.3": pass - + else: + config.ErrorHandler("Where you got THIS version from???\nCannot work with") + else: + config.setSPDversion("0.3") + else: + config.setSection("Main") + else: + config.ErrorHandler("CONFIGFILE THERE BUT NOT READABLE") + else: + if config.checkConfigFileWriteable(): + newconfig = DEFAULTS() + newconfig.createDefaultConfig(config) + else: + config.ErrorHandler("CONFIGFILE PATH NOT WRITEABLE") + +class DEFAULTS(object): + + def createDefaultConfig(self,config): + config.setSection("Main") + config.setSPDversion("0.3") + +test = CHECK("spdInterface") Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-09-05 01:47:55 UTC (rev 305) +++ branches/spd-ng/src/spdConfig.py 2010-09-05 10:17:46 UTC (rev 306) @@ -3,42 +3,47 @@ from ConfigParser import RawConfigParser import os import sys -import spdCheck class CONFIG(object): # {{{ """This is the Configuration Module You can read or set config options""" configfile = os.path.expanduser('~/.spd/config') - config = RawConfigParser() def ErrorHandler(self,message): # {{{ - print message + print "################################################" + print "spdConfig ErrorHandler." + print "Configfile: " + self.configfile + print "ERRORMESSAGE: " + message + print "################################################" sys.exit(2) # }}} - def checkConfigFileWriteable(self,raw=False): # {{{ + def checkConfigFileExist(self): # {{{ + if os.access(self.configfile, os.F_OK): + return True + else: + return False + # }}} + + def checkConfigFileWriteable(self): # {{{ + if not self.checkConfigFileExist(): + open(self.configfile, 'w').close() if os.access(self.configfile,os.W_OK): return True else: - if not raw: - self.ErrorHandler(self.configfile + " Not WRITEABLE") - else: - return False + return False # }}} - def checkConfigFileReadable(self,raw=False): # {{{ + def checkConfigFileReadable(self): # {{{ + config = RawConfigParser() + if not self.checkConfigFileExist(): + self.ErrorHandler("CONFIGFILE MISSING") if os.access(self.configfile,os.R_OK): - self.config.read(self.configfile) - if not raw: - return self.config - else: - return True + config.read(self.configfile) + return config else: - if not raw: - self.ErrorHandler(configfile + " NOT READABLE") - else: - return False + return False # }}} def writeConfigFile(self,config): # {{{ @@ -50,33 +55,82 @@ # }}} def hasSection(self,section): # {{{ - config = slf.checkConfigFileReadable() - return config.has_section(section) + config = self.checkConfigFileReadable() + if not config: + self.ErrorHandler("CONFIGFILE NOT READABLE") + if config.has_section(section): + return config # }}} - def getSPDversion(self,raw=False): # {{{ - config = self.checkConfigFileReadable() - if config.has_section("Main"): + def setSection(self,section): # {{{ + if not self.checkConfigFileWriteable(): + self.ErrorHandler("CONFIGFILE NOT WRITEABLE") + config = self.hasSection(section) + if not config: + config = self.checkConfigFileReadable() + config.add_section(section) + self.writeConfigFile(config) + return True + else: + self.ErrorHandler("SECTION " + section + " already there") + # }}} + + def delSection(self,section): # {{{ + if not self.checkConfigFileWriteable(): + self.ErrorHandler("CONFIGFILE NOT WRITEABLE") + config = self.hasSection(section) + if config: + config.remove_section(section) + return True + else: + return False + # }}} + + def getOption(self,section,option): # {{{ + config = self.hasSection(section) + if config: if config.has_option("Main","version"): return config.get("Main","version") else: - if not raw: - self.ErrorHandler("Option version missing") - else: - return False + return False else: - self.ErrorHandler("Section Main missing") + self.ErrorHandler("SECTION " + section + " MISSING") # }}} - def setSPDversion(self,version): # {{{ - self.checkConfigFileWriteable() - config = self.checkConfigFileReadable() - if config.has_section("Main"): - config.set("Main","version",version) + def setOption(self,section,option,value): # {{{ + config = self.hasSection(section) + if config: + config.set(section,option,value) + self.writeConfigFile(config) + return True else: - self.ErrorHandler("Section Main missing") - self.writeConfigFile(config) + self.ErrorHandler("SECTION " + section + " MISSING") # }}} + + def delOption(self,section,option): # {{{ + config = self.hasSection(section) + if config: + if self.getOption(section,option): + config.remove_option(section,option) + self.writeConfigFile(config) + return True + else: + return False + else: + return False + # }}} + + def getSPDversion(self): # {{{ + option = self.getOption("Main","version") + if option: + return option + else: + self.ErrorHandler("Option version missing") + # }}} + + def setSPDversion(self,version): # {{{ + self.setOption("Main","version",version) + # }}} # }}} # EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tre...@us...> - 2010-09-05 11:17:23
|
Revision: 307 http://spd.svn.sourceforge.net/spd/?rev=307&view=rev Author: treibholz Date: 2010-09-05 11:17:17 +0000 (Sun, 05 Sep 2010) Log Message: ----------- addEntry works Modified Paths: -------------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-09-05 10:17:46 UTC (rev 306) +++ branches/spd-ng/src/spdCore.py 2010-09-05 11:17:17 UTC (rev 307) @@ -14,21 +14,35 @@ # }}} - # Writes back to the Store def __del__(self): self.db.commit() + def searchEntry(self,SearchList): pass - def addEntry(self,NewDict): - pass + def addEntry(self,NewDict): # {{{ + query = 'insert into ' + self.ConfigSection + '( ' + + cols = '' + vals = '' + for i in NewDict.keys(): + cols += i + ', ' + vals += ':' + i + ', ' + query += cols[0:-2] + ') VALUES ( ' + vals[0:-2] + ')' + print query + self.dbc.execute(query,NewDict) + + # }}} + def delEntry(self,ID): pass + + def getColumns(self): # {{{ query = "pragma Table_info('" + self.ConfigSection + "')" self.dbc.execute(query) 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. |
From: <Z3...@us...> - 2010-09-05 11:34:10
|
Revision: 308 http://spd.svn.sourceforge.net/spd/?rev=308&view=rev Author: Z3po Date: 2010-09-05 11:34:04 +0000 (Sun, 05 Sep 2010) Log Message: ----------- first import of spdCLIi and change of spdInterface Module Modified Paths: -------------- branches/spd-ng/src/spdCheck.py Added Paths: ----------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdInterface.py Added: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py (rev 0) +++ branches/spd-ng/src/spdCLI.py 2010-09-05 11:34:04 UTC (rev 308) @@ -0,0 +1,24 @@ +#!/usr/bin/python + +import string + +class CLI(object): # {{{ + """This is the CLI Module. + Resistance is Futile""" + + output = "normal" + + def printPasswords(passdict): # {{{ + if output == 'normal': + for key in passdict: + print key + ':' + passdict[key].value + # }}} + + def findPasswordsInteractive(): # {{{ + searchstring = raw_input("Please give your Searchstrings separated by whitespace") + # }}} + +# }}} + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-09-05 11:17:17 UTC (rev 307) +++ branches/spd-ng/src/spdCheck.py 2010-09-05 11:34:04 UTC (rev 308) @@ -3,15 +3,26 @@ import spdConfig import os -class CHECK(object): +class CHECK(object): # {{{ + """This is the initcheck Configuration Module + Checks if everything is there to perform :)""" - def __init__(self,module): + spddir = os.path.expanduser('~/.spd/') + + def __init__(self,module): # {{{ if module == "spdInterface": + self.checkSPDdir() self.checkConfigFile() elif module == "spdCore": pass + # }}} - def checkConfigFile(self): + def checkSPDdir(self): # {{{ + if not os.access(self.spddir, os.F_OK): + os.mkdir(spddir) + # }}} + + def checkConfigFile(self): # {{{ config = spdConfig.CONFIG() if config.checkConfigFileExist(): if config.checkConfigFileReadable(): @@ -34,11 +45,16 @@ newconfig.createDefaultConfig(config) else: config.ErrorHandler("CONFIGFILE PATH NOT WRITEABLE") + # }}} +# }}} -class DEFAULTS(object): +class DEFAULTS(object): # {{{ - def createDefaultConfig(self,config): + def createDefaultConfig(self,config): # {{{ config.setSection("Main") config.setSPDversion("0.3") + # }}} +# }}} -test = CHECK("spdInterface") +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Added: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py (rev 0) +++ branches/spd-ng/src/spdInterface.py 2010-09-05 11:34:04 UTC (rev 308) @@ -0,0 +1,107 @@ +#!/usr/bin/python + +import spdCheck +import spdCore +import spdCLI +from optparse import OptionParser + +version = "0.3-alpha" + +class INTERFACE(object): # {{{ + + clientmode = "CLI" + + def __init__(self,clientmode="CLI"): # {{{ + """Do some checks before we start""" + check = spdCheck.CHECK("spdInterface") + del check + + if clientmode == 'CLI': + self.client = spdCLI.CLI() + # }}} + + def findPasswords(searchString='%',interactive=False): # {{{ + """Find the passwords interactively or by searchlist handed. + print the results in output format. + searchlist: optional list of keywords to search for + interactive: shall the interface ask for the keywords?""" + + if not interactive: + searchlist = string.split(searchString) + else: + searchlist = self.client.findPasswordsInteractive() + + passdict = spdCore.searchEntry(searchlist) + printPasswords(passdict) + # }}} + + +# }}} + +# {{{ OptionParser stuff +parser = OptionParser( "%prog [Options] [Keywords]", + description = "SPD - Simple Password Displayer", + version = version, + epilog = "With no parameters it will print out everything!") + +#parser.add_option( "-d", "--delete", +# metavar="Keywords", +# dest ="delete", +# help ="Entries to delete") +# +#parser.add_option( "-e", "--edit", +# metavar="ID", +# dest ="edit", +# help ="ID to edit") +# +#parser.add_option( "-i", "--delete-id", +# metavar="ID", +# dest ="deleteID", +# help ="ID to delete") +# +#parser.add_option( "--id", +# dest ="id", +# help ="Show Password by ID") +# +#parser.add_option( "-a", "--add", +# action="store_true", +# dest = "add", +# default=False, +# help = "Add an Entry") +# +#parser.add_option( "--add-collumn", +# metavar="Collumn", +# dest = "addcollumn", +# default=False, +# help = "Add a Collumn to Passfile") +# +#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)") +# +#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") + +(options, args) = parser.parse_args() +# }}} + +interface = INTERFACE() +interface.findPassword(args) + +# 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: <tre...@us...> - 2010-09-05 11:40:24
|
Revision: 309 http://spd.svn.sourceforge.net/spd/?rev=309&view=rev Author: treibholz Date: 2010-09-05 11:40:18 +0000 (Sun, 05 Sep 2010) Log Message: ----------- delEntry implemented Modified Paths: -------------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-09-05 11:34:04 UTC (rev 308) +++ branches/spd-ng/src/spdCore.py 2010-09-05 11:40:18 UTC (rev 309) @@ -33,13 +33,13 @@ vals += ':' + i + ', ' query += cols[0:-2] + ') VALUES ( ' + vals[0:-2] + ')' - print query self.dbc.execute(query,NewDict) # }}} def delEntry(self,ID): - pass + query = 'delete from '+ self.ConfigSection +' where __ID='+str(ID) + self.dbc.execute(query) 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. |
From: <Z3...@us...> - 2010-09-05 12:23:59
|
Revision: 310 http://spd.svn.sourceforge.net/spd/?rev=310&view=rev Author: Z3po Date: 2010-09-05 12:23:53 +0000 (Sun, 05 Sep 2010) Log Message: ----------- some minor changes to improve functionality. cleaned up the code a bit Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-09-05 11:40:18 UTC (rev 309) +++ branches/spd-ng/src/spdCLI.py 2010-09-05 12:23:53 UTC (rev 310) @@ -8,14 +8,23 @@ output = "normal" - def printPasswords(passdict): # {{{ - if output == 'normal': - for key in passdict: - print key + ':' + passdict[key].value + def printPasswords(self,passdict): # {{{ + """Print the passwords out of a dictionary. + # passdict: the dictionary full of passwords""" + + if type(passdict).__name__ != 'NoneType': + if self.output == 'normal': + for key in passdict: + print key + ':' + passdict[key].value + else: + print "No Results found" # }}} def findPasswordsInteractive(): # {{{ + """Create the searchString interactively""" + searchstring = raw_input("Please give your Searchstrings separated by whitespace") + return searchstring # }}} # }}} Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-09-05 11:40:18 UTC (rev 309) +++ branches/spd-ng/src/spdCheck.py 2010-09-05 12:23:53 UTC (rev 310) @@ -3,13 +3,16 @@ import spdConfig import os -class CHECK(object): # {{{ +class Check(object): # {{{ """This is the initcheck Configuration Module Checks if everything is there to perform :)""" spddir = os.path.expanduser('~/.spd/') def __init__(self,module): # {{{ + """Do the initial checks. + # module: which module called me??""" + if module == "spdInterface": self.checkSPDdir() self.checkConfigFile() @@ -18,42 +21,52 @@ # }}} def checkSPDdir(self): # {{{ + """Check if the spd directory exists""" + if not os.access(self.spddir, os.F_OK): os.mkdir(spddir) # }}} def checkConfigFile(self): # {{{ - config = spdConfig.CONFIG() + """Check the configfile.""" + + config = spdConfig.Config() if config.checkConfigFileExist(): if config.checkConfigFileReadable(): if config.hasSection("Main"): if config.getOption("Main","version"): - version = config.getSPDversion() + version = config.getConfigVersion() if version == "0.3": pass else: config.ErrorHandler("Where you got THIS version from???\nCannot work with") else: - config.setSPDversion("0.3") + config.setConfigVersion("0.3") else: config.setSection("Main") else: config.ErrorHandler("CONFIGFILE THERE BUT NOT READABLE") else: if config.checkConfigFileWriteable(): - newconfig = DEFAULTS() + newconfig = Defaults() newconfig.createDefaultConfig(config) else: config.ErrorHandler("CONFIGFILE PATH NOT WRITEABLE") # }}} + # }}} -class DEFAULTS(object): # {{{ +class Defaults(object): # {{{ + """Class to create default values.""" def createDefaultConfig(self,config): # {{{ + """Create the default config here. + # config: the configparser to use""" + config.setSection("Main") - config.setSPDversion("0.3") + config.setConfigVersion("0.3") # }}} + # }}} # EOF Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-09-05 11:40:18 UTC (rev 309) +++ branches/spd-ng/src/spdConfig.py 2010-09-05 12:23:53 UTC (rev 310) @@ -4,13 +4,15 @@ import os import sys -class CONFIG(object): # {{{ +class Config(object): # {{{ """This is the Configuration Module You can read or set config options""" configfile = os.path.expanduser('~/.spd/config') def ErrorHandler(self,message): # {{{ + """ErrorHandler of the Config Module. + # message: means the \'Exception\' to throw""" print "################################################" print "spdConfig ErrorHandler." print "Configfile: " + self.configfile @@ -20,6 +22,8 @@ # }}} def checkConfigFileExist(self): # {{{ + """Does the Config file exist?""" + if os.access(self.configfile, os.F_OK): return True else: @@ -27,6 +31,8 @@ # }}} def checkConfigFileWriteable(self): # {{{ + """Is the Config file writeable?""" + if not self.checkConfigFileExist(): open(self.configfile, 'w').close() if os.access(self.configfile,os.W_OK): @@ -36,6 +42,8 @@ # }}} def checkConfigFileReadable(self): # {{{ + """Is the Config file readable?""" + config = RawConfigParser() if not self.checkConfigFileExist(): self.ErrorHandler("CONFIGFILE MISSING") @@ -47,6 +55,9 @@ # }}} def writeConfigFile(self,config): # {{{ + """Write the Config given. + # config: the configobject.""" + configfile = open(self.configfile, 'wb') try: config.write(configfile) @@ -55,6 +66,9 @@ # }}} def hasSection(self,section): # {{{ + """Check if a given section exists. + # section: the given section.""" + config = self.checkConfigFileReadable() if not config: self.ErrorHandler("CONFIGFILE NOT READABLE") @@ -63,6 +77,9 @@ # }}} def setSection(self,section): # {{{ + """create a section if its not in configfile. + # section: the section to create.""" + if not self.checkConfigFileWriteable(): self.ErrorHandler("CONFIGFILE NOT WRITEABLE") config = self.hasSection(section) @@ -75,7 +92,21 @@ self.ErrorHandler("SECTION " + section + " already there") # }}} + def getSections(self): # {{{ + """Return all sections from configfile.""" + + config = self.checkConfigFileReadable() + if not config: + self.ErrorHandler("CONFIGFILE NOT READABLE") + else: + return config.sections() + + # }}} + def delSection(self,section): # {{{ + """delete a Section from configfile. + # section: the section to delete.""" + if not self.checkConfigFileWriteable(): self.ErrorHandler("CONFIGFILE NOT WRITEABLE") config = self.hasSection(section) @@ -87,6 +118,10 @@ # }}} def getOption(self,section,option): # {{{ + """Return the option from section. + # section: in which section is the option configured? + # option: option to return.""" + config = self.hasSection(section) if config: if config.has_option("Main","version"): @@ -98,6 +133,11 @@ # }}} def setOption(self,section,option,value): # {{{ + """Create or set the given option. + # section: section of the option. + # option: option to set/change. + # value: set the option to this value.""" + config = self.hasSection(section) if config: config.set(section,option,value) @@ -108,6 +148,10 @@ # }}} def delOption(self,section,option): # {{{ + """delete an option. + # section: which section holds the option? + # option: option to delete.""" + config = self.hasSection(section) if config: if self.getOption(section,option): @@ -120,7 +164,9 @@ return False # }}} - def getSPDversion(self): # {{{ + def getConfigVersion(self): # {{{ + """Return the config version.""" + option = self.getOption("Main","version") if option: return option @@ -128,7 +174,10 @@ self.ErrorHandler("Option version missing") # }}} - def setSPDversion(self,version): # {{{ + def setConfigVersion(self,version): # {{{ + """set the config version to the given version. + # version: version number.""" + self.setOption("Main","version",version) # }}} # }}} Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-09-05 11:40:18 UTC (rev 309) +++ branches/spd-ng/src/spdInterface.py 2010-09-05 12:23:53 UTC (rev 310) @@ -3,36 +3,48 @@ import spdCheck import spdCore import spdCLI +import string from optparse import OptionParser version = "0.3-alpha" -class INTERFACE(object): # {{{ +class Interface(object): # {{{ + """The Interface Module. + Connection between Output and Core.""" clientmode = "CLI" def __init__(self,clientmode="CLI"): # {{{ - """Do some checks before we start""" - check = spdCheck.CHECK("spdInterface") + """init procedure""" + + check = spdCheck.Check("spdInterface") del check if clientmode == 'CLI': self.client = spdCLI.CLI() + + self.core = spdCore.Core() # }}} - def findPasswords(searchString='%',interactive=False): # {{{ + def findPasswords(self,searchString='%',interactive=False): # {{{ """Find the passwords interactively or by searchlist handed. print the results in output format. - searchlist: optional list of keywords to search for - interactive: shall the interface ask for the keywords?""" + # searchlist: optional list of keywords to search for + # interactive: shall the interface ask for the keywords?""" if not interactive: + if type(searchString).__name__ == 'list': + searchlist = searchString + else: + searchlist = string.split(searchString) + else: + searchString = self.client.findPasswordsInteractive() searchlist = string.split(searchString) - else: - searchlist = self.client.findPasswordsInteractive() - passdict = spdCore.searchEntry(searchlist) - printPasswords(passdict) + if len(searchlist) == 0: + searchlist = ['%',] + passdict = self.core.searchEntry(searchlist) + self.client.printPasswords(passdict) # }}} @@ -100,8 +112,8 @@ (options, args) = parser.parse_args() # }}} -interface = INTERFACE() -interface.findPassword(args) +interface = Interface() +interface.findPasswords(args) # 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...> - 2010-09-05 17:06:10
|
Revision: 313 http://spd.svn.sourceforge.net/spd/?rev=313&view=rev Author: Z3po Date: 2010-09-05 17:06:04 +0000 (Sun, 05 Sep 2010) Log Message: ----------- added findPassword function and also possibility to add entries Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-09-05 13:05:18 UTC (rev 312) +++ branches/spd-ng/src/spdCLI.py 2010-09-05 17:06:04 UTC (rev 313) @@ -12,21 +12,43 @@ """Print the passwords out of a dictionary. # passdict: the dictionary full of passwords""" - if type(passdict).__name__ != 'NoneType': + if type(passdict).__name__ != 'NoneType' and len(passdict) != 0: if self.output == 'normal': - for key in passdict: - print key + ':' + passdict[key].value + 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) + ': ' + passdict[key][i] + else: + print key.ljust(length) + ': ' + print "" else: print "No Results found" # }}} - def findPasswordsInteractive(): # {{{ + def findPasswordsInteractive(self): # {{{ """Create the searchString interactively""" searchstring = raw_input("Please give your Searchstrings separated by whitespace") return searchstring # }}} - + + def createEntry(self,columns): # {{{ + Entry = {} + print "Adding a new Entry to our passfile" + for column in columns: + value = raw_input(column + ': ') + Entry.update({ column : value }) + return Entry + # }}} + # }}} # EOF Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-09-05 13:05:18 UTC (rev 312) +++ branches/spd-ng/src/spdInterface.py 2010-09-05 17:06:04 UTC (rev 313) @@ -47,6 +47,10 @@ self.client.printPasswords(passdict) # }}} + def addEntry(self): # {{{ + Entry = self.client.createEntry(self.core.getColumns()) + self.core.addEntry(Entry) + # }}} # }}} @@ -75,12 +79,12 @@ # dest ="id", # help ="Show Password by ID") # -#parser.add_option( "-a", "--add", -# action="store_true", -# dest = "add", -# default=False, -# help = "Add an Entry") -# +parser.add_option( "-a", "--add", + action="store_true", + dest = "add", + default=False, + help = "Add an Entry") + #parser.add_option( "--add-collumn", # metavar="Collumn", # dest = "addcollumn", @@ -113,6 +117,10 @@ # }}} interface = Interface() + +if options.add: + interface.addEntry() + interface.findPasswords(args) # EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-09-07 16:08:46
|
Revision: 314 http://spd.svn.sourceforge.net/spd/?rev=314&view=rev Author: Z3po Date: 2010-09-07 16:08:32 +0000 (Tue, 07 Sep 2010) Log Message: ----------- started to seperate CLI from INTERFACE because it also could be GUI or anything like. Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-09-05 17:06:04 UTC (rev 313) +++ branches/spd-ng/src/spdCLI.py 2010-09-07 16:08:32 UTC (rev 314) @@ -1,6 +1,7 @@ #!/usr/bin/python import string +from optparse import OptionParser class CLI(object): # {{{ """This is the CLI Module. @@ -49,6 +50,72 @@ return Entry # }}} + def getParser(self,version): # {{{ + parser = OptionParser( "%prog [Options] [Keywords]", + description = "SPD - Simple Password Displayer", + version = version, + epilog = "With no parameters it will print out everything!") + + #parser.add_option( "-d", "--delete", + # metavar="Keywords", + # dest ="delete", + # help ="Entries to delete") + # + #parser.add_option( "-e", "--edit", + # metavar="ID", + # dest ="edit", + # help ="ID to edit") + # + #parser.add_option( "-i", "--delete-id", + # metavar="ID", + # dest ="deleteID", + # help ="ID to delete") + # + #parser.add_option( "--id", + # dest ="id", + # help ="Show Password by ID") + # + parser.add_option( "-a", "--add", + action="store_true", + dest = "add", + default=False, + help = "Add an Entry") + + #parser.add_option( "--add-collumn", + # metavar="Collumn", + # dest = "addcollumn", + # default=False, + # help = "Add a Collumn to Passfile") + # + #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)") + # + #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") + + return parser + # }}} + + def main(self,options,args): # {{{ + pass + # }}} + # }}} # EOF Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-09-05 17:06:04 UTC (rev 313) +++ branches/spd-ng/src/spdInterface.py 2010-09-07 16:08:32 UTC (rev 314) @@ -52,76 +52,22 @@ self.core.addEntry(Entry) # }}} -# }}} + def main(self,version): # {{{ + parser = self.client.getParser(version) -# {{{ OptionParser stuff -parser = OptionParser( "%prog [Options] [Keywords]", - description = "SPD - Simple Password Displayer", - version = version, - epilog = "With no parameters it will print out everything!") + (options, args) = parser.parse_args() -#parser.add_option( "-d", "--delete", -# metavar="Keywords", -# dest ="delete", -# help ="Entries to delete") -# -#parser.add_option( "-e", "--edit", -# metavar="ID", -# dest ="edit", -# help ="ID to edit") -# -#parser.add_option( "-i", "--delete-id", -# metavar="ID", -# dest ="deleteID", -# help ="ID to delete") -# -#parser.add_option( "--id", -# dest ="id", -# help ="Show Password by ID") -# -parser.add_option( "-a", "--add", - action="store_true", - dest = "add", - default=False, - help = "Add an Entry") + if options.add: + interface.addEntry() + + interface.findPasswords(args) + # }}} -#parser.add_option( "--add-collumn", -# metavar="Collumn", -# dest = "addcollumn", -# default=False, -# help = "Add a Collumn to Passfile") -# -#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)") -# -#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") - -(options, args) = parser.parse_args() # }}} interface = Interface() +interface.main(version) -if options.add: - interface.addEntry() - -interface.findPasswords(args) # 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...> - 2010-09-07 20:42:16
|
Revision: 315 http://spd.svn.sourceforge.net/spd/?rev=315&view=rev Author: z3po Date: 2010-09-07 20:42:10 +0000 (Tue, 07 Sep 2010) Log Message: ----------- completly seperated the CLI from the INTERFACE. much more scalable right now :) Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-09-07 16:08:32 UTC (rev 314) +++ branches/spd-ng/src/spdCLI.py 2010-09-07 20:42:10 UTC (rev 315) @@ -3,8 +3,8 @@ import string from optparse import OptionParser -class CLI(object): # {{{ - """This is the CLI Module. +class Cli(object): # {{{ + """This is the Cli Module. Resistance is Futile""" output = "normal" @@ -40,7 +40,7 @@ searchstring = raw_input("Please give your Searchstrings separated by whitespace") return searchstring # }}} - + def createEntry(self,columns): # {{{ Entry = {} print "Adding a new Entry to our passfile" @@ -50,12 +50,13 @@ return Entry # }}} - def getParser(self,version): # {{{ + def parseArgs(self,version,columns): # {{{ parser = OptionParser( "%prog [Options] [Keywords]", - description = "SPD - Simple Password Displayer", - version = version, - epilog = "With no parameters it will print out everything!") - + description = "SPD - Simple Password Displayer - CLI", + version = "SPD " + version, + epilog = """With no parameters it will print out everything! + Please report Bugs or Feature Request at http://spd.sourceforge.net""") + #parser.add_option( "-d", "--delete", # metavar="Keywords", # dest ="delete", @@ -81,9 +82,9 @@ default=False, help = "Add an Entry") - #parser.add_option( "--add-collumn", + #parser.add_option( "--add-column", # metavar="Collumn", - # dest = "addcollumn", + # dest = "addcolumn", # default=False, # help = "Add a Collumn to Passfile") # @@ -109,7 +110,13 @@ # dest = "passfile", # help = "do not use the confgured passfile but the one given here") - return parser + (options, args) = parser.parse_args() + + if options.add: + Entry = self.createEntry(columns) + return ["addEntry", Entry] + + return ["findPasswords", args] # }}} def main(self,options,args): # {{{ Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-09-07 16:08:32 UTC (rev 314) +++ branches/spd-ng/src/spdInterface.py 2010-09-07 20:42:10 UTC (rev 315) @@ -4,7 +4,6 @@ import spdCore import spdCLI import string -from optparse import OptionParser version = "0.3-alpha" @@ -12,33 +11,28 @@ """The Interface Module. Connection between Output and Core.""" - clientmode = "CLI" - - def __init__(self,clientmode="CLI"): # {{{ + def __init__(self,version,clientmode="CLI"): # {{{ """init procedure""" + self.version = version + check = spdCheck.Check("spdInterface") del check if clientmode == 'CLI': - self.client = spdCLI.CLI() + self.client = spdCLI.Cli() self.core = spdCore.Core() # }}} - def findPasswords(self,searchString='%',interactive=False): # {{{ - """Find the passwords interactively or by searchlist handed. + def findPasswords(self,searchString='%'): # {{{ + """Find the passwords by searchlist handed. print the results in output format. - # searchlist: optional list of keywords to search for - # interactive: shall the interface ask for the keywords?""" + # searchlist: optional string or list of keywords to search for.""" - if not interactive: - if type(searchString).__name__ == 'list': - searchlist = searchString - else: - searchlist = string.split(searchString) + if type(searchString).__name__ == 'list': + searchlist = searchString else: - searchString = self.client.findPasswordsInteractive() searchlist = string.split(searchString) if len(searchlist) == 0: @@ -47,26 +41,19 @@ self.client.printPasswords(passdict) # }}} - def addEntry(self): # {{{ - Entry = self.client.createEntry(self.core.getColumns()) + def addEntry(self,Entry): # {{{ self.core.addEntry(Entry) # }}} - def main(self,version): # {{{ - parser = self.client.getParser(version) - - (options, args) = parser.parse_args() - - if options.add: - interface.addEntry() - - interface.findPasswords(args) + def main(self): # {{{ + function, value = self.client.parseArgs(self.version,self.core.getColumns()) + getattr(self, function)(value) # }}} # }}} -interface = Interface() -interface.main(version) +interface = Interface(version) +interface.main() # EOF This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <z3...@us...> - 2010-09-12 21:29:29
|
Revision: 316 http://spd.svn.sourceforge.net/spd/?rev=316&view=rev Author: z3po Date: 2010-09-12 21:29:23 +0000 (Sun, 12 Sep 2010) Log Message: ----------- added clientmode option in configfile Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-09-07 20:42:10 UTC (rev 315) +++ branches/spd-ng/src/spdCLI.py 2010-09-12 21:29:23 UTC (rev 316) @@ -1,6 +1,5 @@ #!/usr/bin/python -import string from optparse import OptionParser class Cli(object): # {{{ Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-09-07 20:42:10 UTC (rev 315) +++ branches/spd-ng/src/spdCheck.py 2010-09-12 21:29:23 UTC (rev 316) @@ -8,6 +8,7 @@ Checks if everything is there to perform :)""" spddir = os.path.expanduser('~/.spd/') + config = spdConfig.Config() def __init__(self,module): # {{{ """Do the initial checks. @@ -16,6 +17,7 @@ if module == "spdInterface": self.checkSPDdir() self.checkConfigFile() + self.getClientmode() elif module == "spdCore": pass # }}} @@ -30,7 +32,7 @@ def checkConfigFile(self): # {{{ """Check the configfile.""" - config = spdConfig.Config() + config = self.config if config.checkConfigFileExist(): if config.checkConfigFileReadable(): if config.hasSection("Main"): @@ -54,6 +56,14 @@ config.ErrorHandler("CONFIGFILE PATH NOT WRITEABLE") # }}} + def getClientmode(self): + config = self.config + if config.getOption('Main','clientmode'): + self.clientmode = config.getOption('Main','clientmode') + else: + config.setOption('Main','clientmode','CLI') + self.clientmode = config.getOption('Main','clientmode') + # }}} class Defaults(object): # {{{ Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-09-07 20:42:10 UTC (rev 315) +++ branches/spd-ng/src/spdConfig.py 2010-09-12 21:29:23 UTC (rev 316) @@ -124,8 +124,8 @@ config = self.hasSection(section) if config: - if config.has_option("Main","version"): - return config.get("Main","version") + if config.has_option(section,option): + return config.get(section,option) else: return False else: Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-09-07 20:42:10 UTC (rev 315) +++ branches/spd-ng/src/spdInterface.py 2010-09-12 21:29:23 UTC (rev 316) @@ -4,6 +4,7 @@ import spdCore import spdCLI import string +from sys import exit version = "0.3-alpha" @@ -11,16 +12,24 @@ """The Interface Module. Connection between Output and Core.""" - def __init__(self,version,clientmode="CLI"): # {{{ + def __init__(self,version,clientmode=False): # {{{ """init procedure""" self.version = version - check = spdCheck.Check("spdInterface") - del check + initcheck = spdCheck.Check("spdInterface") + if not clientmode: + if initcheck.clientmode: + clientmode = initcheck.clientmode + else: + clientmode = 'CLI' + del initcheck if clientmode == 'CLI': self.client = spdCLI.Cli() + else: + print 'CLIENTMODE \'not yet\' available' + exit(2) self.core = spdCore.Core() # }}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <z3...@us...> - 2010-09-15 20:01:39
|
Revision: 317 http://spd.svn.sourceforge.net/spd/?rev=317&view=rev Author: z3po Date: 2010-09-15 20:01:33 +0000 (Wed, 15 Sep 2010) Log Message: ----------- included --delete-id and --delete Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-09-12 21:29:23 UTC (rev 316) +++ branches/spd-ng/src/spdCLI.py 2010-09-15 20:01:33 UTC (rev 317) @@ -4,7 +4,7 @@ class Cli(object): # {{{ """This is the Cli Module. - Resistance is Futile""" + Resistance is futile""" output = "normal" @@ -33,13 +33,6 @@ print "No Results found" # }}} - def findPasswordsInteractive(self): # {{{ - """Create the searchString interactively""" - - searchstring = raw_input("Please give your Searchstrings separated by whitespace") - return searchstring - # }}} - def createEntry(self,columns): # {{{ Entry = {} print "Adding a new Entry to our passfile" @@ -56,21 +49,23 @@ epilog = """With no parameters it will print out everything! Please report Bugs or Feature Request at http://spd.sourceforge.net""") - #parser.add_option( "-d", "--delete", - # metavar="Keywords", - # dest ="delete", - # help ="Entries to delete") - # + parser.add_option( "-d", "--delete", + action = "store_true", + dest ="delete", + default = False, + help ="Entries to delete") + #parser.add_option( "-e", "--edit", # metavar="ID", # dest ="edit", # help ="ID to edit") # - #parser.add_option( "-i", "--delete-id", - # metavar="ID", - # dest ="deleteID", - # help ="ID to delete") - # + parser.add_option( "-i", "--delete-id", + action = "store_true", + dest ="deleteID", + default = False, + help ="ID(s) to delete") + #parser.add_option( "--id", # dest ="id", # help ="Show Password by ID") @@ -114,8 +109,12 @@ if options.add: Entry = self.createEntry(columns) return ["addEntry", Entry] + elif options.delete: + return ["deleteEntry", args] + elif options.deleteID: + return ["deleteID", args] - return ["findPasswords", args] + return ["printPasswords", args] # }}} def main(self,options,args): # {{{ Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-09-12 21:29:23 UTC (rev 316) +++ branches/spd-ng/src/spdInterface.py 2010-09-15 20:01:33 UTC (rev 317) @@ -35,8 +35,8 @@ # }}} def findPasswords(self,searchString='%'): # {{{ - """Find the passwords by searchlist handed. - print the results in output format. + """Find the passwords by searchlist/searchstring handed. + print the results in CLIENTMODE. # searchlist: optional string or list of keywords to search for.""" if type(searchString).__name__ == 'list': @@ -47,9 +47,30 @@ if len(searchlist) == 0: searchlist = ['%',] passdict = self.core.searchEntry(searchlist) + return passdict + # }}} + + def printPasswords(self,searchString='%'): # {{{ + passdict = self.findPasswords(searchString) self.client.printPasswords(passdict) # }}} + def deleteID(self,ids): # {{{ + if type(ids).__name__ != 'list': + if type(ids).__name__ == 'int': + ids = str(ids) + ids = string.split(ids) + for id in ids: + self.core.delEntry(id) + # }}} + + def deleteEntry(self,searchString): # {{{ + passdict = self.findPasswords(searchString) + print str(passdict) + for id in passdict["__ID"]: + self.core.delEntry(id) + # }}} + def addEntry(self,Entry): # {{{ self.core.addEntry(Entry) # }}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-11-28 01:01:57
|
Revision: 318 http://spd.svn.sourceforge.net/spd/?rev=318&view=rev Author: Z3po Date: 2010-11-28 01:01:51 +0000 (Sun, 28 Nov 2010) Log Message: ----------- used atexit to make sure changes are written back upon exit Modified Paths: -------------- branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-09-15 20:01:33 UTC (rev 317) +++ branches/spd-ng/src/spdCheck.py 2010-11-28 01:01:51 UTC (rev 318) @@ -38,12 +38,12 @@ if config.hasSection("Main"): if config.getOption("Main","version"): version = config.getConfigVersion() - if version == "0.3": + if version == "0.3-alpha": pass else: config.ErrorHandler("Where you got THIS version from???\nCannot work with") else: - config.setConfigVersion("0.3") + config.setConfigVersion("0.3-alpha") else: config.setSection("Main") else: @@ -74,7 +74,8 @@ # config: the configparser to use""" config.setSection("Main") - config.setConfigVersion("0.3") + config.setConfigVersion("0.3-alpha") + config.setClientMode("CLI") # }}} # }}} Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-09-15 20:01:33 UTC (rev 317) +++ branches/spd-ng/src/spdConfig.py 2010-11-28 01:01:51 UTC (rev 318) @@ -180,6 +180,14 @@ self.setOption("Main","version",version) # }}} + + def setClientMode(self,clientmode): # {{{ + """set the clientmode. + # clientmode: clientmode to use.""" + + self.setOption("Main","clientmode",clientmode) + # }}} + # }}} # EOF Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-09-15 20:01:33 UTC (rev 317) +++ branches/spd-ng/src/spdCore.py 2010-11-28 01:01:51 UTC (rev 318) @@ -1,9 +1,15 @@ #!/usr/bin/python import sqlite3 +import atexit class Core(object): + # Writes back to the Store + def __commit(self): # {{{ + self.db.commit() + #}}} + # create the database from the stuff out of the store def __init__(self,ConfigSection='Main',PasswordColumn='Password'): # {{{ self.ConfigSection = ConfigSection @@ -13,15 +19,9 @@ self.dbc = self.db.cursor() self.deletedColumns = [] - + atexit.register(self.__commit) # Make Sure to Write back changes to sqldb exiting # }}} - # Writes back to the Store - def __del__(self): # {{{ - self.db.commit() - - #}}} - def __sql2dict(self,cursor,row): # {{{ result = {} for ColumnNr, Column in enumerate(cursor.description): @@ -31,7 +31,7 @@ # }}} - def searchEntry(self,SearchList): + def searchEntry(self,SearchList): # {{{ query = 'select * from ' + self.ConfigSection + ' where ' @@ -59,6 +59,7 @@ return result + # }}} def addEntry(self,NewDict): # {{{ query = 'insert into ' + self.ConfigSection + '( ' @@ -80,7 +81,6 @@ # }}} - def getColumns(self): # {{{ query = "pragma Table_info('" + self.ConfigSection + "')" 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. |
From: <Z3...@us...> - 2010-11-28 12:16:42
|
Revision: 319 http://spd.svn.sourceforge.net/spd/?rev=319&view=rev Author: Z3po Date: 2010-11-28 12:16:35 +0000 (Sun, 28 Nov 2010) Log Message: ----------- reworked Config and Check Module Modified Paths: -------------- branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdInterface.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-11-28 01:01:51 UTC (rev 318) +++ branches/spd-ng/src/spdCheck.py 2010-11-28 12:16:35 UTC (rev 319) @@ -15,14 +15,22 @@ # module: which module called me??""" if module == "spdInterface": - self.checkSPDdir() - self.checkConfigFile() - self.getClientmode() + self.__checkSPDdir() elif module == "spdCore": pass # }}} - def checkSPDdir(self): # {{{ + def __ErrorHandler(self, message): # {{{ + '''ErrorHandler of the Check Module. + # message: means the \'Exception\' to throw''' + print '################################################' + print 'spdCheck ErrorHandler.' + print 'ERRORMESSAGE: ' + message + print '################################################' + sys.exit(2) + # }}} + + def __checkSPDdir(self): # {{{ """Check if the spd directory exists""" if not os.access(self.spddir, os.F_OK): @@ -33,37 +41,27 @@ """Check the configfile.""" config = self.config - if config.checkConfigFileExist(): - if config.checkConfigFileReadable(): - if config.hasSection("Main"): - if config.getOption("Main","version"): - version = config.getConfigVersion() - if version == "0.3-alpha": - pass - else: - config.ErrorHandler("Where you got THIS version from???\nCannot work with") - else: - config.setConfigVersion("0.3-alpha") - else: - config.setSection("Main") - else: - config.ErrorHandler("CONFIGFILE THERE BUT NOT READABLE") - else: - if config.checkConfigFileWriteable(): - newconfig = Defaults() - newconfig.createDefaultConfig(config) - else: - config.ErrorHandler("CONFIGFILE PATH NOT WRITEABLE") - # }}} - def getClientmode(self): - config = self.config - if config.getOption('Main','clientmode'): - self.clientmode = config.getOption('Main','clientmode') - else: - config.setOption('Main','clientmode','CLI') - self.clientmode = config.getOption('Main','clientmode') + reval, version = config.getConfigVersion(raw=True) + if reval > 0 and reval < 64: + Defaults.createDefaultConfig(config) + elif reval == 64: + print 'ConfigVersion not found...setting Default one\n' + config.setConfigVersion('0.3-alpha') + version = config.getConfigVersion() + + reval, clientmode = config.getClientmode(raw=True) + + if reval > 0: + config.setClientmode('CLI') + clientmode = config.getClientmode() + + return({ 'version' : version, + 'clientmode' : clientmode }) + + # }}} + # }}} class Defaults(object): # {{{ @@ -73,9 +71,9 @@ """Create the default config here. # config: the configparser to use""" - config.setSection("Main") - config.setConfigVersion("0.3-alpha") - config.setClientMode("CLI") + config.addConfigSection('Main') + config.setConfigVersion('0.3-alpha') + config.setClientmode('CLI') # }}} # }}} Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-11-28 01:01:51 UTC (rev 318) +++ branches/spd-ng/src/spdConfig.py 2010-11-28 12:16:35 UTC (rev 319) @@ -5,12 +5,20 @@ import sys class Config(object): # {{{ - """This is the Configuration Module - You can read or set config options""" + '''This is the Configuration Module + You can read or set config options''' - configfile = os.path.expanduser('~/.spd/config') + 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' } - def ErrorHandler(self,message): # {{{ + def __init__(self, conffile='~/.spd/config'): + self.configfile = os.path.expanduser(conffile) + + def __ErrorHandler(self,message): # {{{ """ErrorHandler of the Config Module. # message: means the \'Exception\' to throw""" print "################################################" @@ -21,171 +29,251 @@ sys.exit(2) # }}} - def checkConfigFileExist(self): # {{{ + def __checkConfigFileExist(self): # {{{ """Does the Config file exist?""" if os.access(self.configfile, os.F_OK): - return True + return 0 else: - return False + return 2 # }}} - def checkConfigFileWriteable(self): # {{{ - """Is the Config file writeable?""" + def __checkConfigFileReadable(self): # {{{ + """Is the Config file readable?""" - if not self.checkConfigFileExist(): - open(self.configfile, 'w').close() - if os.access(self.configfile,os.W_OK): - return True - else: - return False - # }}} + reval = self.__checkConfigFileExist() - def checkConfigFileReadable(self): # {{{ - """Is the Config file readable?""" + if reval > 0: + return reval, None config = RawConfigParser() - if not self.checkConfigFileExist(): - self.ErrorHandler("CONFIGFILE MISSING") + if os.access(self.configfile,os.R_OK): config.read(self.configfile) - return config + return 0,config else: - return False + return 4, None # }}} - def writeConfigFile(self,config): # {{{ - """Write the Config given. - # config: the configobject.""" + def __checkConfigFileWriteable(self): # {{{ + """Is the Config file writeable?""" - configfile = open(self.configfile, 'wb') + reval = self.__checkConfigFileExist() + + if reval > 0: + return reval, None + + if os.access(self.configfile,os.W_OK): + configfile = open(self.configfile, 'wb') + return 0, configfile + else: + return 8, None + # }}} + + def __writeConfigFile(self,config): # {{{ + '''Write the Config given. + # config: the configobject.''' + + reval, configfile = self.__checkConfigFileWriteable() + if reval > 0: + return reval + try: config.write(configfile) except Exception, e: - self.ErrorHandler("An Error Occured" + str(e)) + return 16 # }}} - def hasSection(self,section): # {{{ + def __hasSection(self,section): # {{{ """Check if a given section exists. # section: the given section.""" - config = self.checkConfigFileReadable() - if not config: - self.ErrorHandler("CONFIGFILE NOT READABLE") + reval, config = self.__checkConfigFileReadable() + if reval > 0: + return reval, None + if config.has_section(section): - return config + return 0, config + + return 32, config # }}} - def setSection(self,section): # {{{ + def __addSection(self,section): # {{{ """create a section if its not in configfile. # section: the section to create.""" - if not self.checkConfigFileWriteable(): - self.ErrorHandler("CONFIGFILE NOT WRITEABLE") - config = self.hasSection(section) - if not config: - config = self.checkConfigFileReadable() - config.add_section(section) - self.writeConfigFile(config) - return True - else: - self.ErrorHandler("SECTION " + section + " already there") + reval, config = self.__hasSection() + + if reval > 0 and reval < 32: + return reval + + config.add_section(section) + reval = self.__writeConfigFile(config) + + if reval > 0: + return reval + + return 0 # }}} - def getSections(self): # {{{ + def __listSections(self): # {{{ """Return all sections from configfile.""" - config = self.checkConfigFileReadable() - if not config: - self.ErrorHandler("CONFIGFILE NOT READABLE") - else: - return config.sections() + reval, config = self.__checkConfigFileReadable() + + if reval > 0: + return reval, None + + return 0, config.sections() # }}} - def delSection(self,section): # {{{ + def __delSection(self,section): # {{{ """delete a Section from configfile. # section: the section to delete.""" - if not self.checkConfigFileWriteable(): - self.ErrorHandler("CONFIGFILE NOT WRITEABLE") - config = self.hasSection(section) - if config: - config.remove_section(section) - return True - else: - return False + reval, config = self.__hasSection(section) + + if reval > 0 and reval < 32: + return reval + + config.remove_section(section) + reval = self.__writeConfigFile(config) + + if reval > 0: + return reval + + return 0 # }}} - def getOption(self,section,option): # {{{ + def __getOption(self,section,option): # {{{ """Return the option from section. # section: in which section is the option configured? # option: option to return.""" - config = self.hasSection(section) - if config: - if config.has_option(section,option): - return config.get(section,option) - else: - return False + reval, config = self.__hasSection(section) + + if reval > 0: + return reval, None + + if config.has_option(section,option): + return 0, config.get(section,option) else: - self.ErrorHandler("SECTION " + section + " MISSING") + return 64, None # }}} - def setOption(self,section,option,value): # {{{ + def __setOption(self,section,option,value): # {{{ """Create or set the given option. # section: section of the option. # option: option to set/change. # value: set the option to this value.""" - config = self.hasSection(section) - if config: - config.set(section,option,value) - self.writeConfigFile(config) - return True - else: - self.ErrorHandler("SECTION " + section + " MISSING") + reval, config = self.__hasSection(section) + + if reval > 0: + return reval + + config.set(section,option,value) + reval = self.__writeConfigFile(config) + + if reval > 0: + return reval + + return 0 # }}} - def delOption(self,section,option): # {{{ + def __delOption(self,section,option): # {{{ """delete an option. # section: which section holds the option? # option: option to delete.""" - config = self.hasSection(section) - if config: - if self.getOption(section,option): - config.remove_option(section,option) - self.writeConfigFile(config) - return True - else: - return False - else: - return False + reval, config = self.__hasSection(section) + + if reval > 0: + return reval + + reval, option = self.__getOption(section,option) + + if reval > 0: + return reval + + config.remove_option(section,option) + reval = self.__writeConfigFile(config) + + if reval > 0: + return reval + + return 0 + # }}} - def getConfigVersion(self): # {{{ + def addConfigSection(self): # {{{ + reval = self.__addSection('Main') + + if reval > 0: + self.__ErrorHandler(self.ReturnCodes[reval]) + + # }}} + + def getConfigVersion(self, raw=False): # {{{ """Return the config version.""" - option = self.getOption("Main","version") - if option: - return option - else: - self.ErrorHandler("Option version missing") + reval, option = self.__getOption("Main","version") + + if reval > 2 and reval < 32: + self.__ErrorHandler(self.ReturnCodes[reval]) # don't tolerate These + + if reval > 0: + if raw: + return reval, None + + self.__ErrorHandler(self.ReturnCodes[reval]) + + if raw: + return reval, option + + return option # }}} def setConfigVersion(self,version): # {{{ """set the config version to the given version. # version: version number.""" - self.setOption("Main","version",version) + reval = self.__setOption("Main","version",version) + + if reval > 0: + self.__ErrorHandler(self.ReturnCodes[reval]) # }}} - def setClientMode(self,clientmode): # {{{ + def getClientmode(self, raw=False): # {{{ + '''get the clientmode. + # return the clientmode option''' + + reval, clientmode = self.__getOption('Main', 'clientmode') + + if reval > 0 and reval < 64: + self.__ErrorHandler(self.ReturnCodes[reval]) + + if reval > 0: + if raw: + return reval, None + else: + self.__ErrorHandler(self.ReturnCodes[reval]) + + if raw: + return reval, clientmode + + return clientmode + # }}} + + def setClientmode(self,clientmode): # {{{ """set the clientmode. # clientmode: clientmode to use.""" - self.setOption("Main","clientmode",clientmode) + reval = self.__setOption("Main","clientmode",clientmode) + + if reval > 0: + self.__ErrorHandler(self.ReturnCodes[reval]) # }}} # }}} Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-11-28 01:01:51 UTC (rev 318) +++ branches/spd-ng/src/spdInterface.py 2010-11-28 12:16:35 UTC (rev 319) @@ -2,30 +2,30 @@ import spdCheck import spdCore -import spdCLI import string from sys import exit -version = "0.3-alpha" - class Interface(object): # {{{ """The Interface Module. Connection between Output and Core.""" + version = None + client = None + core = None - def __init__(self,version,clientmode=False): # {{{ + def __init__(self,clientmode=False): # {{{ """init procedure""" - self.version = version + check = spdCheck.Check("spdInterface") + initcheck = check.checkConfigFile() - initcheck = spdCheck.Check("spdInterface") + self.version = initcheck['version'] if not clientmode: - if initcheck.clientmode: - clientmode = initcheck.clientmode - else: - clientmode = 'CLI' + clientmode = initcheck['clientmode'] + del initcheck if clientmode == 'CLI': + import spdCLI self.client = spdCLI.Cli() else: print 'CLIENTMODE \'not yet\' available' @@ -82,7 +82,7 @@ # }}} -interface = Interface(version) +interface = Interface() interface.main() 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. |
From: <Z3...@us...> - 2010-11-29 09:38:38
|
Revision: 320 http://spd.svn.sourceforge.net/spd/?rev=320&view=rev Author: Z3po Date: 2010-11-29 09:38:31 +0000 (Mon, 29 Nov 2010) Log Message: ----------- cleanup Modified Paths: -------------- branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdInterface.py Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-11-28 12:16:35 UTC (rev 319) +++ branches/spd-ng/src/spdCheck.py 2010-11-29 09:38:31 UTC (rev 320) @@ -14,10 +14,7 @@ """Do the initial checks. # module: which module called me??""" - if module == "spdInterface": - self.__checkSPDdir() - elif module == "spdCore": - pass + self.module = 'spdInterface' # }}} def __ErrorHandler(self, message): # {{{ @@ -30,35 +27,35 @@ sys.exit(2) # }}} - def __checkSPDdir(self): # {{{ - """Check if the spd directory exists""" + def startupCheck(self): # {{{ + """Do initial checks""" - if not os.access(self.spddir, os.F_OK): - os.mkdir(spddir) - # }}} + if self.module == 'spdInterface': - def checkConfigFile(self): # {{{ - """Check the configfile.""" + if not os.access(self.spddir, os.F_OK): + os.mkdir(spddir) - config = self.config + config = self.config - reval, version = config.getConfigVersion(raw=True) + reval, version = config.getConfigVersion(raw=True) - if reval > 0 and reval < 64: - Defaults.createDefaultConfig(config) - elif reval == 64: - print 'ConfigVersion not found...setting Default one\n' - config.setConfigVersion('0.3-alpha') - version = config.getConfigVersion() + if reval > 0 and reval < 64: + Defaults.createDefaultConfig(config) + elif reval == 64: + print 'ConfigVersion not found...setting Default one\n' + config.setConfigVersion('0.3-alpha') + version = config.getConfigVersion() - reval, clientmode = config.getClientmode(raw=True) - - if reval > 0: - config.setClientmode('CLI') - clientmode = config.getClientmode() + reval, clientmode = config.getClientmode(raw=True) + + if reval > 0: + config.setClientmode('CLI') + clientmode = config.getClientmode() - return({ 'version' : version, + return({ 'version' : version, 'clientmode' : clientmode }) + else: + return True # }}} Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-11-28 12:16:35 UTC (rev 319) +++ branches/spd-ng/src/spdInterface.py 2010-11-29 09:38:31 UTC (rev 320) @@ -16,7 +16,7 @@ """init procedure""" check = spdCheck.Check("spdInterface") - initcheck = check.checkConfigFile() + initcheck = check.startupCheck() self.version = initcheck['version'] if not clientmode: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-12-11 00:40:26
|
Revision: 321 http://spd.svn.sourceforge.net/spd/?rev=321&view=rev Author: Z3po Date: 2010-12-11 00:40:20 +0000 (Sat, 11 Dec 2010) Log Message: ----------- added ErrorHandler to Interface Class, added spd-cli to call interface, fixed function to add entries Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdConfig.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-11-29 09:38:31 UTC (rev 320) +++ branches/spd-ng/src/spdCLI.py 2010-12-11 00:40:20 UTC (rev 321) @@ -6,14 +6,14 @@ """This is the Cli Module. Resistance is futile""" - output = "normal" + __outmode = None def printPasswords(self,passdict): # {{{ """Print the passwords out of a dictionary. # passdict: the dictionary full of passwords""" if type(passdict).__name__ != 'NoneType' and len(passdict) != 0: - if self.output == 'normal': + if self.__outmode == 'lines': length = 0 for key in passdict.keys(): if length < len(key): @@ -29,6 +29,8 @@ else: print key.ljust(length) + ': ' print "" + elif self.__outmode == 'wide': + print 'NOT YET IMPLEMENTED...SORRY' else: print "No Results found" # }}} @@ -42,7 +44,8 @@ return Entry # }}} - def parseArgs(self,version,columns): # {{{ + def parseArgs(self,version): # {{{ + __ouput="lines" parser = OptionParser( "%prog [Options] [Keywords]", description = "SPD - Simple Password Displayer - CLI", version = "SPD " + version, @@ -88,12 +91,12 @@ # 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)") + #parser.add_option( "-l", "--local", # action="store_true", # dest = "localStore", @@ -107,13 +110,17 @@ (options, args) = parser.parse_args() if options.add: - Entry = self.createEntry(columns) - return ["addEntry", Entry] + return ["addEntry", args] elif options.delete: return ["deleteEntry", args] elif options.deleteID: return ["deleteID", args] + elif options.widemode: + self.__outmode = 'wide' + else: + self.__outmode = 'lines' + return ["printPasswords", args] # }}} Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-11-29 09:38:31 UTC (rev 320) +++ branches/spd-ng/src/spdConfig.py 2010-12-11 00:40:20 UTC (rev 321) @@ -15,8 +15,9 @@ 32 : 'Section not found', 64 : 'Option not found' } - def __init__(self, conffile='~/.spd/config'): + def __init__(self, conffile='~/.spd/config'): # {{{ self.configfile = os.path.expanduser(conffile) + # }}} def __ErrorHandler(self,message): # {{{ """ErrorHandler of the Config Module. Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-11-29 09:38:31 UTC (rev 320) +++ branches/spd-ng/src/spdCore.py 2010-12-11 00:40:20 UTC (rev 321) @@ -81,13 +81,15 @@ # }}} - def getColumns(self): # {{{ - + def getColumns(self,__showid=True): # {{{ + query = "pragma Table_info('" + self.ConfigSection + "')" 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']) Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-11-29 09:38:31 UTC (rev 320) +++ branches/spd-ng/src/spdInterface.py 2010-12-11 00:40:20 UTC (rev 321) @@ -34,6 +34,17 @@ self.core = spdCore.Core() # }}} + 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 findPasswords(self,searchString='%'): # {{{ """Find the passwords by searchlist/searchstring handed. print the results in CLIENTMODE. @@ -56,6 +67,8 @@ # }}} def deleteID(self,ids): # {{{ + if not ids: + self.__ErrorHandler('deleteID()','No ID to delete given') if type(ids).__name__ != 'list': if type(ids).__name__ == 'int': ids = str(ids) @@ -71,20 +84,18 @@ self.core.delEntry(id) # }}} - def addEntry(self,Entry): # {{{ + def addEntry(self, args): # {{{ + Entry = self.client.createEntry(self.core.getColumns(id=False)) self.core.addEntry(Entry) # }}} def main(self): # {{{ - function, value = self.client.parseArgs(self.version,self.core.getColumns()) + function, value = self.client.parseArgs(self.version) getattr(self, function)(value) # }}} # }}} -interface = Interface() -interface.main() - # EOF # vim:foldmethod=marker:tabstop=3:autoindent: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. |
From: <Z3...@us...> - 2010-12-24 00:16:37
|
Revision: 322 http://spd.svn.sourceforge.net/spd/?rev=322&view=rev Author: Z3po Date: 2010-12-24 00:16:30 +0000 (Fri, 24 Dec 2010) Log Message: ----------- bugfix. It was impossible to create a default config Modified Paths: -------------- branches/spd-ng/src/spdCheck.py branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdInterface.py Added Paths: ----------- branches/spd-ng/src/spd branches/spd-ng/src/spd-cli Added: branches/spd-ng/src/spd =================================================================== --- branches/spd-ng/src/spd (rev 0) +++ branches/spd-ng/src/spd 2010-12-24 00:16:30 UTC (rev 322) @@ -0,0 +1,6 @@ +#!/usr/bin/python + +import spdInterface + +Interface = spdInterface.Interface() +Interface.main() Property changes on: branches/spd-ng/src/spd ___________________________________________________________________ Added: svn:executable + * Added: branches/spd-ng/src/spd-cli =================================================================== --- branches/spd-ng/src/spd-cli (rev 0) +++ branches/spd-ng/src/spd-cli 2010-12-24 00:16:30 UTC (rev 322) @@ -0,0 +1,6 @@ +#!/usr/bin/python + +import spdInterface + +Interface = spdInterface.Interface(clientmode='CLI') +Interface.main() Property changes on: branches/spd-ng/src/spd-cli ___________________________________________________________________ Added: svn:executable + * Modified: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-12-11 00:40:20 UTC (rev 321) +++ branches/spd-ng/src/spdCheck.py 2010-12-24 00:16:30 UTC (rev 322) @@ -27,6 +27,23 @@ sys.exit(2) # }}} + def __oldSPDCheck(self): # {{{ + __oldspdconfig = '~/.spd/spd.conf' + if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): + print 'old config found' + + # }}} + + def __createDefaultConfig(self,config): # {{{ + """Create the default config here. + # config: the configparser to use""" + + config.addConfigSection('Main') + config.setConfigVersion('0.3-alpha') + config.setClientmode('CLI') + # }}} + + def startupCheck(self): # {{{ """Do initial checks""" @@ -40,7 +57,10 @@ reval, version = config.getConfigVersion(raw=True) if reval > 0 and reval < 64: - Defaults.createDefaultConfig(config) + self.__oldSPDCheck() + self.__createDefaultConfig(config) + return self.startupCheck() + elif reval == 64: print 'ConfigVersion not found...setting Default one\n' config.setConfigVersion('0.3-alpha') @@ -61,19 +81,5 @@ # }}} -class Defaults(object): # {{{ - """Class to create default values.""" - - def createDefaultConfig(self,config): # {{{ - """Create the default config here. - # config: the configparser to use""" - - config.addConfigSection('Main') - config.setConfigVersion('0.3-alpha') - config.setClientmode('CLI') - # }}} - -# }}} - # EOF # vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-12-11 00:40:20 UTC (rev 321) +++ branches/spd-ng/src/spdConfig.py 2010-12-24 00:16:30 UTC (rev 322) @@ -43,17 +43,17 @@ """Is the Config file readable?""" reval = self.__checkConfigFileExist() + config = RawConfigParser() if reval > 0: - return reval, None + return reval, config - config = RawConfigParser() if os.access(self.configfile,os.R_OK): config.read(self.configfile) return 0,config else: - return 4, None + return 4, config # }}} def __checkConfigFileWriteable(self): # {{{ @@ -62,13 +62,19 @@ reval = self.__checkConfigFileExist() if reval > 0: - return reval, None + try: + configfile = open(self.configfile, 'wb') + except IOError: + return 8, configfile + else: + return 0, configfile if os.access(self.configfile,os.W_OK): configfile = open(self.configfile, 'wb') - return 0, configfile else: return 8, None + + return 0, configfile # }}} def __writeConfigFile(self,config): # {{{ @@ -91,11 +97,11 @@ reval, config = self.__checkConfigFileReadable() if reval > 0: - return reval, None + return reval, config if config.has_section(section): return 0, config - + return 32, config # }}} @@ -103,9 +109,9 @@ """create a section if its not in configfile. # section: the section to create.""" - reval, config = self.__hasSection() + reval, config = self.__hasSection(section) - if reval > 0 and reval < 32: + if reval > 0 and reval < 32 and reval is not 2: return reval config.add_section(section) @@ -208,8 +214,8 @@ # }}} - def addConfigSection(self): # {{{ - reval = self.__addSection('Main') + def addConfigSection(self,section): # {{{ + reval = self.__addSection(section) if reval > 0: self.__ErrorHandler(self.ReturnCodes[reval]) Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-12-11 00:40:20 UTC (rev 321) +++ branches/spd-ng/src/spdInterface.py 2010-12-24 00:16:30 UTC (rev 322) @@ -20,7 +20,7 @@ self.version = initcheck['version'] if not clientmode: - clientmode = initcheck['clientmode'] + clientmode = initcheck['clientmode'] del initcheck This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <Z3...@us...> - 2010-12-24 14:33:30
|
Revision: 323 http://spd.svn.sourceforge.net/spd/?rev=323&view=rev Author: Z3po Date: 2010-12-24 14:33:23 +0000 (Fri, 24 Dec 2010) Log Message: ----------- removed spdCheck and added spdDefaults module. bugfix for --add function in spd. changed loading of clientmode to be more dynamic. Checks are now done in the module itself. Modified Paths: -------------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/spdInterface.py branches/spd-ng/src/test.db Added Paths: ----------- branches/spd-ng/src/spdDefaults.py Removed Paths: ------------- branches/spd-ng/src/spdCheck.py Deleted: branches/spd-ng/src/spdCheck.py =================================================================== --- branches/spd-ng/src/spdCheck.py 2010-12-24 00:16:30 UTC (rev 322) +++ branches/spd-ng/src/spdCheck.py 2010-12-24 14:33:23 UTC (rev 323) @@ -1,85 +0,0 @@ -#!/usr/bin/python - -import spdConfig -import os - -class Check(object): # {{{ - """This is the initcheck Configuration Module - Checks if everything is there to perform :)""" - - spddir = os.path.expanduser('~/.spd/') - config = spdConfig.Config() - - def __init__(self,module): # {{{ - """Do the initial checks. - # module: which module called me??""" - - self.module = 'spdInterface' - # }}} - - def __ErrorHandler(self, message): # {{{ - '''ErrorHandler of the Check Module. - # message: means the \'Exception\' to throw''' - print '################################################' - print 'spdCheck ErrorHandler.' - print 'ERRORMESSAGE: ' + message - print '################################################' - sys.exit(2) - # }}} - - def __oldSPDCheck(self): # {{{ - __oldspdconfig = '~/.spd/spd.conf' - if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): - print 'old config found' - - # }}} - - def __createDefaultConfig(self,config): # {{{ - """Create the default config here. - # config: the configparser to use""" - - config.addConfigSection('Main') - config.setConfigVersion('0.3-alpha') - config.setClientmode('CLI') - # }}} - - - def startupCheck(self): # {{{ - """Do initial checks""" - - if self.module == 'spdInterface': - - if not os.access(self.spddir, os.F_OK): - os.mkdir(spddir) - - config = self.config - - reval, version = config.getConfigVersion(raw=True) - - if reval > 0 and reval < 64: - self.__oldSPDCheck() - self.__createDefaultConfig(config) - return self.startupCheck() - - elif reval == 64: - print 'ConfigVersion not found...setting Default one\n' - config.setConfigVersion('0.3-alpha') - version = config.getConfigVersion() - - reval, clientmode = config.getClientmode(raw=True) - - if reval > 0: - config.setClientmode('CLI') - clientmode = config.getClientmode() - - return({ 'version' : version, - 'clientmode' : clientmode }) - else: - return True - - # }}} - -# }}} - -# EOF -# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-12-24 00:16:30 UTC (rev 322) +++ branches/spd-ng/src/spdCore.py 2010-12-24 14:33:23 UTC (rev 323) @@ -81,14 +81,14 @@ # }}} - def getColumns(self,__showid=True): # {{{ + def getColumns(self,showid=True): # {{{ query = "pragma Table_info('" + self.ConfigSection + "')" self.dbc.execute(query) result = [] for i in self.dbc: - if not __showid and i['name'] == "__ID": + if not showid and i['name'] == "__ID": continue if i['name'] not in self.deletedColumns: result.append(i['name']) Copied: branches/spd-ng/src/spdDefaults.py (from rev 322, branches/spd-ng/src/spdCheck.py) =================================================================== --- branches/spd-ng/src/spdDefaults.py (rev 0) +++ branches/spd-ng/src/spdDefaults.py 2010-12-24 14:33:23 UTC (rev 323) @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import spdConfig +import os + +class Defaults(object): # {{{ + """This is the Defaults Configuration Module + Trying to create the defaults""" + + spddir = os.path.expanduser('~/.spd/') + + def __ErrorHandler(self, function, message): # {{{ + '''ErrorHandler of the Defaults Module. + # function: the function who called the ErrorHandler + # message: means the \'Exception\' to throw''' + print '################################################' + print 'spdDefaults ErrorHandler.' + print 'ERRORFUNCTION: ' + function + print 'ERRORMESSAGE: ' + message + print '################################################' + sys.exit(2) + # }}} + + def __oldSPDCheck(self): # {{{ + __oldspdconfig = '~/.spd/spd.conf' + if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): + print 'old config found' + # }}} + + def createDefaultConfig(self,config): # {{{ + """Create the default config here. + # config: the configparser to use""" + + self.__oldSPDCheck() + config.addConfigSection('Main') + config.setConfigVersion('0.3-alpha') + config.setClientmode('CLI') + # }}} + +# }}} + +# EOF +# vim:foldmethod=marker:tabstop=3:autoindent:shiftwidth=3 Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-12-24 00:16:30 UTC (rev 322) +++ branches/spd-ng/src/spdInterface.py 2010-12-24 14:33:23 UTC (rev 323) @@ -1,6 +1,8 @@ #!/usr/bin/python -import spdCheck +import spdConfig +import spdDefaults +import os import spdCore import string from sys import exit @@ -8,6 +10,8 @@ class Interface(object): # {{{ """The Interface Module. Connection between Output and Core.""" + spddir = os.path.expanduser('~/.spd/') + config = spdConfig.Config() version = None client = None core = None @@ -15,8 +19,7 @@ def __init__(self,clientmode=False): # {{{ """init procedure""" - check = spdCheck.Check("spdInterface") - initcheck = check.startupCheck() + initcheck = self.__startupCheck() self.version = initcheck['version'] if not clientmode: @@ -24,12 +27,14 @@ del initcheck - if clientmode == 'CLI': - import spdCLI - self.client = spdCLI.Cli() + try: + __client = __import__('spd' + clientmode) + except ImportError: + print 'clientmode \"' + clientmode + '\" not available' + exit(2) else: - print 'CLIENTMODE \'not yet\' available' - exit(2) + self.client = __client.Cli() + del __client self.core = spdCore.Core() # }}} @@ -45,6 +50,37 @@ exit(2) # }}} + def __startupCheck(self): # {{{ + """Do initial checks""" + + if not os.access(self.spddir, os.F_OK): + os.mkdir(spddir) + + config = self.config + + reval, version = config.getConfigVersion(raw=True) + + if reval > 0 and reval < 64: + Defaults = spdDefaults.Defaults() + Defaults.createDefaultConfig(config) + return self.__startupCheck() + + elif reval == 64: + print 'ConfigVersion not found...setting Default one\n' + config.setConfigVersion('0.3-alpha') + version = config.getConfigVersion() + + reval, clientmode = config.getClientmode(raw=True) + + if reval > 0: + print 'Clientmode not found...setting it to CLI\n' + config.setClientmode('CLI') + clientmode = config.getClientmode() + + return({ 'version' : version, + 'clientmode' : clientmode }) + # }}} + def findPasswords(self,searchString='%'): # {{{ """Find the passwords by searchlist/searchstring handed. print the results in CLIENTMODE. @@ -85,7 +121,7 @@ # }}} def addEntry(self, args): # {{{ - Entry = self.client.createEntry(self.core.getColumns(id=False)) + 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. |
From: <Z3...@us...> - 2010-12-25 00:35:29
|
Revision: 324 http://spd.svn.sourceforge.net/spd/?rev=324&view=rev Author: Z3po Date: 2010-12-25 00:35:22 +0000 (Sat, 25 Dec 2010) Log Message: ----------- little code cleanup Modified Paths: -------------- branches/spd-ng/src/spdConfig.py branches/spd-ng/src/spdDefaults.py branches/spd-ng/src/spdInterface.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdConfig.py =================================================================== --- branches/spd-ng/src/spdConfig.py 2010-12-24 14:33:23 UTC (rev 323) +++ branches/spd-ng/src/spdConfig.py 2010-12-25 00:35:22 UTC (rev 324) @@ -7,6 +7,7 @@ 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', @@ -15,8 +16,8 @@ 32 : 'Section not found', 64 : 'Option not found' } - def __init__(self, conffile='~/.spd/config'): # {{{ - self.configfile = os.path.expanduser(conffile) + def __init__(self, configfile='~/.spd/config'): # {{{ + self.__configfile = os.path.expanduser(configfile) # }}} def __ErrorHandler(self,message): # {{{ @@ -24,7 +25,7 @@ # message: means the \'Exception\' to throw""" print "################################################" print "spdConfig ErrorHandler." - print "Configfile: " + self.configfile + print "Configfile: " + self.__configfile print "ERRORMESSAGE: " + message print "################################################" sys.exit(2) @@ -33,7 +34,7 @@ def __checkConfigFileExist(self): # {{{ """Does the Config file exist?""" - if os.access(self.configfile, os.F_OK): + if os.access(self.__configfile, os.F_OK): return 0 else: return 2 @@ -49,8 +50,8 @@ return reval, config - if os.access(self.configfile,os.R_OK): - config.read(self.configfile) + if os.access(self.__configfile,os.R_OK): + config.read(self.__configfile) return 0,config else: return 4, config @@ -63,14 +64,14 @@ if reval > 0: try: - configfile = open(self.configfile, 'wb') + configfile = open(self.__configfile, 'wb') except IOError: return 8, configfile else: return 0, configfile - if os.access(self.configfile,os.W_OK): - configfile = open(self.configfile, 'wb') + if os.access(self.__configfile,os.W_OK): + configfile = open(self.__configfile, 'wb') else: return 8, None Modified: branches/spd-ng/src/spdDefaults.py =================================================================== --- branches/spd-ng/src/spdDefaults.py 2010-12-24 14:33:23 UTC (rev 323) +++ branches/spd-ng/src/spdDefaults.py 2010-12-25 00:35:22 UTC (rev 324) @@ -24,17 +24,30 @@ def __oldSPDCheck(self): # {{{ __oldspdconfig = '~/.spd/spd.conf' if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): - print 'old config found' + print 'old config found!' + return True, __oldspdconfig + return False, None # }}} def createDefaultConfig(self,config): # {{{ """Create the default config here. # config: the configparser to use""" - self.__oldSPDCheck() - config.addConfigSection('Main') - config.setConfigVersion('0.3-alpha') - config.setClientmode('CLI') + print 'Checking if we are an upgrade first...' + __found, __oldconfig = self.__oldSPDCheck() + if __found == True: + __input = '' + while __input is not 'y' and __input is not 'n': + __input = raw_input('Shall i try to convert the old Configfile?(y|n):') + if __input == 'y': + print 'Trying to convert...' + print 'NOT YET IMPLEMENTED' + else: + __input = raw_input('Going to create default config now...[ENTER]') + config.addConfigSection('Main') + config.setConfigVersion('0.3-alpha') + config.setClientmode('CLI') + __input = raw_input('Done. Back to normal. [ENTER]') # }}} # }}} Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-12-24 14:33:23 UTC (rev 323) +++ branches/spd-ng/src/spdInterface.py 2010-12-25 00:35:22 UTC (rev 324) @@ -10,33 +10,32 @@ class Interface(object): # {{{ """The Interface Module. Connection between Output and Core.""" - spddir = os.path.expanduser('~/.spd/') - config = spdConfig.Config() - version = None - client = None - core = None + __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'] + self.__version = initcheck['version'] + if not clientmode: clientmode = initcheck['clientmode'] del initcheck try: - __client = __import__('spd' + clientmode) + __tempclient = __import__('spd' + clientmode) except ImportError: - print 'clientmode \"' + clientmode + '\" not available' - exit(2) + self.__ErrorHandler('__init__', 'clientmode ' + clientmode + ' not available!') else: - self.client = __client.Cli() - del __client + self.__client = __tempclient.Cli() + del __tempclient - self.core = spdCore.Core() + self.__core = spdCore.Core() # }}} def __ErrorHandler(self,function,message): # {{{ @@ -53,31 +52,31 @@ def __startupCheck(self): # {{{ """Do initial checks""" - if not os.access(self.spddir, os.F_OK): - os.mkdir(spddir) + if not os.access(self.__spddir, os.F_OK): + os.mkdir(self.__spddir) + + __config = spdConfig.Config() + + reval, __version = __config.getConfigVersion(raw=True) - config = self.config - - reval, version = config.getConfigVersion(raw=True) - if reval > 0 and reval < 64: Defaults = spdDefaults.Defaults() - Defaults.createDefaultConfig(config) + Defaults.createDefaultConfig(__config) return self.__startupCheck() elif reval == 64: print 'ConfigVersion not found...setting Default one\n' - config.setConfigVersion('0.3-alpha') - version = config.getConfigVersion() + __config.setConfigVersion('0.3-alpha') + __version = __config.getConfigVersion() - reval, clientmode = config.getClientmode(raw=True) + reval, clientmode = __config.getClientmode(raw=True) if reval > 0: print 'Clientmode not found...setting it to CLI\n' - config.setClientmode('CLI') - clientmode = config.getClientmode() + __config.setClientmode('CLI') + clientmode = __config.getClientmode() - return({ 'version' : version, + return({ 'version' : __version, 'clientmode' : clientmode }) # }}} @@ -93,13 +92,13 @@ if len(searchlist) == 0: searchlist = ['%',] - passdict = self.core.searchEntry(searchlist) + passdict = self.__core.searchEntry(searchlist) return passdict # }}} def printPasswords(self,searchString='%'): # {{{ passdict = self.findPasswords(searchString) - self.client.printPasswords(passdict) + self.__client.printPasswords(passdict) # }}} def deleteID(self,ids): # {{{ @@ -110,23 +109,23 @@ ids = str(ids) ids = string.split(ids) for id in ids: - self.core.delEntry(id) + self.__core.delEntry(id) # }}} def deleteEntry(self,searchString): # {{{ passdict = self.findPasswords(searchString) print str(passdict) for id in passdict["__ID"]: - self.core.delEntry(id) + self.__core.delEntry(id) # }}} 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, value = self.client.parseArgs(self.version) + function, value = self.__client.parseArgs(self.__version) getattr(self, function)(value) # }}} 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. |
From: <Z3...@us...> - 2010-12-25 11:25:51
|
Revision: 325 http://spd.svn.sourceforge.net/spd/?rev=325&view=rev Author: Z3po Date: 2010-12-25 11:25:43 +0000 (Sat, 25 Dec 2010) Log Message: ----------- introducing --wide mode Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCLI.py =================================================================== --- branches/spd-ng/src/spdCLI.py 2010-12-25 00:35:22 UTC (rev 324) +++ branches/spd-ng/src/spdCLI.py 2010-12-25 11:25:43 UTC (rev 325) @@ -1,6 +1,8 @@ #!/usr/bin/python from optparse import OptionParser +import sys +import re class Cli(object): # {{{ """This is the Cli Module. @@ -8,12 +10,25 @@ __outmode = None + 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): # {{{ """Print the passwords out of a dictionary. # passdict: the dictionary full of passwords""" + __keylength = {} if type(passdict).__name__ != 'NoneType' and len(passdict) != 0: - if self.__outmode == 'lines': + if self.__outmode == 'line': length = 0 for key in passdict.keys(): if length < len(key): @@ -30,7 +45,32 @@ print key.ljust(length) + ': ' print "" elif self.__outmode == 'wide': - print 'NOT YET IMPLEMENTED...SORRY' + 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 len(str(value)) > __keylength[key]: + __keylength[key] = len(str(value)) + + for key in passdict: + sys.stdout.write(key.ljust(__keylength[key]) + '|') + sys.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] = '' + sys.stdout.write(re.sub('\n','\n' + __space,str(passdict[key][i]).ljust(__keylength[key])) + '|') + __space = __space + ''.ljust(__keylength[key]) + ' ' + sys.stdout.write('\n') + else: + self.__ErrorHandler('printPasswords', 'output mode unknown') else: print "No Results found" # }}} @@ -45,7 +85,6 @@ # }}} def parseArgs(self,version): # {{{ - __ouput="lines" parser = OptionParser( "%prog [Options] [Keywords]", description = "SPD - Simple Password Displayer - CLI", version = "SPD " + version, @@ -119,15 +158,11 @@ elif options.widemode: self.__outmode = 'wide' else: - self.__outmode = 'lines' + self.__outmode = 'line' return ["printPasswords", args] # }}} - def main(self,options,args): # {{{ - pass - # }}} - # }}} # EOF 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. |
From: <Z3...@us...> - 2010-12-27 22:31:18
|
Revision: 326 http://spd.svn.sourceforge.net/spd/?rev=326&view=rev Author: Z3po Date: 2010-12-27 22:31:11 +0000 (Mon, 27 Dec 2010) Log Message: ----------- code cleanup and little improvements Modified Paths: -------------- branches/spd-ng/src/spdCLI.py branches/spd-ng/src/spdCore.py branches/spd-ng/src/spdDefaults.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-25 11:25:43 UTC (rev 325) +++ branches/spd-ng/src/spdCLI.py 2010-12-27 22:31:11 UTC (rev 326) @@ -75,6 +75,7 @@ print "No Results found" # }}} + def createEntry(self,columns): # {{{ Entry = {} print "Adding a new Entry to our passfile" Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-12-25 11:25:43 UTC (rev 325) +++ branches/spd-ng/src/spdCore.py 2010-12-27 22:31:11 UTC (rev 326) @@ -1,5 +1,10 @@ -#!/usr/bin/python +'''spdCore Module. + Handles the Datastore of SPD. + Usage: + import spdCore + coreobject = spdCore.Core()''' + import sqlite3 import atexit Modified: branches/spd-ng/src/spdDefaults.py =================================================================== --- branches/spd-ng/src/spdDefaults.py 2010-12-25 11:25:43 UTC (rev 325) +++ branches/spd-ng/src/spdDefaults.py 2010-12-27 22:31:11 UTC (rev 326) @@ -1,55 +1,49 @@ -#!/usr/bin/python +"""This is the Defaults Configuration Module + Trying to create the defaults""" import spdConfig import os -class Defaults(object): # {{{ - """This is the Defaults Configuration Module - Trying to create the defaults""" +def __ErrorHandler(function, message): # {{{ + '''ErrorHandler of the Defaults Module. + # function: the function who called the ErrorHandler + # message: means the \'Exception\' to throw''' + print '################################################' + print 'spdDefaults ErrorHandler.' + print 'ERRORFUNCTION: ' + function + print 'ERRORMESSAGE: ' + message + print '################################################' + sys.exit(2) +# }}} - spddir = os.path.expanduser('~/.spd/') +def __oldSPDCheck(): # {{{ + '''Checks if a old spd configuration file is there and tries to mutate it''' + __oldspdconfig = '~/.spd/spd.conf' + if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): + print 'old config found!' + return True, __oldspdconfig + return False, None +# }}} - def __ErrorHandler(self, function, message): # {{{ - '''ErrorHandler of the Defaults Module. - # function: the function who called the ErrorHandler - # message: means the \'Exception\' to throw''' - print '################################################' - print 'spdDefaults ErrorHandler.' - print 'ERRORFUNCTION: ' + function - print 'ERRORMESSAGE: ' + message - print '################################################' - sys.exit(2) - # }}} - - def __oldSPDCheck(self): # {{{ - __oldspdconfig = '~/.spd/spd.conf' - if os.access(os.path.expanduser(__oldspdconfig), os.R_OK): - print 'old config found!' - return True, __oldspdconfig - return False, None - # }}} - - def createDefaultConfig(self,config): # {{{ - """Create the default config here. - # config: the configparser to use""" - - print 'Checking if we are an upgrade first...' - __found, __oldconfig = self.__oldSPDCheck() - if __found == True: - __input = '' - while __input is not 'y' and __input is not 'n': - __input = raw_input('Shall i try to convert the old Configfile?(y|n):') - if __input == 'y': - print 'Trying to convert...' - print 'NOT YET IMPLEMENTED' - else: - __input = raw_input('Going to create default config now...[ENTER]') - config.addConfigSection('Main') - config.setConfigVersion('0.3-alpha') - config.setClientmode('CLI') - __input = raw_input('Done. Back to normal. [ENTER]') - # }}} - +def createDefaultConfig(config): # {{{ + """Create the default config here. + # config: the configparser to use""" + + print 'Checking if we are an upgrade first...' + __found, __oldconfig = __oldSPDCheck() + if __found == True: + __input = '' + while __input is not 'y' and __input is not 'n': + __input = raw_input('Shall i try to convert the old Configfile?(y|n):') + if __input == 'y': + print 'Trying to convert...' + print 'NOT YET IMPLEMENTED' + else: + __input = raw_input('Going to create default config now...[ENTER]') + config.addConfigSection('Main') + config.setConfigVersion('0.3-alpha') + config.setClientmode('CLI') + __input = raw_input('Done. Back to normal. [ENTER]') # }}} # EOF Modified: branches/spd-ng/src/spdInterface.py =================================================================== --- branches/spd-ng/src/spdInterface.py 2010-12-25 11:25:43 UTC (rev 325) +++ branches/spd-ng/src/spdInterface.py 2010-12-27 22:31:11 UTC (rev 326) @@ -1,15 +1,28 @@ -#!/usr/bin/python +'''spdInterface Module. -import spdConfig -import spdDefaults +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')''' + +from sys import exit import os -import spdCore import string -from sys import exit +try: + import spdConfig + import spdDefaults + import spdCore +except ImportError: + print 'spd not installed. Missing Modules.' + exit(2) class Interface(object): # {{{ """The Interface Module. - Connection between Output and Core.""" + Interface between client and Core.""" __spddir = os.path.expanduser('~/.spd/') __version = None __client = None @@ -53,19 +66,22 @@ """Do initial checks""" if not os.access(self.__spddir, os.F_OK): - os.mkdir(self.__spddir) + try: + os.mkdir(self.__spddir) + except Exception, e: + self.__ErrorHandler('__startupCheck','Could not create ' + self.__spddir + ' Exception: ' + str(e)) __config = spdConfig.Config() reval, __version = __config.getConfigVersion(raw=True) if reval > 0 and reval < 64: - Defaults = spdDefaults.Defaults() - Defaults.createDefaultConfig(__config) + 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') __version = __config.getConfigVersion() @@ -73,6 +89,7 @@ if reval > 0: print 'Clientmode not found...setting it to CLI\n' + __input = raw_input('Press any key') __config.setClientmode('CLI') clientmode = __config.getClientmode() @@ -80,7 +97,7 @@ 'clientmode' : clientmode }) # }}} - def findPasswords(self,searchString='%'): # {{{ + def __findPasswords(self,searchString): # {{{ """Find the passwords by searchlist/searchstring handed. print the results in CLIENTMODE. # searchlist: optional string or list of keywords to search for.""" @@ -93,11 +110,12 @@ if len(searchlist) == 0: searchlist = ['%',] passdict = self.__core.searchEntry(searchlist) + return passdict # }}} def printPasswords(self,searchString='%'): # {{{ - passdict = self.findPasswords(searchString) + passdict = self.__findPasswords(searchString) self.__client.printPasswords(passdict) # }}} @@ -113,10 +131,14 @@ # }}} def deleteEntry(self,searchString): # {{{ - passdict = self.findPasswords(searchString) - print str(passdict) - for id in passdict["__ID"]: - self.__core.delEntry(id) + __passdict = self.__findPasswords(searchString) + if len(__passdict) > 1: + print str(__passdict) + elif len(__passdict) > 0: + print str(__passdict) + self.__core.delEntry(__passdict['__ID']) + else: + self.__ErrorHandler('deleteEntry','No matches found') # }}} def addEntry(self, args): # {{{ 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. |
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. |
From: <Z3...@us...> - 2010-12-29 22:07:14
|
Revision: 328 http://spd.svn.sourceforge.net/spd/?rev=328&view=rev Author: Z3po Date: 2010-12-29 22:07:08 +0000 (Wed, 29 Dec 2010) Log Message: ----------- bugfix. accidentially killed PRIMARY KEY in delColumn function of spdCore Modified Paths: -------------- branches/spd-ng/src/spdCore.py branches/spd-ng/src/test.db Modified: branches/spd-ng/src/spdCore.py =================================================================== --- branches/spd-ng/src/spdCore.py 2010-12-28 21:46:06 UTC (rev 327) +++ branches/spd-ng/src/spdCore.py 2010-12-29 22:07:08 UTC (rev 328) @@ -10,11 +10,6 @@ class Core(object): - # Writes back to the Store - def __commit(self): # {{{ - self.db.commit() - #}}} - # create the database from the stuff out of the store def __init__(self,ConfigSection='Main',PasswordColumn='Password'): # {{{ self.ConfigSection = ConfigSection @@ -24,7 +19,6 @@ self.dbc = self.db.cursor() self.deletedColumns = [] - atexit.register(self.__commit) # Make Sure to Write back changes to sqldb exiting # }}} def __ErrorHandler(self,function,message): # {{{ @@ -74,7 +68,6 @@ except KeyError: result[j] = [i[j]] - return result # }}} @@ -89,17 +82,16 @@ query += cols[0:-2] + ') VALUES ( ' + vals[0:-2] + ')' self.dbc.execute(query,NewDict) - + self.db.commit() # }}} def delEntry(self,ID): # {{{ query = 'delete from '+ self.ConfigSection +' where __ID='+str(ID) self.dbc.execute(query) - + self.db.commit() # }}} def getColumns(self,showid=True): # {{{ - query = "pragma Table_info('" + self.ConfigSection + "')" self.dbc.execute(query) @@ -109,9 +101,7 @@ continue if i['name'] not in self.deletedColumns: result.append(i['name']) - return result - # }}} def addColumn(self,columnname): # {{{ @@ -119,14 +109,26 @@ self.__ErrorHandler('addColumn','Column already exists') query='alter table ' + self.ConfigSection + ' add column ' + columnname + ' text ' self.db.execute(query) - + self.db.commit() # }}} def delColumn(self,columnname): # {{{ __columns = '' + __newcolumns = '' for __column in self.getColumns(showid=True): if __column == columnname and columnname != '__ID': continue + + if __column == '__ID': + __newcolumn = __column + ' INTEGER PRIMARY KEY' + else: + __newcolumn = __column + ' text' + + if __newcolumns == '': + __newcolumns = __newcolumn + else: + __newcolumns = __newcolumns + ',' + __newcolumn + if __columns == '': __columns = __column else: @@ -134,13 +136,14 @@ # it's not that easy, to delete a column in SQLite self.dbc.executescript(""" - CREATE TEMPORARY TABLE """ + self.ConfigSection + """_backup(""" + __columns + """); + 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 + """(""" + __columns + """); + CREATE TABLE """ + self.ConfigSection + """(""" + __newcolumns + """); INSERT INTO """ + self.ConfigSection + """ SELECT """ + __columns + """ FROM """ + self.ConfigSection + """_backup; DROP TABLE """ + self.ConfigSection + """_backup; """) + self.db.commit() # }}} # EOF 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. |