From c24e8050172a1884aef170455ac75977bb7ab4e8 Mon Sep 17 00:00:00 2001 From: John-Mark Gurney Date: Tue, 25 Apr 2006 00:19:54 -0800 Subject: [PATCH] make all Objects have the checkUpdate routine, and just return self if it isn't there... This lets us update all children before sending them down the pipe... set the size properly... make FSDirectory have proper order for inheritance, so the Item checkUpdate doesn't get called instead of the FSObject's [git-p4: depot-paths = "//depot/": change = 767] --- ContentDirectory.py | 5 ++--- DIDLLite.py | 3 +++ FSStorage.py | 12 +++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ContentDirectory.py b/ContentDirectory.py index 9c60b90..6131b64 100644 --- a/ContentDirectory.py +++ b/ContentDirectory.py @@ -124,8 +124,7 @@ class ContentDirectoryControl(UPnPPublisher, dict): result = {} # check to see if object needs to be updated - if ObjectID in self and hasattr(self[ObjectID], 'checkUpdate'): - self[ObjectID].checkUpdate() + self[ObjectID].checkUpdate() # return error code if we don't exist if ObjectID not in self: @@ -134,7 +133,7 @@ class ContentDirectoryControl(UPnPPublisher, dict): try: if BrowseFlag == 'BrowseDirectChildren': ch = self.getchildren(ObjectID)[StartingIndex: StartingIndex + RequestedCount] - filter(lambda x, s = self, d = didl: d.addItem(s[x.id]) and None, ch) + filter(lambda x, s = self, d = didl: d.addItem(s[x.id].checkUpdate()) and None, ch) else: didl.addItem(self[ObjectID]) diff --git a/DIDLLite.py b/DIDLLite.py index 795eea9..cd33ba5 100644 --- a/DIDLLite.py +++ b/DIDLLite.py @@ -50,6 +50,9 @@ class Object: else: self.restricted = '0' + def checkUpdate(self): + return self + def toElement(self): root = Element(self.elementName) diff --git a/FSStorage.py b/FSStorage.py index 24de529..d4c5e20 100644 --- a/FSStorage.py +++ b/FSStorage.py @@ -30,7 +30,7 @@ class FSObject(object): try: nstat = os.stat(self.FSpath) if statcmp(self.pstat, nstat): - return + return self self.pstat = nstat self.doUpdate() @@ -41,9 +41,8 @@ class FSObject(object): self.cd.delItem(self.id) else: raise x - except: - import traceback - print traceback.print_exc() + + return self def doUpdate(self): raise NotImplementedError @@ -62,7 +61,7 @@ class FSItem(FSObject, Item): def doUpdate(self): self.res = Resource(self.url, 'http-get:*:%s:*' % self.mimetype) - self.res.size = os.path.getsize(fpath) + self.res.size = os.path.getsize(self.FSpath) class FSVideoItem(FSItem, VideoItem): pass @@ -104,7 +103,7 @@ def dofileadd(cd, parent, urlbase, path, name): return cd.addItem(parent, klass, name, urlbase = urlbase, path = os.path.join(path, name), mimetype = mt) -class FSDirectory(StorageFolder, FSObject): +class FSDirectory(FSObject, StorageFolder): def __init__(self, *args, **kwargs): path = kwargs['path'] del kwargs['path'] @@ -147,7 +146,6 @@ class FSDirectory(StorageFolder, FSObject): if nf is not None: self.pathObjmap[i] = nf log.msg('i: %s, nf: %s' % (i, nf)) - self.cd[nf].checkUpdate() # sort our children log.msg('doUpdate: %s, sorting: %s' % (self.title, list.__str__(self)))