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.

37 lines
1.3 KiB

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