|
From: <Z3...@us...> - 2011-01-16 19:48:38
|
Revision: 331
http://spd.svn.sourceforge.net/spd/?rev=331&view=rev
Author: Z3po
Date: 2011-01-16 19:48:31 +0000 (Sun, 16 Jan 2011)
Log Message:
-----------
improved argument passing, added pwonly option
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 2011-01-08 09:08:07 UTC (rev 330)
+++ branches/spd-ng/src/spdCLI.py 2011-01-16 19:48:31 UTC (rev 331)
@@ -23,13 +23,19 @@
exit(2)
# }}}
- def printPasswords(self,passdict): # {{{
+ def printPasswords(self,passdict,pwonly=False): # {{{
"""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 == 'line':
+ if pwonly:
+ if len(passdict['__ID']) > 1:
+ self.__ErrorHandler('printPasswords', 'pwonly selected but more than one result returned')
+ else:
+ print passdict['Password'][0] # FIXME!!
+
+ elif self.__outmode == 'line':
length = 0
for key in passdict.keys():
if length < len(key):
@@ -41,7 +47,7 @@
if key == '__ID':
continue
if type(passdict[key][i]).__name__ != 'NoneType':
- print key.ljust(length) + ': ' + passdict[key][i]
+ print key.ljust(length) + ': ' + re.sub('\n','\n ' + ' '.ljust(length),passdict[key][i])
else:
print key.ljust(length) + ': '
print ""
@@ -97,6 +103,19 @@
return __passdict
# }}}
+ def deleteEntry(self,__passdict): # {{{
+ __count = len(__passdict['__ID'])
+ __ids = []
+ print '\n---------------------------'
+ for i in range(0, __count):
+ __input = None
+ while __input != 'y' and __input != 'n':
+ __input = raw_input('Delete Entry with ID ' + str(__passdict['__ID'][i]) + ' (y|n)?')
+ if __input == 'y':
+ __ids.append(__passdict['__ID'][i])
+ return __ids
+ # }}}
+
def createEntry(self,columns): # {{{
Entry = {}
print "Adding a new Entry to our passfile"
@@ -149,20 +168,15 @@
default=False,
help = "print output in wide mode (means as a table)")
+
+ group.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_group(group)
-
- #parser.add_option( "--add-column",
- # metavar="Collumn",
- # dest = "addcolumn",
- # 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( "-l", "--local",
# action="store_true",
@@ -192,24 +206,24 @@
(options, args) = parser.parse_args()
+ if options.widemode:
+ self.__outmode = 'wide'
+ else:
+ self.__outmode = 'line'
+
if options.addEntry:
return ["addEntry", args]
elif options.deleteEntry:
return ["deleteEntry", [ options.byid, args]]
elif options.editEntry:
- return ["editEntry", args]
+ return ["editEntry", [ options.byid, args]]
elif options.deleteColumn:
return ["deleteColumn", args]
elif options.addColumn:
return ["addColumn", args]
- elif options.widemode:
- self.__outmode = 'wide'
- else:
- self.__outmode = 'line'
-
- return ["printPasswords", args]
+ return ["printPasswords", [ options.byid, options.pwonly, args]]
# }}}
# }}}
Modified: branches/spd-ng/src/spdInterface.py
===================================================================
--- branches/spd-ng/src/spdInterface.py 2011-01-08 09:08:07 UTC (rev 330)
+++ branches/spd-ng/src/spdInterface.py 2011-01-16 19:48:31 UTC (rev 331)
@@ -51,7 +51,7 @@
self.__client = __tempclient.Cli()
del __tempclient
- self.__core = spdCore.Core()
+ self.__core = spdCore.Core(ConfigSection='Main')
# }}}
def __ErrorHandler(self,function,message): # {{{
@@ -100,11 +100,13 @@
'clientmode' : clientmode })
# }}}
- def __findPasswords(self,searchString,byid=False): # {{{
+ def __findPasswords(self,args): # {{{
"""Find the passwords by searchlist/searchstring handed.
print the results in CLIENTMODE.
# searchlist: optional string or list of keywords to search for."""
+ byid, searchString = args
+
if type(searchString).__name__ == 'list':
searchlist = searchString
else:
@@ -117,32 +119,31 @@
return passdict
# }}}
- def printPasswords(self,searchString='%'): # {{{
- passdict = self.__findPasswords(searchString)
- self.__client.printPasswords(passdict)
+ def printPasswords(self,args): # {{{
+ byid, pwonly, keywords = args
+ passdict = self.__findPasswords([ byid, keywords ])
+ self.__client.printPasswords(passdict, pwonly)
# }}}
- def deleteEntry(self, values): # {{{
- byid, searchString = values
- __passdict = self.__findPasswords(searchString,byid)
+ def deleteEntry(self, args): # {{{
+ byid, searchString = args
+ __passdict = self.__findPasswords(args)
if len(__passdict) == 0:
self.__ErrorHandler('deleteEntry','No matches found')
- if len(__passdict['__ID']) > 1:
- print str(__passdict)
- else:
- print str(__passdict)
- self.__core.delEntry(__passdict['__ID'])
+ self.__client.printPasswords(__passdict)
+ ids = self.__client.deleteEntry(__passdict)
+ self.__core.delEntry(ids)
# }}}
- def editEntry(self,ids): # {{{
- __passdict = self.__findPasswords(ids,byid=True)
+ def editEntry(self,args): # {{{
+ __passdict = self.__findPasswords(args)
if len(__passdict) > 0:
__newpassdict = self.__client.editEntry(__passdict)
self.__core.editEntry(__newpassdict)
else:
- self.__ErrorHandler('editEntry','no matches for ' + str(ids) + 'found')
+ self.__ErrorHandler('editEntry','no matches for ' + str(args[1]) + 'found')
# }}}
def deleteColumn(self,columns): # {{{
@@ -164,8 +165,8 @@
# }}}
def main(self): # {{{
- function, value = self.__client.parseArgs(self.__version)
- getattr(self, function)(value)
+ function, args = self.__client.parseArgs(self.__version)
+ getattr(self, function)(args)
# }}}
# }}}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|