0.24 Python Bindings
m (shift links)
m (missed one)
|Line 1:||Line 1:|
== Introduction ==
== Introduction ==
The MythTV Python bindings are a set of bindings designed to provide access to the MythTV database and interfaces in an object oriented, 'pythonic' manner. If upgrading from 0.23, please see the [[
The MythTV Python bindings are a set of bindings designed to provide access to the MythTV database and interfaces in an object oriented, 'pythonic' manner. If upgrading from 0.23, please see the [[Python bindings/Upgrade Guide|upgrade guide]].
=== Requirements ===
=== Requirements ===
Latest revision as of 08:43, 9 November 2010
The MythTV Python bindings are a set of bindings designed to provide access to the MythTV database and interfaces in an object oriented, 'pythonic' manner. If upgrading from 0.23, please see the upgrade guide.
These are the external runtime dependencies required by the python bindings. They are checked at configure time prior to installation, and the bindings will not install if these are not met.
Due to the MySQLdb dependency, Python 2.7 is currently not supported.
The data model used in the bindings is based around the DictData class, an ordered dictionary class intended to abstract lists of data provided by the backend and database, and provide them to users as dictionary values or object attributes.
- MythDB - top level database connection
- MythBE - top level mythproto connection
- MythXML - pseudo-connection for accessing the XML interface
- Frontend - connection to frontend socket control
- MythVideo - database connection for managing mythvideo
- MythMusic - database connection for managing mythmusic
- BEEventMonitor - diagnostic mythproto connection for displaying events
- MythSystemEvent - implementation of the system event handler
These classes provide access to external functions.
- System - manages calling external scripts and programs
- Grabber - modified system class for the universal grabber syntax
- VideoGrabber - modified grabber class for pulling data from MythVideo grabbers
- InternetSource - class for pulling data from MythNetvision grabbers over MythXML
- SystemEvent - modified system class emulating the system event handler in MythTV
The MythLog class intends to provide a logging faculty emulating that used by the MythTV libraries. The class accepts three keyword inputs:
- module - (optional) string, to be used for identification of log entries (def: 'pythonbindings')
- lstr - (optional) string, comma separated list of log filters
- lbit - (optional) bitwise, operator defining which log filters are active
The log filters are a number of keywords defining what sections of logs should be displayed. The stored filter is a bitwise operator, so multiple sections can be active simultaneously. If any bit in the filter matches the section specified in an individual log entry, the log will be passed. If neither 'lstr' nor 'lbit' is defined, the class will default to 'important,general'. The log filter is a global value, and will be shared among all instances of the MythLog class.
The MythLog.log method takes three inputs:
- level - bitwise operator to test against log filter
- message - log message to output
- detail - (optional) additional detail to output
The level accepts multiple values, and if any bit matches with the filter, the message will be formatted and outputted by the log. The formatting exists as:
YYYY-MM-DD HH:mm:ss.ttt <module>: <message> YYYY-MM-DD HH:mm:ss.ttt <module>: <message> - <detail>
The logger accepts multi-line messages, and will format them as:
YYYY-MM-DD HH:mm:ss.ttt <module>: <message line 1> <message line 2> <message line ...> <detail line 1> <detail line ...>
Objects of the MythLog class are callable directly, and will run this 'log' method.
The MythLog class contains several classmethods for altering the function of all open instances.
- _setlevel - accepts 'lstr' and 'lbit' inputs, can be used to directly alter the log filter
- _setfile - accepts a filename, opens a new file path to log to, closing the previous (WARNING: file will be truncated)
- _setfileobject - accepts a file object to log to, closing the previous
Five exception classes are available for error handling. All errors will have at minimum 'ecode', 'ename', and 'args' defined as attributes. 'args' will be a list with a single string at index 0. The exceptions may provide additional attributes depending on the error code.
Base exception class, can be used to except all internally thrown errors.
- SYSTEM - retcode, command, stderr
- SOCKET - sockcode, sockerr
- DB_RAW - sqlerr
- DB_CONNECTION - dbconn
- DB_SETTING - setting, hostname
- DB_SCHEMAMISMATCH - setting, remote, local
- DB_SCHEMAUPDATE - sqlerr
- PROTO_CONNECTION - backend, port
- PROTO_ANNOUNCE - backend, port, response
- PROTO_MISMATCH - remote, local
- FE_CONNECTION - frontend, port
- FR_ANNOUNCE - frontend, port
- FILE_FAILED_READ - file
- FILE_FAILED_WRITE - file, reason
For 'try' statements, MythError is a catch-all class. The exception will provide three attributes:
- args - tuple containing a single error string
- ename - string with the name of the error code
- ecode - numeric error code
The OrdDict class provides an ordered dictionary implementation. It behaves exactly as a normal dictionary, except that order of values are maintained in the order that they are added. Python 2.7 now includes an ordered dictionary implementation, so this class should be considered obsolete, and due for removal at such time as Python 2.7 or 3.x is make a minimum requirement.
The DictInvert class provides a pair of entangled dictionaries, which have their values and keys swapped. Any new entries added to one is automatically mapped to the other.
The MSearch class provides a basic UPnP search utility. The search method accepts the following inputs:
- timeout - float, number of seconds to run the search before being automatically terminated
- filter - a single string or list/tuple of strings, if given, only results whose URN is listed in the filter will be passed
The search method is a generator, only processing results as requested by the user. As with all iterables, the result is only available once, and must be stored manually if multiple uses are desired. The method returns a dictionary with the following fields:
The search method can be terminated prematurely by the terminate method.
Canned searches of searchMythBE and searchMythFE will return one instance per host found.
This class connects to a backend and will remain locked until it has received an event matching a given compiled regular expression. The 'wait' method will block until the event is received and the object unlocked.
The function takes a Myth URI and returns a file object, either from the local file system if found locally, or from a FileTransfer socket connected to the backend.