Added recursirve search

This commit is contained in:
Patrick Neumann 2020-12-02 14:46:50 +00:00
parent 0849593430
commit 132f4108fd

View File

@ -103,13 +103,19 @@ try:
with open( plist, 'rb' ) as fp:
content = plistlib.load( fp )
except:
print( "\nError: plist is not a XML file!\n" )
print( "\nError: not able to load plist!\n" )
sys.exit( 1 )
try:
print( key + ":", content[ key ] )
except:
print( "\nError: key not found!\n" )
sys.exit( 1 )
# net to be able to get values of keys and subkeys
def _finditem(obj, key):
if key in obj: return obj[key]
for k, v in obj.items():
if isinstance(v,dict):
item = _finditem(v, key)
if item is not None:
return item
# find key and print value (recursively)
print( key + ":", _finditem( content, key ) )
sys.exit( 0 )