grepros 1.2.2
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
Scanner Class Reference

ROS message grepper. More...

Public Member Functions

 __init__ (self, args=None, **kwargs)
 
 __enter__ (self)
 Context manager entry, does nothing, returns self.
 
 __exit__ (self, exc_type, exc_value, traceback)
 Context manager exit, does nothing.
 
 find (self, source, highlight=None)
 Yields matched and context messages from source.
 
 get_match (self, msg)
 Returns transformed message if all patterns find a match in message, else None.
 
 match (self, topic, msg, stamp, highlight=None)
 Returns matched message if message matches search filters.
 
 validate (self, reset=False)
 Returns whether conditions have valid syntax, prints errors.
 
 work (self, source, sink)
 Greps messages yielded from source and emits matched content to 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 MatchMarkers tags, with numeric field values converted to strings beforehand.

Definition at line 36 of file search.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  args = None,
**  kwargs 
)
Parameters
argsarguments as namespace or dictionary, case-insensitive
args.patternpattern(s) to find in message field values
args.fixed_stringpattern contains ordinary strings, not regular expressions
args.caseuse case-sensitive matching in pattern
args.invertselect messages not matching pattern
args.expressionpattern(s) are a logical expression like 'this AND (this2 OR NOT "skip this")', with elements as patterns to find in message fields
args.highlighthighlight matched values
args.beforenumber of messages of leading context to emit before match
args.afternumber of messages of trailing context to emit after match
args.contextnumber of messages of leading and trailing context to emit around match, overrides args.before and args.after
args.max_countnumber of matched messages to emit (per file if bag input)
args.max_per_topicnumber of matched messages to emit from each topic
args.max_topicsnumber of topics to emit matches from
args.nth_matchemit every Nth match in topic, starting from first
args.select_fieldmessage fields to use in matching if not all
args.noselect_fieldmessage fields to skip in matching
args.match_wrapperstring 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 "**")
kwargsany and all arguments as keyword overrides, case-insensitive

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

Parameters
args.topicROS topics to read if not all
args.typeROS message types to read if not all
args.skip_topicROS topics to skip
args.skip_typeROS message types to skip
args.start_timeearliest timestamp of messages to read
args.end_timelatest timestamp of messages to read
args.start_indexmessage index within topic to start from
args.end_indexmessage index within topic to stop at
args.uniqueemit messages that are unique in topic
args.nth_messageread every Nth message in topic, starting from first
args.nth_intervalminimum time interval between messages in topic, as seconds or ROS duration
args.conditionPython expressions that must evaluate as true for message to be processable, see ConditionMixin
args.progresswhether to print progress bar
args.stop_on_errorstop execution on any error like unknown message type

Definition at line 96 of file search.py.

Member Function Documentation

◆ __enter__()

__enter__ (   self)

Context manager entry, does nothing, returns self.

Definition at line 236 of file search.py.

◆ __exit__()

__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)

Context manager exit, does nothing.

Definition at line 241 of file search.py.

◆ find()

find (   self,
  source,
  highlight = None 
)

Yields matched and context messages from source.

Parameters
sourceinputs.Source or api.Bag instance
highlightwhether to highlight matched values in message fields, defaults to flag from constructor
Returns
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 143 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 472 of file search.py.

◆ match()

match (   self,
  topic,
  msg,
  stamp,
  highlight = None 
)

Returns matched message if message matches search filters.

Parameters
topictopic name
msgROS message
stampmessage ROS timestamp
highlightwhether to highlight matched values in message fields, defaults to flag from constructor
Returns
original or highlighted message on match else None

Definition at line 162 of file search.py.

◆ validate()

validate (   self,
  reset = False 
)

Returns whether conditions have valid syntax, prints errors.

Definition at line 210 of file search.py.

◆ work()

work (   self,
  source,
  sink 
)

Greps messages yielded from source and emits matched content to sink.

Parameters
sourceinputs.Source or api.Bag instance
sinkoutputs.Sink instance
Returns
count matched

Definition at line 196 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: