glob_helper.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 import rospy
4 import fnmatch
5 
6 topics_glob = []
7 services_glob = []
8 params_glob = []
9 
10 
11 def get_globs():
12 
13  global topics_glob
14  global services_glob
15  global params_glob
16 
17  def get_param(param_name):
18  param = rospy.get_param(param_name, '')
19  # strips array delimiters in case of an array style value
20  return [
21  element.strip().strip("'")
22  for element in param.strip('[').strip(']').split(',')
23  if len(element.strip().strip("'")) > 0]
24 
25  topics_glob = get_param('~topics_glob')
26  services_glob = get_param('~services_glob')
27  params_glob = get_param('~params_glob')
28 
29 
30 def filter_globs(globs, full_list):
31  # If the globs are empty (weren't defined in the params), return the full list
32  if globs is not None and len(globs) > 0:
33  return [i for i in filter(lambda x: any_match(x, globs), full_list)]
34  else:
35  return full_list
36 
37 
38 def any_match(query, globs):
39  return globs is None or len(globs) == 0 or any(fnmatch.fnmatch(str(query), glob) for glob in globs)
rosapi.params.get_param
def get_param(name, default, params_glob)
Definition: params.py:62
rosapi.glob_helper.get_globs
def get_globs()
Definition: glob_helper.py:11
rosapi.glob_helper.filter_globs
def filter_globs(globs, full_list)
Definition: glob_helper.py:30
rosapi.glob_helper.any_match
def any_match(query, globs)
Definition: glob_helper.py:38


rosapi
Author(s): Jonathan Mace
autogenerated on Wed Feb 12 2025 03:14:55