Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
grepros.search.Scanner Class Reference
Inheritance diagram for grepros.search.Scanner:
Inheritance graph
[legend]

Public Member Functions

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

Public Attributes

 args
 
 sink
 Sink instance. More...
 
 source
 Source instance. More...
 

Static Public Attributes

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

Private Member Functions

def _clear_data (self)
 
def _configure_flags (self, highlight=None)
 
def _generate (self)
 
def _generate_context (self, topickey, before=False)
 
def _has_in_window (self, topickey, length, status, full=False)
 
def _is_max_done (self)
 
def _is_processable (self, topic, msg, stamp)
 
def _parse_patterns (self)
 
def _prepare (self, source, sink=None, highlight=None)
 
def _prune_data (self, topickey)
 
def _register_message (self, topickey, msgid, msg, stamp)
 

Private Attributes

 _brute_prechecks
 
 _counts
 
 _highlight
 
 _idcounter
 
 _messages
 
 _passthrough
 
 _patterns
 
 _stamps
 
 _statuses
 

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 26 of file search.py.

Constructor & Destructor Documentation

◆ __init__()

def grepros.search.Scanner.__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.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
@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
@param   args.nth_interval        minimum time interval between messages in topic
@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 48 of file search.py.

Member Function Documentation

◆ __enter__()

def grepros.search.Scanner.__enter__ (   self)
Context manager entry, does nothing, returns self.

Definition at line 191 of file search.py.

◆ __exit__()

def grepros.search.Scanner.__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)
Context manager exit, does nothing.

Definition at line 196 of file search.py.

◆ _clear_data()

def grepros.search.Scanner._clear_data (   self)
private
Clears local structures.

Definition at line 274 of file search.py.

◆ _configure_flags()

def grepros.search.Scanner._configure_flags (   self,
  highlight = None 
)
private
Sets highlight and passthrough flags from current settings.

Definition at line 334 of file search.py.

◆ _generate()

def grepros.search.Scanner._generate (   self)
private
Yields matched and context messages from source.

@return  tuples of (topic, msg, stamp, matched optionally highlighted msg, index in topic)

Definition at line 201 of file search.py.

◆ _generate_context()

def grepros.search.Scanner._generate_context (   self,
  topickey,
  before = False 
)
private
Yields before/after context for latest match.

Definition at line 260 of file search.py.

◆ _has_in_window()

def grepros.search.Scanner._has_in_window (   self,
  topickey,
  length,
  status,
  full = False 
)
private
Returns whether given status exists in recent message window.

Definition at line 362 of file search.py.

◆ _is_max_done()

def grepros.search.Scanner._is_max_done (   self)
private
Returns whether max match count has been reached (and message after-context emitted).

Definition at line 344 of file search.py.

◆ _is_processable()

def grepros.search.Scanner._is_processable (   self,
  topic,
  msg,
  stamp 
)
private
Returns whether processing current message in topic is acceptable:
that topic or total maximum count has not been reached,
and current message in topic is in configured range, if any.

Definition at line 238 of file search.py.

◆ _parse_patterns()

def grepros.search.Scanner._parse_patterns (   self)
private
Parses pattern arguments into re.Patterns.

Definition at line 300 of file search.py.

◆ _prepare()

def grepros.search.Scanner._prepare (   self,
  source,
  sink = None,
  highlight = None 
)
private
Clears local structures, binds and registers source and sink, if any.

Definition at line 281 of file search.py.

◆ _prune_data()

def grepros.search.Scanner._prune_data (   self,
  topickey 
)
private
Drops history older than context window.

Definition at line 290 of file search.py.

◆ _register_message()

def grepros.search.Scanner._register_message (   self,
  topickey,
  msgid,
  msg,
  stamp 
)
private
Registers message with local structures.

Definition at line 326 of file search.py.

◆ find()

def grepros.search.Scanner.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 116 of file search.py.

◆ get_match()

def grepros.search.Scanner.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 369 of file search.py.

◆ match()

def grepros.search.Scanner.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 135 of file search.py.

◆ work()

def grepros.search.Scanner.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 172 of file search.py.

Member Data Documentation

◆ _brute_prechecks

grepros.search.Scanner._brute_prechecks
private

Definition at line 101 of file search.py.

◆ _counts

grepros.search.Scanner._counts
private

Definition at line 97 of file search.py.

◆ _highlight

grepros.search.Scanner._highlight
private

Definition at line 103 of file search.py.

◆ _idcounter

grepros.search.Scanner._idcounter
private

Definition at line 102 of file search.py.

◆ _messages

grepros.search.Scanner._messages
private

Definition at line 93 of file search.py.

◆ _passthrough

grepros.search.Scanner._passthrough
private

Definition at line 104 of file search.py.

◆ _patterns

grepros.search.Scanner._patterns
private

Definition at line 91 of file search.py.

◆ _stamps

grepros.search.Scanner._stamps
private

Definition at line 95 of file search.py.

◆ _statuses

grepros.search.Scanner._statuses
private

Definition at line 99 of file search.py.

◆ ANY_MATCHES

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

Match patterns for global any-match.

Definition at line 39 of file search.py.

◆ args

grepros.search.Scanner.args

Definition at line 111 of file search.py.

◆ DEFAULT_ARGS

grepros.search.Scanner.DEFAULT_ARGS
static
Initial value:
= dict(PATTERN=(), CASE=False, FIXED_STRING=False, INVERT=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 42 of file search.py.

◆ GrepMessage

grepros.search.Scanner.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 36 of file search.py.

◆ sink

grepros.search.Scanner.sink

Sink instance.

Definition at line 109 of file search.py.

◆ source

grepros.search.Scanner.source

Source instance.

Definition at line 107 of file search.py.


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


grepros
Author(s): Erki Suurjaak
autogenerated on Sat Jan 6 2024 03:11:30