|
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.
|