0.24 Python Bindings
The MythTV Python 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.
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>
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:
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 exceptions may provide additional attributes depending on the error code.
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.