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