File: Add feature to file module for sorting files vs directories.
Add configuration option in [file] section of mopidy.conf Add documentation for feature with the valid options. Signed-off-by: caysho@internode.on.net
This commit is contained in:
parent
2b7f12b854
commit
84992bf80e
@ -51,3 +51,16 @@ See :ref:`config` for general help on configuring Mopidy.
|
||||
Number of milliseconds before giving up scanning a file and moving on to
|
||||
the next file. Reducing the value might speed up the directory listing,
|
||||
but can lead to some tracks not being shown.
|
||||
|
||||
.. confval:: file/sort_order
|
||||
|
||||
Sort the files and directories in the given order.
|
||||
Options are:
|
||||
|
||||
``DirectoriesFirst``
|
||||
|
||||
``FilesFirst``
|
||||
|
||||
``Mixed``
|
||||
|
||||
Default is ``DirectoriesFirst``
|
||||
|
||||
@ -26,6 +26,7 @@ class Extension(ext.Extension):
|
||||
schema['show_dotfiles'] = config.Boolean(optional=True)
|
||||
schema['follow_symlinks'] = config.Boolean(optional=True)
|
||||
schema['metadata_timeout'] = config.Integer(optional=True)
|
||||
schema['sort_order'] = config.String(optional=True)
|
||||
return schema
|
||||
|
||||
def setup(self, registry):
|
||||
|
||||
@ -9,3 +9,4 @@ excluded_file_extensions =
|
||||
.jpeg
|
||||
follow_symlinks = false
|
||||
metadata_timeout = 1000
|
||||
sort_order = DirectoriesFirst
|
||||
|
||||
@ -43,9 +43,19 @@ class FileLibraryProvider(backend.LibraryProvider):
|
||||
self._scanner = scan.Scanner(
|
||||
timeout=config['file']['metadata_timeout'])
|
||||
|
||||
self._sort_order = config['file']['sort_order']
|
||||
logger.info('File browing sort order is: %s', self._sort_order)
|
||||
|
||||
self._sort_files_first = (self._sort_order == 'FilesFirst')
|
||||
self._sort_directories_first = (self._sort_order ==
|
||||
'DirectoriesFirst')
|
||||
self._sort_mixed = (self._sort_order == 'Mixed')
|
||||
|
||||
def browse(self, uri):
|
||||
logger.debug('Browsing files at: %s', uri)
|
||||
result = []
|
||||
result_directories = []
|
||||
result_files = []
|
||||
local_path = path.uri_to_path(uri)
|
||||
|
||||
if local_path == 'root':
|
||||
@ -78,11 +88,24 @@ class FileLibraryProvider(backend.LibraryProvider):
|
||||
|
||||
name = dir_entry.decode(FS_ENCODING, 'replace')
|
||||
if os.path.isdir(child_path):
|
||||
result.append(models.Ref.directory(name=name, uri=uri))
|
||||
result_directories.append(models.Ref.directory(name=name,
|
||||
uri=uri))
|
||||
elif os.path.isfile(child_path):
|
||||
result.append(models.Ref.track(name=name, uri=uri))
|
||||
result_files.append(models.Ref.track(name=name, uri=uri))
|
||||
|
||||
if not self._sort_mixed:
|
||||
result_directories.sort(key=operator.attrgetter('name'))
|
||||
result_files.sort(key=operator.attrgetter('name'))
|
||||
|
||||
if self._sort_mixed or self._sort_directories_first:
|
||||
result = result_directories + result_files
|
||||
|
||||
if self._sort_files_first:
|
||||
result = result_files + result_directories
|
||||
|
||||
if self._sort_mixed:
|
||||
result.sort(key=operator.attrgetter('name'))
|
||||
|
||||
result.sort(key=operator.attrgetter('name'))
|
||||
return result
|
||||
|
||||
def lookup(self, uri):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user