Skip to content

Commit

Permalink
Fix setting of values to Artwork property.
Browse files Browse the repository at this point in the history
This makes the Artwork property derived from a MutableString rather than
a unicode type, allowing the setting of values to work properly, rather
than merely by chance, and correcting an issue where importMetadata
would not apply a coverart value to Video Library entries.
  • Loading branch information
wagnerrp committed Oct 18, 2012
1 parent af9d367 commit e4b46f0
Showing 1 changed file with 35 additions and 11 deletions.
46 changes: 35 additions & 11 deletions mythtv/bindings/python/MythTV/dataheap.py
Expand Up @@ -17,20 +17,43 @@
import xml.etree.cElementTree as etree
from datetime import date, time

class Artwork( unicode ):
from UserString import MutableString
class Artwork( MutableString ):
_types = {'coverart': 'Coverart',
'coverfile': 'Coverart',
'fanart': 'Fanart',
'banner': 'Banners',
'screenshot': 'ScreenShots',
'trailer': 'Trailers'}
def __new__(self, attr, parent=None, imagetype=None):
s = u''
if parent and (parent[attr] is not None):
s = parent[attr]
return super(Artwork, self).__new__(self, s)

@property
def data(self):
try:
return self.parent[self.attr]
except:
raise RuntimeError("Artwork property must be used through an " +\
"object, not independently.")
@data.setter
def data(self, value):
try:
self.parent[self.attr] = value
except:
raise RuntimeError("Artwork property must be used through an " +\
"object, not independently.")
@data.deleter
def data(self):
try:
self.parent[self.attr] = self.parent._defaults.get(self.attr, "")
except:
raise RuntimeError("Artwork property must be used through an " +\
"object, not independently.")

def __init__(self, attr, parent=None, imagetype=None):
# replace standard MutableString init to not overwrite self.data
from warnings import warnpy3k
warnpy3k('the class UserString.MutableString has been removed in '
'Python 3.0', stacklevel=2)

self.attr = attr
if imagetype is None:
imagetype = self._types[attr]
Expand All @@ -39,24 +62,25 @@ def __init__(self, attr, parent=None, imagetype=None):

if parent:
self.hostname = parent.get('hostname', parent.get('host', None))
super(Artwork, self).__init__()

def __repr__(self):
return u"<{0.imagetype} '{0}'>".format(self)
return u"<{0.imagetype} '{0.data}'>".format(self)

def __get__(self, inst, owner):
if inst is None:
return self
return Artwork(self.attr, inst, self.imagetype)

def __set__(self, inst, value):
super(Artwork, self).__set__(inst, value)
self.parent[self.attr] = value
inst[self.attr] = value

def __delete__(self, inst):
inst[self.attr] = inst._defaults.get(self.attr, "")

@property
def exists(self):
be = FileOps(self.hostname, db = self.parent._db)
return be.fileExists(self, self.imagetype)
return be.fileExists(unicode(self), self.imagetype)

def downloadFrom(self, url):
if self.parent is None:
Expand Down

0 comments on commit e4b46f0

Please sign in to comment.