glob_helper.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 import fnmatch
00005 
00006 topics_glob = []
00007 services_glob = []
00008 params_glob = []
00009 
00010 
00011 def get_globs():
00012 
00013     global topics_glob
00014     global services_glob
00015     global params_glob
00016 
00017     def get_param(param_name):
00018         param = rospy.get_param(param_name, '')
00019         # strips array delimiters in case of an array style value
00020         return [
00021             element.strip().strip("'")
00022             for element in param.strip('[').strip(']').split(',')
00023             if len(element.strip().strip("'")) > 0]
00024 
00025     topics_glob = get_param('~topics_glob')
00026     services_glob = get_param('~services_glob')
00027     params_glob = get_param('~params_glob')
00028 
00029 
00030 def filter_globs(globs, full_list):
00031     # If the globs are empty (weren't defined in the params), return the full list
00032     if globs is not None and len(globs) > 0:
00033         return filter(lambda x: any_match(x, globs), full_list)
00034     else:
00035         return full_list
00036 
00037 
00038 def any_match(query, globs):
00039     return globs is None or len(globs) == 0 or any(fnmatch.fnmatch(str(query), glob) for glob in globs)
00040 


rosapi
Author(s): Jonathan Mace
autogenerated on Thu Jun 6 2019 21:51:49