From 6b48c04a1959213506ac48f1efeb2c0a098a078c Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 25 Apr 2006 09:36:37 -0800 Subject: [PATCH] properly handle UpdateID's... and have Item's automaticly propagate changes up to parent... [git-p4: depot-paths = "//depot/": change = 768] --- ContentDirectory.py | 12 ++---------- DIDLLite.py | 8 ++++++++ FSStorage.py | 3 +++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/ContentDirectory.py b/ContentDirectory.py index 6131b64..dbcef3b 100644 --- a/ContentDirectory.py +++ b/ContentDirectory.py @@ -69,19 +69,12 @@ class ContentDirectoryControl(UPnPPublisher, dict): fakeparent = '-1' self.nextID = 0 self.children = { fakeparent: []} - self.needupdate = False - self.updateId = 0 self[fakeparent] = Container(None, None, '-1', 'fake') root = self.addContainer(fakeparent, title) assert root == '0' del self[fakeparent] del self.children[fakeparent] - def doupdate(self): - if self.needupdate: - self.needupdate += 1 - self.needupdate = False - # Required actions def soap_GetSearchCapabilities(self, *args, **kwargs): @@ -101,8 +94,7 @@ class ContentDirectoryControl(UPnPPublisher, dict): """Required: Return the current value of state variable SystemUpdateID.""" log.msg('GetSystemUpdateID()') - self.needupdate = True - return { 'SystemUpdateIdResponse': { 'Id': self.updateId }} + return { 'SystemUpdateIdResponse': { 'Id': self['0'].updateID }} BrowseFlags = ('BrowseMetaData', 'BrowseDirectChildren') @@ -140,7 +132,7 @@ class ContentDirectoryControl(UPnPPublisher, dict): result = {'BrowseResponse': {'Result': didl.toString() , 'NumberReturned': didl.numItems(), 'TotalMatches': didl.numItems(), - 'UpdateID': 0}} + 'UpdateID': self[ObjectID].updateID }} except: traceback.print_exc(file=log.logfile) diff --git a/DIDLLite.py b/DIDLLite.py index cd33ba5..314dacf 100644 --- a/DIDLLite.py +++ b/DIDLLite.py @@ -86,6 +86,10 @@ class Item(Object): elementName = 'item' refID = None + def doUpdate(self): + # Update parent container + self.cd[self.parentID].doUpdate() + def toElement(self): root = Object.toElement(self) @@ -217,11 +221,15 @@ class Container(Object, list): createClass = None searchClass = None searchable = None + updateID = 0 def __init__(self, cd, id, parentID, title, restricted = 0, creator = None): Object.__init__(self, cd, id, parentID, title, restricted, creator) list.__init__(self) + def doUpdate(self): + self.updateID = (self.updateID + 1) % (1l << 32) + def toElement(self): root = Object.toElement(self) diff --git a/FSStorage.py b/FSStorage.py index d4c5e20..3083576 100644 --- a/FSStorage.py +++ b/FSStorage.py @@ -62,6 +62,7 @@ class FSItem(FSObject, Item): def doUpdate(self): self.res = Resource(self.url, 'http-get:*:%s:*' % self.mimetype) self.res.size = os.path.getsize(self.FSpath) + Item.doUpdate(self) class FSVideoItem(FSItem, VideoItem): pass @@ -151,3 +152,5 @@ class FSDirectory(FSObject, StorageFolder): log.msg('doUpdate: %s, sorting: %s' % (self.title, list.__str__(self))) self.sort(lambda x, y: cmp(x.title, y.title)) log.msg('sorted') + + StorageFolder.doUpdate(self)