make Containers contain their own list of children... add the containing ContentDirectory to the Items so that they can add children to themselves... [git-p4: depot-paths = "//depot/": change = 762]replace/4e84fdb41ea781c7a8f872baa423e8b3be4045a7
@@ -39,17 +39,25 @@ class ContentDirectoryControl(UPnPPublisher, dict): | |||||
def addContainer(self, parent, title, klass = Container, **kwargs): | def addContainer(self, parent, title, klass = Container, **kwargs): | ||||
ret = self.addItem(parent, klass, title, **kwargs) | ret = self.addItem(parent, klass, title, **kwargs) | ||||
self.children[ret] = [] | |||||
self.children[ret] = self[ret] | |||||
return ret | return ret | ||||
def addItem(self, parent, klass, *args, **kwargs): | def addItem(self, parent, klass, *args, **kwargs): | ||||
assert isinstance(self[parent], Container) | assert isinstance(self[parent], Container) | ||||
nid = self.getnextID() | nid = self.getnextID() | ||||
i = klass(nid, parent, *args, **kwargs) | |||||
i = klass(self, nid, parent, *args, **kwargs) | |||||
self.children[parent].append(i) | self.children[parent].append(i) | ||||
self[i.id] = i | self[i.id] = i | ||||
return i.id | return i.id | ||||
def delItem(self, id): | |||||
if isinstance(self[id], Container): | |||||
for i in self.children[id]: | |||||
self.delItem(i) | |||||
assert len(self.children[id]) == 0 | |||||
del self.children[id] | |||||
del self[id] | |||||
def getchildren(self, item): | def getchildren(self, item): | ||||
assert isinstance(self[item], Container) | assert isinstance(self[item], Container) | ||||
return self.children[item][:] | return self.children[item][:] | ||||
@@ -36,9 +36,10 @@ class Object: | |||||
res = None | res = None | ||||
writeStatus = None | writeStatus = None | ||||
def __init__(self, id, parentID, title, restricted = False, | |||||
def __init__(self, cd, id, parentID, title, restricted = False, | |||||
creator = None): | creator = None): | ||||
self.cd = cd | |||||
self.id = id | self.id = id | ||||
self.parentID = parentID | self.parentID = parentID | ||||
self.title = title | self.title = title | ||||
@@ -203,19 +204,20 @@ class PlaylistItem(Item): | |||||
class TextItem(Item): | class TextItem(Item): | ||||
klass = Item.klass + '.textItem' | klass = Item.klass + '.textItem' | ||||
class Container(Object): | |||||
class Container(Object, list): | |||||
"""An object that can contain other objects.""" | """An object that can contain other objects.""" | ||||
klass = Object.klass + '.container' | klass = Object.klass + '.container' | ||||
elementName = 'container' | elementName = 'container' | ||||
childCount = 0 | |||||
childCount = property(lambda x: len(x)) | |||||
createClass = None | createClass = None | ||||
searchClass = None | searchClass = None | ||||
searchable = None | searchable = None | ||||
def __init__(self, id, parentID, title, restricted = 0, creator = None): | |||||
Object.__init__(self, id, parentID, title, restricted, creator) | |||||
def __init__(self, cd, id, parentID, title, restricted = 0, creator = None): | |||||
Object.__init__(self, cd, id, parentID, title, restricted, creator) | |||||
list.__init__(self) | |||||
def toElement(self): | def toElement(self): | ||||