Difference between revisions of "0.24 Python Bindings"

From MythTV Official Wiki
Jump to: navigation, search
m (Advanced Use)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
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 [[Trunk Python bindings/Upgrade Guide|upgrade guide]].
+
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 [[Trunk Python bindings/Upgrade Guide|upgrade guide]].
  
 
=== Requirements ===
 
=== 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.
 
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.
* Python 2.5 (2.6+ preferred)
+
* Python 2.5 (2.6 preferred)
 
* [http://sourceforge.net/projects/mysql-python/ mysql-python] (1.2.2+ preferred)
 
* [http://sourceforge.net/projects/mysql-python/ mysql-python] (1.2.2+ preferred)
 
* [http://codespeak.net/lxml/lxml2.html lxml] 2.2.0+
 
* [http://codespeak.net/lxml/lxml2.html lxml] 2.2.0+
 +
 +
Due to the MySQLdb dependency, Python 2.7 is currently not supported.
  
 
== Data Model ==
 
== Data Model ==
Line 45: Line 47:
 
== External Classes ==
 
== External Classes ==
 
These classes provide access to external functions.
 
These classes provide access to external functions.
* System - manages calling external scripts and programs
+
* [[Trunk_Python_bindings/System_Calls#System|System]] - manages calling external scripts and programs
* Grabber  
+
* [[Trunk_Python_bindings/System_Calls#Grabber|Grabber]] - modified system class for the [[MythTV_Universal_Metadata_Format|universal grabber syntax]]
* VideoGrabber - modified system class for pulling data from MythVideo grabbers
+
* [[Trunk_Python_bindings/System_Calls#VideoGrabber|VideoGrabber]] - modified grabber class for pulling data from MythVideo grabbers
* InternetSource - class for pulling data from MythNetvision grabbers
+
* [[Trunk_Python_bindings/System_Calls#InternetSource|InternetSource]] - class for pulling data from MythNetvision grabbers over MythXML
* SystemEvent - modified system class emulating the system event handler in MythTV
+
* [[Trunk_Python_bindings/System_Calls#SystemEvent|SystemEvent]] - modified system class emulating the system event handler in MythTV
  
 
== Other Classes ==
 
== Other Classes ==
Line 68: Line 70:
 
YYYY-MM-DD HH:mm:ss.ttt <module>: <message> - <detail>
 
YYYY-MM-DD HH:mm:ss.ttt <module>: <message> - <detail>
 
</pre>
 
</pre>
 +
The logger accepts multi-line messages, and will format them as:
 +
<pre>
 +
YYYY-MM-DD HH:mm:ss.ttt <module>: <message line 1>
 +
                                  <message line 2>
 +
                                  <message line ...>
 +
                                      <detail line 1>
 +
                                      <detail line ...>
 +
<pre>
 
Objects of the MythLog class are callable directly, and will run this 'log' method.
 
Objects of the MythLog class are callable directly, and will run this 'log' method.
  
Line 121: Line 131:
  
 
== Advanced Use ==
 
== Advanced Use ==
=== schemaUpdate ===
+
* schemaUpdate
=== databaseSearch ===
+
* databaseSearch
=== SplitInt ===
+
* SplitInt
=== CMPVideo ===
+
* CMPVideo
=== CMPRecord ===
+
* CMPRecord
=== deadlinesocket ====
+
* deadlinesocket
=== MARKUPLIST ===
+
* MARKUPLIST
=== DictData ===
+
* DictData
=== DBData ===
+
* DBData
=== DBDataWrite ===
+
* DBDataWrite
=== DBDataRef ===
+
* DBDataRef
=== DBDataCRef ===
+
* DBDataCRef
=== DBConnection ===
+
* DBConnection
=== BEConnection ===
+
* BEConnection
=== FEConnection ===
+
* FEConnection
=== XMLConnection ===
+
* XMLConnection
=== DBCache ===
+
* DBCache
=== BECache ===
+
* BECache
=== BEEvent ===
+
* BEEvent
  
 
[[Category:Trunk_Python_Bindings]]
 
[[Category:Trunk_Python_Bindings]]

Revision as of 18:35, 6 August 2010

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.

Due to the MySQLdb dependency, Python 2.7 is currently not supported.

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.

Connection Classes

Data Classes

Backend Data

Database Read-Only

Database Read-Write

External Classes

These classes provide access to external functions.

Other Classes

Logging

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 ...>
<pre>
Objects of the MythLog class are callable directly, and will run this 'log' method.

=== classmethods ===
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

== Exceptions ==
Five exception classes are available for error handling:
* MythError
* MythDBError
* MythBEError
* MythFEError
* MythFileError
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.

== 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.

== Advanced Use ==
* schemaUpdate
* databaseSearch
* SplitInt
* CMPVideo
* CMPRecord
* deadlinesocket
* MARKUPLIST
* DictData
* DBData
* DBDataWrite
* DBDataRef
* DBDataCRef
* DBConnection
* BEConnection
* FEConnection
* XMLConnection
* DBCache
* BECache
* BEEvent

[[Category:Trunk_Python_Bindings]]