grepros 1.3.0
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
Scanner Class Reference
Inheritance diagram for Scanner:
Inheritance graph

Public Member Functions

 __init__ (self, args=None, **kwargs)
 
 __enter__ (self)
 
 __exit__ (self, exc_type, exc_value, traceback)
 
 find (self, source, highlight=None)
 
 get_match (self, msg)
 
 match (self, topic, msg, stamp, highlight=None)
 
 validate (self, reset=False)
 
 work (self, source, sink)
 

Public Attributes

 args
 
 args0
 
 sink
 Sink instance.
 
 source
 Source instance.
 
 valid
 Result of validate()
 

Static Public Attributes

list ANY_MATCHES = [((), re.compile("(.*)", re.DOTALL)), (), re.compile("(.?)", re.DOTALL)]
 Match patterns for global any-match.
 
 DEFAULT_ARGS
 Constructor argument defaults.
 
 GrepMessage = collections.namedtuple("BagMessage", "topic message timestamp match index")
 Namedtuple of (topic name, ROS message, ROS time object, message if matched, index in topic).
 

Detailed Description

ROS message grepper.

In highlighted results, message field values that match search criteria are modified
to wrap the matching parts in {@link grepros.common.MatchMarkers MatchMarkers} tags,
with numeric field values converted to strings beforehand.

Definition at line 29 of file search.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  args = None,
**  kwargs 
)
@param   args                     arguments as namespace or dictionary, case-insensitive
@param   args.pattern             pattern(s) to find in message field values
@param   args.fixed_string        pattern contains ordinary strings, not regular expressions
@param   args.case                use case-sensitive matching in pattern
@param   args.invert              select messages not matching pattern
@param   args.expression          pattern(s) are a logical expression
                                  like 'this AND (this2 OR NOT "skip this")',
                                  with elements as patterns to find in message fields
@param   args.highlight           highlight matched values
@param   args.before              number of messages of leading context to emit before match
@param   args.after               number of messages of trailing context to emit after match
@param   args.context             number of messages of leading and trailing context to emit
                                  around match, overrides args.before and args.after
@param   args.max_count           number of matched messages to emit (per file if bag input)
@param   args.max_per_topic       number of matched messages to emit from each topic
@param   args.max_topics          number of topics to emit matches from
@param   args.nth_match           emit every Nth match in topic, starting from first
@param   args.select_field        message fields to use in matching if not all
@param   args.noselect_field      message fields to skip in matching
@param   args.match_wrapper       string to wrap around matched values in find() and match(),
                                  both sides if one value, start and end if more than one,
                                  or no wrapping if zero values (default "**")
@param   kwargs                   any and all arguments as keyword overrides, case-insensitive
<!--sep-->

Additional arguments when using match() or find(grepros.api.Bag):

@param   args.topic               ROS topics to read if not all
@param   args.type                ROS message types to read if not all
@param   args.skip_topic          ROS topics to skip
@param   args.skip_type           ROS message types to skip
@param   args.start_time          earliest timestamp of messages to read
@param   args.end_time            latest timestamp of messages to read
@param   args.start_index         message index within topic to start from
@param   args.end_index           message index within topic to stop at
@param   args.unique              emit messages that are unique in topic
@param   args.nth_message         read every Nth message in topic, starting from first
@param   args.nth_interval        minimum time interval between messages in topic,
                                  as seconds or ROS duration
@param   args.condition           Python expressions that must evaluate as true
                                  for message to be processable, see ConditionMixin
@param   args.progress            whether to print progress bar
@param   args.stop_on_error       stop execution on any error like unknown message type

Definition at line 51 of file search.py.

Member Function Documentation

◆ __enter__()

__enter__ (   self)
Context manager entry, does nothing, returns self.

Definition at line 237 of file search.py.

◆ __exit__()

__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)
Context manager exit, does nothing.

Definition at line 242 of file search.py.

◆ find()

find (   self,
  source,
  highlight = None 
)
Yields matched and context messages from source.

@param   source     inputs.Source or api.Bag instance
@param   highlight  whether to highlight matched values in message fields,
                    defaults to flag from constructor
@return             GrepMessage namedtuples of
                    (topic, message, timestamp, match, index in topic),
                    where match is matched optionally highlighted message
                    or `None` if yielding a context message

Definition at line 131 of file search.py.

◆ get_match()

get_match (   self,
  msg 
)
Returns transformed message if all patterns find a match in message, else None.

Matching field values are converted to strings and surrounded by markers.
Returns original message if any-match and sink does not require highlighting.

Definition at line 445 of file search.py.

◆ match()

match (   self,
  topic,
  msg,
  stamp,
  highlight = None 
)
Returns matched message if message matches search filters.

@param   topic      topic name
@param   msg        ROS message
@param   stamp      message ROS timestamp
@param   highlight  whether to highlight matched values in message fields,
                    defaults to flag from constructor
@return             original or highlighted message on match else `None`

Definition at line 152 of file search.py.

◆ validate()

validate (   self,
  reset = False 
)
Returns whether conditions have valid syntax, prints errors.

Definition at line 211 of file search.py.

◆ work()

work (   self,
  source,
  sink 
)
Greps messages yielded from source and emits matched content to sink.

@param   source  inputs.Source or api.Bag instance
@param   sink    outputs.Sink instance
@return          count matched

Definition at line 190 of file search.py.

Member Data Documentation

◆ ANY_MATCHES

list ANY_MATCHES = [((), re.compile("(.*)", re.DOTALL)), (), re.compile("(.?)", re.DOTALL)]
static

Match patterns for global any-match.

Definition at line 42 of file search.py.

◆ args

args

Definition at line 127 of file search.py.

◆ args0

args0

Definition at line 126 of file search.py.

◆ DEFAULT_ARGS

DEFAULT_ARGS
static
Initial value:
= dict(PATTERN=(), CASE=False, FIXED_STRING=False, INVERT=False, EXPRESSION=False,
HIGHLIGHT=False, NTH_MATCH=1, BEFORE=0, AFTER=0, CONTEXT=0, MAX_COUNT=0,
MAX_PER_TOPIC=0, MAX_TOPICS=0, SELECT_FIELD=(), NOSELECT_FIELD=(),
MATCH_WRAPPER="**")

Constructor argument defaults.

Definition at line 45 of file search.py.

◆ GrepMessage

GrepMessage = collections.namedtuple("BagMessage", "topic message timestamp match index")
static

Namedtuple of (topic name, ROS message, ROS time object, message if matched, index in topic).

Definition at line 39 of file search.py.

◆ sink

sink

Sink instance.

Definition at line 122 of file search.py.

◆ source

source

Source instance.

Definition at line 120 of file search.py.

◆ valid

valid

Result of validate()

Definition at line 124 of file search.py.


The documentation for this class was generated from the following file: