From 316a1bf20fa8cf95a7399f14757e8aed35ac7401 Mon Sep 17 00:00:00 2001 From: Thomas Adamcik Date: Sat, 18 Jan 2014 01:30:02 +0100 Subject: [PATCH] local: Ensure logging does not divide by zero in scanner. --- docs/ext/local.rst | 1 + mopidy/local/commands.py | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/ext/local.rst b/docs/ext/local.rst index 5d3562a9..31d00d66 100644 --- a/docs/ext/local.rst +++ b/docs/ext/local.rst @@ -90,6 +90,7 @@ See :ref:`config` for general help on configuring Mopidy. Number of tracks to wait before telling library it should try and store its progress so far. Some libraries might not respect this setting. + Set this to zero to disable flushing. .. confval:: local/excluded_file_extensions diff --git a/mopidy/local/commands.py b/mopidy/local/commands.py index 5e4bfe62..85939b43 100644 --- a/mopidy/local/commands.py +++ b/mopidy/local/commands.py @@ -144,10 +144,14 @@ class _Progress(object): def increment(self): self.count += 1 - return self.count % self.batch_size == 0 + return self.batch_size and self.count % self.batch_size == 0 def log(self): duration = time.time() - self.start - remainder = duration / self.count * (self.total - self.count) - logger.info('Scanned %d of %d files in %ds, ~%ds left.', - self.count, self.total, duration, remainder) + if self.count >= self.total or not self.count: + logger.info('Scanned %d of %d files in %ds.', + self.count, self.total, duration) + else: + remainder = duration / self.count * (self.total - self.count) + logger.info('Scanned %d of %d files in %ds, ~%ds left.', + self.count, self.total, duration, remainder)