Skip to content
Snippets Groups Projects
Commit 4ba6bb84 authored by Christian Weber's avatar Christian Weber
Browse files

Feature: buildDictTreeFromTDir

parent 76fbfa5e
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ def TDirToList(TDir): # return the contents of a TDir as a list
for TKey in TDir.GetListOfKeys(): outputList.append( TKey.ReadObj() ) # this is how I access the element that belongs to the current TKey
return outputList
def getTDirContentNames(TDir): return [tObj.GetName() for tObj in TDirToList(TDir)]
def generateTDirContents(TDir):
# this is a python generator
......@@ -42,6 +43,28 @@ def getSubTDirList( currentTDir) : # provides a list of subdirectories in the cu
return listOfSubdirectories
def buildDictTreeFromTDir(TDir, newOwnership = None):
outputDict = {}
#def expandDict(aDict, keyList):
# addToEndOfDict(aDict, keyList, None)
# return None
def addToEndOfDict(aDict, keyList, thingToInsert):
if len(keyList) > 1:
if keyList[0] not in aDict: aDict[keyList[0]] = {}
addToEndOfDict(aDict[keyList[0]], keyList[1:], thingToInsert )
else:
aDict[keyList[0]]=thingToInsert
return None
# def addToEndOfDict(aDict, keyList, thingToInsert):
for path, TObject in generateTDirPathAndContentsRecursive(TDir, baseString = "" , newOwnership = newOwnership):
truncatedPath = path.split("/")[1:-1] # split into dir names and remove the first entry, i.e. the name of the TDir/Tfile, and the last one, i.e. the TObject name
addToEndOfDict(outputDict, truncatedPath, TObject )
return outputDict
###################################################################
# Functions to convert tree like nested dicts into TDir hierarchies
###################################################################
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment