Skip to content

Commit

Permalink
Added util package, which provides a general get()
Browse files Browse the repository at this point in the history
  • Loading branch information
danwos committed Sep 15, 2016
1 parent 08e22e8 commit d3f334d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions groundwork/util.py
@@ -0,0 +1,36 @@
def gw_get(object_dict, name=None, plugin=None):
"""
Getter function to retrieve objects from a given object dictionary.
Used mainly to provide get() inside patterns.
:param object_dict: objects, which must have 'name' and 'plugin' as attribute
:type object_dict: dictionary
:param name: name of the object
:type name: str
:param plugin: plugin name, which registers the object
:return: None, single object or dict of objects
"""
if plugin is not None:
if name is None:
object_list = {}
for key in object_dict.keys():
if object_dict[key].plugin == plugin:
object_list[key] = object_dict[key]
return object_list
else:
if name in object_dict.keys():
if object_dict[name].plugin == plugin:
return object_dict[name]
else:
return None
else:
return None
else:
if name is None:
return object_dict
else:
if name in object_dict.keys():
return object_dict[name]
else:
return None

0 comments on commit d3f334d

Please sign in to comment.