Merge pull request #2805 from forslund/docs/filesystem

Docs/filesystem
pull/2814/head
Kris Gesling 2021-01-19 14:49:42 +09:30 committed by GitHub
commit 5e6ba03695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 10 deletions

View File

@ -66,7 +66,6 @@ autodoc_mock_imports = list(autodoc_mock_imports) + [
'serial',
'websocket',
'speech_recognition',
'xdg',
'yaml'
]

View File

@ -1,2 +1,3 @@
sphinx>= 2.2.1
sphinx_rtd_theme>=0.4.3
pyxdg

View File

@ -0,0 +1,6 @@
mycroft.filesystem
==================
.. autoclass:: mycroft.filesystem.FileSystemAccess
:members:

View File

@ -56,6 +56,11 @@ removes_context decorator
-------------------------
.. autofunction:: mycroft.removes_context
mycroft.filesystem
==================
.. toctree::
mycroft.filesystem
mycroft.util
===============

View File

@ -17,13 +17,14 @@ from os.path import join, expanduser, isdir
class FileSystemAccess:
"""
A class for providing access to the mycroft FS sandbox. Intended to be
attached to skills at initialization time to provide a skill-specific
namespace.
"""A class for providing access to the mycroft FS sandbox.
Intended to be attached to skills at initialization time to provide a
skill-specific namespace.
"""
def __init__(self, path):
#: Member value containing the root path of the namespace
self.path = self.__init_path(path)
@staticmethod
@ -37,19 +38,30 @@ class FileSystemAccess:
return path
def open(self, filename, mode):
"""
"""Open a file in the provided namespace.
Get a handle to a file (with the provided mode) within the
skill-specific namespace.
:param filename: a str representing a path relative to the namespace.
subdirs not currently supported.
Parameters:
filename (str): a path relative to the namespace.
subdirs not currently supported.
:param mode: a file handle mode
mode (str): a file handle mode
:return: an open file handle.
Returns:
an open file handle.
"""
file_path = join(self.path, filename)
return open(file_path, mode)
def exists(self, filename):
"""Check if file exists in the namespace.
Arguments:
filename (str): a path relative to the namespace.
subdirs not currently supported.
Returns:
bool: True if file exists, else False.
"""
return os.path.exists(join(self.path, filename))