rpi_video_looper/Adafruit_Video_Looper/directory.py

43 lines
1.4 KiB
Python
Raw Normal View History

2015-02-11 01:34:46 +00:00
# Copyright 2015 Adafruit Industries.
# Author: Tony DiCola
# License: GNU GPLv2, see LICENSE.txt
2015-06-08 13:27:55 +00:00
import os.path
2015-02-11 01:34:46 +00:00
class DirectoryReader(object):
def __init__(self, config):
"""Create an instance of a file reader that just reads a single
directory on disk.
"""
self._load_config(config)
2015-06-08 13:27:55 +00:00
self._mtime = 0
2015-02-11 01:34:46 +00:00
def _load_config(self, config):
self._path = config.get('directory', 'path')
def search_paths(self):
"""Return a list of paths to search for files."""
return [self._path]
def is_changed(self):
"""Return true if the file search paths have changed."""
# For now just return false and assume the path never changes. In the
# future it might be interesting to watch for file changes and return
# true if new files are added/removed from the directory. This is
# called in a tight loop of the main program so it needs to be fast and
# not resource intensive.
2015-06-08 13:27:55 +00:00
mtime = os.path.getmtime(self._path)
changed = mtime and mtime > self._mtime
self._mtime = mtime
return changed
2015-02-11 01:34:46 +00:00
def idle_message(self):
"""Return a message to display when idle and no files are found."""
return 'No files found in {0}'.format(self._path)
def create_file_reader(config):
"""Create new file reader based on reading a directory on disk."""
return DirectoryReader(config)