plugin file: progressFinished and progressError are now sent on SatFile.close. eof Deferred attribute is removed, as it is not used and bring unnecessary complication

This commit is contained in:
Goffi 2015-11-16 00:24:49 +01:00
commit 7f8dc5849f

View file

@ -68,14 +68,16 @@ class SatFile(object):
self._file = open(path, mode)
self.size = size
self.profile = profile
self.eof = defer.Deferred()
self.host.registerProgressCb(self.uid, self.getProgress, profile)
self.host.bridge.progressStarted(self.uid, self.profile)
self.eof.addCallback(lambda ignore: self.host.bridge.progressFinished(self.uid, self.profile))
self.eof.addErrback(lambda failure: self.host.bridge.progressError(self.uid, unicode(failure), self.profile))
def close(self):
position = self._file.tell()
self._file.close()
if not self.size or self.size == position:
self.host.bridge.progressFinished(self.uid, self.profile)
else:
self.host.bridge.progressError(self.uid, u"size doesn't match", self.profile)
self.host.removeProgressCb(self.uid, self.profile)
def flush(self):
@ -86,8 +88,6 @@ class SatFile(object):
def read(self, size=-1):
read = self._file.read(size)
if not read:
self.eof.callback(None)
return read
def seek(self, offset, whence=os.SEEK_SET):