FileChooser compatibility with PyFilesystem2
Is your feature request related to a problem? Please describe. The FileChooser is only compatible to the native filesystem (os.path). I would like to have a FileChooser that supports other filesystems aswell (f.ex. pyfilesystem / pyfilesystem2 / ipfs / ...)
Describe the solution you'd like
If we would move some of the native-dependant functions from the kivy.uix.filechooser.FileChooser to the kivy.uix.filechooser.FileSystemAbstract and implement the current solution in the kivy.uix.filechooser.FileSystemLocal class.
That way, we could keep backwards compatibility for users of the FileSystemLocal (which is default), but would increase Effort for the users of the abstract interface / custom implementations.
Describe alternatives you've considered
- ~Implement PyFilesystem2 directly and remove the current filesystem dependencies~
- ~Reimplement FileChooser~
Additional context Renaming suggestions / better solutions welcome! The Solution could look like the following:
class FileSystemAbstract(object):
'''Class for implementing a File System view that can be used with the
:class:``FileChooser <FileChooser>``.
.. versionadded:: 1.8.0
'''
def listdir(self, fn):
'''Return the list of files in the directory `fn`
'''
pass
def getsize(self, fn):
'''Return the size in bytes of a file
'''
pass
def is_hidden(self, fn):
'''Return True if the file is hidden
'''
pass
def is_dir(self, fn):
'''Return True if the argument passed to this method is a directory
'''
pass
def is_root(self, fpath):
'''Return True if the argument (path) passed is the root dir
'''
pass
def normpath(self, fn):
'''Return similar compared to `os.path.normpath`
'''
pass
def realpath(self, fn):
'''Return similar compared to `os.path.realpath`
'''
pass
def basename(self, fn):
'''Return similar compared to `os.path.basename`
'''
pass
def expanduser(self, fn):
'''Return similar compared to `os.path.expanduser`
'''
pass
def dirname(self, fn):
'''Return similar compared to `os.path.dirname`
'''
pass
def isfile(self, fn):
'''Return similar compared to `os.path.isfile`
'''
pass
def join(self, *paths):
'''Return similar compared to `os.path.join`
'''
pass
class FileSystemLocal(FileSystemAbstract):
'''Implementation of :class:`FileSystemAbstract` for local files.
.. versionadded:: 1.8.0
'''
def listdir(self, fn):
return listdir(fn)
def getsize(self, fn):
return getsize(fn)
def is_hidden(self, fn):
if platform == 'win':
if not _have_win32file:
return False
try:
return GetFileAttributesExW(fn)[0] & FILE_ATTRIBUTE_HIDDEN
except error:
# This error can occurred when a file is already accessed by
# someone else. So don't return to True, because we have lot
# of chances to not being able to do anything with it.
Logger.exception('unable to access to <%s>' % fn)
return True
return basename(fn).startswith('.')
def is_dir(self, fn):
return isdir(fn)
def is_root(self, fpath):
if platform == 'win':
return splitdrive(path)[1] in (sep, altsep)
elif platform in ('macosx', 'linux', 'android', 'ios'):
return normpath(expanduser(path)) == sep
else:
# Unknown fs, just always add the .. entry but also log
Logger.warning('Filechooser: Unsupported OS: %r' % platform)
return False
def normpath(self, fn):
return os.path.normpath(fn)
def realpath(self, fn):
return os.path.realpath(fn)
def basename(self, fn):
return os.path.basename(fn)
def expanduser(self, fn):
return os.path.expanduser(fn)
def dirname(self, fn):
return os.path.dirname(fn)
def isfile(self, fn):
return os.path.isfile(fn)
def join(self, *paths):
return os.path.join(*paths)