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.

48 lines
1.5 KiB

  1. #!/usr/bin/env python
  2. # Copyright 2015 Adafruit Industries.
  3. # Author: Tony DiCola
  4. # License: GNU GPLv2, see LICENSE.txt
  5. import glob
  6. from usb_drive_mounter import USBDriveMounter
  7. class USBDriveReader(object):
  8. def __init__(self, config):
  9. """Create an instance of a file reader that uses the USB drive mounter
  10. service to keep track of attached USB drives and automatically mount
  11. them for reading videos.
  12. """
  13. self._load_config(config)
  14. self._mounter = USBDriveMounter(root=self._mount_path,
  15. readonly=self._readonly)
  16. self._mounter.start_monitor()
  17. def _load_config(self, config):
  18. self._mount_path = config.get('usb_drive', 'mount_path')
  19. self._readonly = config.getboolean('usb_drive', 'readonly')
  20. def search_paths(self):
  21. """Return a list of paths to search for files. Will return a list of all
  22. mounted USB drives.
  23. """
  24. self._mounter.mount_all()
  25. return glob.glob(self._mount_path + '*')
  26. def is_changed(self):
  27. """Return true if the file search paths have changed, like when a new
  28. USB drive is inserted.
  29. """
  30. return self._mounter.poll_changes()
  31. def idle_message(self):
  32. """Return a message to display when idle and no files are found."""
  33. return 'Insert USB drive with compatible movies.'
  34. def create_file_reader(config):
  35. """Create new file reader based on mounting USB drives."""
  36. return USBDriveReader(config)