support glob matching

more flexibility in selecting active datasets and groups
This commit is contained in:
Martin Diehl 2019-09-14 09:38:04 -07:00
parent b85ac11c49
commit e4e9c5f558
1 changed files with 33 additions and 11 deletions

View File

@ -71,22 +71,47 @@ class DADF5():
self.filename = filename self.filename = filename
def __visible_set(self,output,t,p): def __visible_set(self,output,t,p):
valid = set(p) """Sets visible."""
# allow True/False and string arguments
if output is True:
output = ['*']
elif output is False:
output = []
choice = [output] if isinstance(output,str) else output choice = [output] if isinstance(output,str) else output
self.visible[t] = list(valid.intersection(choice))
valid = [e for e_ in [glob.fnmatch.filter(p,s) for s in choice] for e in e_]
self.visible[t] = valid
def __visible_add(self,output,t,p): def __visible_add(self,output,t,p):
"""Adds from visible."""
# allow True/False and string arguments
if output is True:
output = ['*']
elif output is False:
output = []
choice = [output] if isinstance(output,str) else output choice = [output] if isinstance(output,str) else output
valid = set(p).intersection(choice)
existing = set(self.visible[t]) existing = set(self.visible[t])
self.visible[t] = list(existing.add(valid)) valid = [e for e_ in [glob.fnmatch.filter(p,s) for s in choice] for e in e_]
self.visible[t] = list(existing.union(valid))
def __visible_del(self,output,t): def __visible_del(self,output,t):
"""Deletes from visible."""
# allow True/False and string arguments
if output is True:
output = ['*']
elif output is False:
output = []
choice = [output] if isinstance(output,str) else output choice = [output] if isinstance(output,str) else output
existing = set(self.visible[t]) existing = set(self.visible[t])
self.visible[t] = list(existing.remove(choice)) valid = [e for e_ in [glob.fnmatch.filter(existing,s) for s in choice] for e in e_]
self.visible[t] = list(existing.difference_update(valid))
def __visible_iter(self,t): def __visible_iter(self,t):
@ -102,6 +127,7 @@ class DADF5():
self.__visible_set(a,t,a) self.__visible_set(a,t,a)
# ToDo: store increments, select icrements (trivial), position, and time
def increment_set_by_time(self,start,end): def increment_set_by_time(self,start,end):
for t in self.time_information: for t in self.time_information:
if start<= t['time']< end: if start<= t['time']< end:
@ -183,10 +209,6 @@ class DADF5():
self.__visible_del(output,'materialpoints') self.__visible_del(output,'materialpoints')
# ToDo: store increments, select icrements (trivial), position, and time
def groups_with_datasets(self,datasets): def groups_with_datasets(self,datasets):
""" """
Get groups that contain all requested datasets. Get groups that contain all requested datasets.