No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

usb_drive.py 1.5 KiB

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