Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
ZX_PostProcessingPlotter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christian Weber
ZX_PostProcessingPlotter
Commits
4ba6bb84
Commit
4ba6bb84
authored
5 years ago
by
Christian Weber
Browse files
Options
Downloads
Patches
Plain Diff
Feature: buildDictTreeFromTDir
parent
76fbfa5e
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
functions/rootDictAndTDirTools.py
+23
-0
23 additions, 0 deletions
functions/rootDictAndTDirTools.py
with
23 additions
and
0 deletions
functions/rootDictAndTDirTools.py
+
23
−
0
View file @
4ba6bb84
...
...
@@ -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
###################################################################
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment