Difference between revisions of "0.23 Python bindings/Data Objects"

From MythTV Official Wiki
Jump to: navigation, search
(add crosslinks to Python Bindings)
(Job())
Line 89: Line 89:
 
<span id="Job"></span>
 
<span id="Job"></span>
 
==Job(id=None, chanid=None, starttime=None, db=None, raw=None)==
 
==Job(id=None, chanid=None, starttime=None, db=None, raw=None)==
 +
This class provides an two ways to initialize an object; either define the jobid, or define both chanid and starttime.
 +
<pre>
 +
>>> Job(3780)
 +
<Job '3780' at 0x803da9cd0>
 +
>>> Job(chanid=2069, starttime=20100309220000)
 +
<Job '3780' at 0x803dd5450>
 +
>>> Job(None, 2069, 20100309220000)
 +
<Job '3780' at 0x803da9cd0>
 +
</pre>
 +
 +
===setComment(comment)===
 +
Shortcut to updating the comment string for an existing job. Allows in-progress messages and persistent exit messages to be set.
 +
 +
===setStatus(status)===
 +
Shortcut to updating the status value.
 +
 
===created by===
 
===created by===
 
* [[Python_bindings#searchJobs.28.2A.2Akwargs.29|MythDB.searchJobs]]
 
* [[Python_bindings#searchJobs.28.2A.2Akwargs.29|MythDB.searchJobs]]
 
<span id="Channel"></span>
 
<span id="Channel"></span>
 +
 
==Channel(chanid=None, db=None, raw=None)==
 
==Channel(chanid=None, db=None, raw=None)==
 
===created by===
 
===created by===

Revision as of 03:58, 10 March 2010

The basic data object supplied by the Python bindings is designed to operate as a dictionary or as a class with attributes.

>>> prog = be.getRecordings()[0]
>>> prog.keys()
['title', 'subtitle', 'description', 'category', 'chanid', 'channum', 'callsign', 'channame', 'filename', 'fs_high', 'fs_low', 'starttime', 'endtime', 'duplicate', 'shareable', 'findid', 'hostname', 'sourceid', 'cardid', 'inputid', 'recpriority', 'recstatus', 'recordid', 'rectype', 'dupin', 'dupmethod', 'recstartts', 'recendts', 'repeat', 'programflags', 'recgroup', 'commfree', 'outputfilters', 'seriesid', 'programid', 'lastmodified', 'stars', 'airdate', 'hasairdate', 'playgroup', 'recpriority2', 'parentid', 'storagegroup', 'audio_props', 'video_props', 'subtitle_type', 'year']
>>> prog.title
u'Psych'
>>> prog['channame']
u'USA Network'
>>> a = prog.iteritems()
>>> a.next()
('title', u'Psych')

Data Only objects

These objects are read only, and populated by data from the backend.

Program(raw)

This class is the standard Program Info structure used by the backend protocol. It provides the following fields: title, subtitle, description, category, chanid, channum, callsign, channame, filename, fs_high, fs_low, starttime, endtime, duplicate, shareable, findid, hostname, sourceid, cardid, inputid, recpriority, recstatus, recordid, rectype, dupin, dupmethod, recstartts, recendts, repeat, programflags, recgroup, commfree, outputfilters, seriesid, programid, lastmodified, stars, airdate, hasairdate, playgroup, recpriority2, parentid, storagegroup, audio_props, video_props, subtitle_type, year. Additionally, the 'filesize' attribute is is calculated from 'fs_high' and 'fs_low'.

toString()

Produces a string representation of the data, for use with backend protocol commands.

delete(force=False, rerecord=False)

Issues a protocol command to tell the backend to delete the recording. 'force' will force the delete even if the backend could not find the file. 'rerecord' informs the scheduler to allow the show to be recorded again.

getRecorded()

Returns a matching Recorded object.

open(type='r')

Returns a file object, defaults to read access.

created by

This type of object is returned by the following methods:

FreeSpace(raw)

This class provides basic statistics for a storage group folder. It provides the following fields: host, path, islocal, disknumber, sgroupid, blocksize, ts_high, ts_low, us_high, us_low. Additionally, the following attributes are calculated: totalspace, freespace, usedspace

>>> be.getFreeSpace()
>>> fs = be.getFreeSpace()
>>> fs
[<FreeSpace '/mnt/mythtv/fserve_1/video@mythbe' at 0x803952e50>, <FreeSpace '/mnt/mythtv/fserve_2/video@mythbe' at 0x803952c50>, <FreeSpace '/mnt/mythtv/fserve_3/video@mythbe' at 0x803952ed0>]
>>> fs[0].items()
[('host', u'mythbe'), ('path', u'/mnt/mythtv/fserve_1/video'), ('islocal', True), ('disknumber', -1), ('sgroupid', 35), ('blocksize', 32768), ('ts_high', 0), ('ts_low', 286948096), ('us_high', 0), ('us_low', 203925376)]
>>> fs[0].totalspace
286948096
>>> fs[0].freespace
83022720

created by

Read Only Database objects

These classes correspond to one entry in a specific database table. The provided data fields will match those in the database. These classes provide a 'getAllEntries()' method which returns a list of all such objects in the database.

>>> StorageGroup().getAllEntries()
[<StorageGroup 'myth://Default@fserve/mnt/mythtv/fserve_1/video/' at 0x803c8fe90>, <StorageGroup 'myth://Default@fserve/mnt/mythtv/fserve_3/video/' at 0x803c94090>]

StorageGroup(id=None, db=None, raw=None)

This class provides information from the storagegroup database table. In addition to the database information, a boolean 'local' attribute specifies whether a storage group folder is accessible on the local machine.

>>> db = MythDB()
>>> sg = db.getStorageGroup()[0]
>>> sg
<StorageGroup 'myth://Videos@mythbe.wagnerrp.com/mnt/mythtv/store/media/video/' at 0x803dad810>
>>> sg.id
5L
>>> sg.local
False

created by

Guide(data=None, db=None, raw=None)

This class provides information for a show listing in the program guide.

record(type=kAllRecord)

Return a new Record object for a recording rule, using the optional record type.

created by

Read-Write Database objects

These classes provide write capacity to certain database tables. Included beyond the read-only types are methods 'create()', 'update()', and 'delete()'. Create only works on an object with no 'wheredat' attribute set, while update and delete only work with the attribute set. Create takes an optional dictionary for additional information, returning the new row id. Update follows standard dict.update() syntax. All updates to the database will be sanitized, preventing certain fields from being written, and providing default values for others.

Job(id=None, chanid=None, starttime=None, db=None, raw=None)

This class provides an two ways to initialize an object; either define the jobid, or define both chanid and starttime.

>>> Job(3780)
<Job '3780' at 0x803da9cd0>
>>> Job(chanid=2069, starttime=20100309220000)
<Job '3780' at 0x803dd5450>
>>> Job(None, 2069, 20100309220000)
<Job '3780' at 0x803da9cd0>

setComment(comment)

Shortcut to updating the comment string for an existing job. Allows in-progress messages and persistent exit messages to be set.

setStatus(status)

Shortcut to updating the status value.

created by

Channel(chanid=None, db=None, raw=None)

created by

Video(id=None, db=None, raw=None)

created by

Record(id=None, db=None, raw=None)

created by

Recorded(data=None, db=None, raw=None)

created by

RecordedProgram(data=None, db=None, raw=None)

created by

OldRecorded(data=None, db=None, raw=None)

created by