Don't delete the image that we're currently running, for safety.

This commit is contained in:
Ian Gulliver
2016-05-11 05:12:43 +00:00
parent 8b08a5cec6
commit c302ffd87a
4 changed files with 14 additions and 5 deletions

View File

@@ -166,9 +166,10 @@ class Fetcher(object):
self._FetchImage(image)
self._SetCurrent(image)
def DeleteOldImages(self, max_images=5):
def DeleteOldImages(self, max_images=5, skip=None):
if not max_images:
return
skip = skip or set()
images = []
for filename in os.listdir(self._image_dir):
match = self._FILE_REGEX.match(filename)
@@ -177,6 +178,8 @@ class Fetcher(object):
images.append((int(match.group('timestamp')), filename))
images.sort(reverse=True)
for timestamp, filename in images[max_images:]:
if filename in skip:
continue
print('Deleting old image:', filename, flush=True)
path = os.path.join(self._image_dir, filename)
os.unlink(path)