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 upgrade guide.

Requirements

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.

Data Model

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.

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:

Exceptions

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.

MythError

Base exception class, can be used to except all internally thrown errors.

GENERIC

SYSTEM - retcode, command, stderr

SOCKET - sockcode, sockerr

MythDBError

DB_RAW - sqlerr

DB_CONNECTION - dbconn

DB_CREDENTIALS

DB_SETTING - setting, hostname

DB_SCHEMAMISMATCH - setting, remote, local

DB_SCHEMAUPDATE - sqlerr

MythBEError

PROTO_CONNECTION - backend, port

PROTO_ANNOUNCE - backend, port, response

PROTO_MISMATCH - remote, local

PROTO_PROGRAMINFO

MythFEError

FE_CONNECTION - frontend, port

FR_ANNOUNCE - frontend, port

MythFileError

FILE_ERROR

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

Utility

OrdDict

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.

DictInvert

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.

UPnP Search

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:

content-length

request

date

usn

location

cache-control

server

ext

st

The search method can be terminated prematurely by the terminate method.

Canned searches of searchMythBE and searchMythFE will return one instance per host found.

EventLock

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.

ftopen

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.