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

Base class for writing messages to a database. More...

Inheritance diagram for BaseDataSink:
Inheritance graph

Public Member Functions

 __init__ (self, args=None, **kwargs)
 
 close (self)
 Closes database connection, if any, emits metainfo.
 
 close_output (self)
 Closes database connection, if any, executing any pending statements.
 
 emit (self, topic, msg, stamp=None, match=None, index=None)
 Writes message to database.
 
 validate (self)
 Returns whether args.write_options has valid values, if any.
 
- Public Member Functions inherited from Sink
 __init__ (self, args=None, **kwargs)
 
 __enter__ (self)
 Context manager entry.
 
 __exit__ (self, exc_type, exc_value, traceback)
 Context manager exit, closes sink.
 
 autodetect (cls, target)
 Returns true if target is recognizable as output for this sink class.
 
 bind (self, source)
 Attaches source to sink.
 
 close (self)
 Shuts down output, closing any files or connections.
 
 configure (self, args=None, **kwargs)
 Updates sink configuration.
 
 emit (self, topic, msg, stamp=None, match=None, index=None)
 Outputs ROS message.
 
 emit_meta (self)
 Outputs source metainfo like bag header as debug stream, if not already emitted.
 
 flush (self)
 Writes out any pending data to disk.
 
 is_highlighting (self)
 Returns whether this sink requires highlighted matches.
 
 thread_excepthook (self, text, exc)
 Handles exception, used by background threads.
 
 validate (self)
 Returns whether sink prerequisites are met (like ROS environment set if LiveSink).
 
 __init__ (self, args=None, **kwargs)
 
 close (self)
 Clears data structures.
 
 validate (self)
 Returns whether arguments are valid.
 

Public Attributes

 close
 
 COMMIT_INTERVAL
 
 db
 Database connection.
 
- Public Attributes inherited from Sink
 args
 
 source
 inputs.Source instance bound to this sink
 
 valid
 Result of validate()
 
- Public Attributes inherited from SqlMixin
 DIALECTS
 

Static Public Attributes

int COMMIT_INTERVAL = 1000
 Number of emits between commits; 0 is autocommit.
 
 DEFAULT_ARGS = dict(META=False, WRITE_OPTIONS={}, VERBOSE=False)
 Constructor argument defaults.
 
 ENGINE = None
 Database engine name, overridden in subclasses.
 
list MESSAGE_TYPE_BASECOLS
 Default columns for pkg/MsgType tables.
 
list MESSAGE_TYPE_NESTCOLS
 Additional default columns for pkg/MsgType tables with nesting output.
 
list MESSAGE_TYPE_TOPICCOLS
 Default topic-related columns for pkg/MsgType tables.
 
- Static Public Attributes inherited from Sink
 DEFAULT_ARGS = dict(META=False)
 Constructor argument defaults.
 
tuple FILE_EXTENSIONS = ()
 Auto-detection file extensions for subclasses, as (".ext", )
 
- Static Public Attributes inherited from SqlMixin
 DEFAULT_ARGS = dict(WRITE_OPTIONS={})
 Constructor argument defaults.
 
str DEFAULT_DIALECT = "sqlite"
 Default SQL dialect used if dialect not specified.
 
dict DIALECTS
 Supported SQL dialects and options.
 
list KEYWORDS
 Words that need quoting if in name context, like table name.
 

Detailed Description

Base class for writing messages to a database.

Output will have:

  • table "topics", with topic and message type names
  • table "types", with message type definitions

plus:

  • table "pkg/MsgType" for each topic message type, with detailed fields, BYTEA fields for uint8[], array fields for scalar list attributes, and JSONB fields for lists of ROS messages; with foreign keys if nesting else subtype values as JSON dictionaries; plus underscore-prefixed fields for metadata, like _topic as the topic name. If not nesting, only topic message type tables are created.
  • view "/full/topic/name" for each topic, selecting from the message type table

If a message type table already exists but for a type with a different MD5 hash, the new table will have its MD5 hash appended to end, as "pkg/MsgType (hash)".

Definition at line 43 of file dbbase.py.

Constructor & Destructor Documentation

◆ __init__()

__init__ (   self,
  args = None,
**  kwargs 
)
Parameters
argsarguments as namespace or dictionary, case-insensitive; or a single item as the database connection string
args.writedatabase connection string
args.write_options
{"commit-interval": transaction size (0 is autocommit),
"nesting": "array" to recursively insert arrays
            of nested types, or "all" for any nesting)}
args.metawhether to emit metainfo
args.verbosewhether to emit debug information
kwargsany and all arguments as keyword overrides, case-insensitive

Reimplemented from Sink.

Reimplemented in PostgresSink, and SqliteSink.

Definition at line 81 of file dbbase.py.

Member Function Documentation

◆ close()

close (   self)

Closes database connection, if any, emits metainfo.

Reimplemented from Sink.

Definition at line 142 of file dbbase.py.

◆ close_output()

close_output (   self)

Closes database connection, if any, executing any pending statements.

Definition at line 167 of file dbbase.py.

◆ emit()

emit (   self,
  topic,
  msg,
  stamp = None,
  match = None,
  index = None 
)

Writes message to database.

Reimplemented from Sink.

Reimplemented in SqliteSink.

Definition at line 130 of file dbbase.py.

◆ validate()

validate (   self)

Returns whether args.write_options has valid values, if any.

Checks parameters "commit-interval" and "nesting".

Reimplemented from Sink.

Reimplemented in PostgresSink, and SqliteSink.

Definition at line 112 of file dbbase.py.

Member Data Documentation

◆ close

close

Definition at line 104 of file dbbase.py.

◆ COMMIT_INTERVAL [1/2]

int COMMIT_INTERVAL = 1000
static

Number of emits between commits; 0 is autocommit.

Definition at line 49 of file dbbase.py.

◆ COMMIT_INTERVAL [2/2]

COMMIT_INTERVAL

Definition at line 187 of file dbbase.py.

◆ db

db

Database connection.

Definition at line 88 of file dbbase.py.

◆ DEFAULT_ARGS

DEFAULT_ARGS = dict(META=False, WRITE_OPTIONS={}, VERBOSE=False)
static

Constructor argument defaults.

Definition at line 64 of file dbbase.py.

◆ ENGINE

ENGINE = None
static

Database engine name, overridden in subclasses.

Definition at line 46 of file dbbase.py.

◆ MESSAGE_TYPE_BASECOLS

list MESSAGE_TYPE_BASECOLS
static
Initial value:
= [("_dt", "TIMESTAMP"),
("_timestamp", "INTEGER"),
("_id", "INTEGER NOT NULL "
"PRIMARY KEY AUTOINCREMENT"), ]

Default columns for pkg/MsgType tables.

Definition at line 55 of file dbbase.py.

◆ MESSAGE_TYPE_NESTCOLS

list MESSAGE_TYPE_NESTCOLS
static
Initial value:
= [("_parent_type", "TEXT"),
("_parent_id", "INTEGER"), ]

Additional default columns for pkg/MsgType tables with nesting output.

Definition at line 60 of file dbbase.py.

◆ MESSAGE_TYPE_TOPICCOLS

list MESSAGE_TYPE_TOPICCOLS
static
Initial value:
= [("_topic", "TEXT"),
("_topic_id", "INTEGER"), ]

Default topic-related columns for pkg/MsgType tables.

Definition at line 52 of file dbbase.py.


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