You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

directory.py 1.2 KiB

9 years ago
9 years ago
1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright 2015 Adafruit Industries.
  2. # Author: Tony DiCola
  3. # License: GNU GPLv2, see LICENSE.txt
  4. class DirectoryReader:
  5. def __init__(self, config):
  6. """Create an instance of a file reader that just reads a single
  7. directory on disk.
  8. """
  9. self._load_config(config)
  10. def _load_config(self, config):
  11. self._path = config.get('directory', 'path')
  12. def search_paths(self):
  13. """Return a list of paths to search for files."""
  14. return [self._path]
  15. def is_changed(self):
  16. """Return true if the file search paths have changed."""
  17. # For now just return false and assume the path never changes. In the
  18. # future it might be interesting to watch for file changes and return
  19. # true if new files are added/removed from the directory. This is
  20. # called in a tight loop of the main program so it needs to be fast and
  21. # not resource intensive.
  22. return False
  23. def idle_message(self):
  24. """Return a message to display when idle and no files are found."""
  25. return 'No files found in {0}'.format(self._path)
  26. def create_file_reader(config):
  27. """Create new file reader based on reading a directory on disk."""
  28. return DirectoryReader(config)