Skip to content
This repository has been archived by the owner on Sep 8, 2024. It is now read-only.

Docs/filesystem #2805

Merged
merged 2 commits into from
Jan 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def iad_add_directive_header(self, sig):
'serial',
'websocket',
'speech_recognition',
'xdg',
'yaml'
]

Expand Down
1 change: 1 addition & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
sphinx>= 2.2.1
sphinx_rtd_theme>=0.4.3
pyxdg
6 changes: 6 additions & 0 deletions doc/source/mycroft.filesystem.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
mycroft.filesystem
==================

.. autoclass:: mycroft.filesystem.FileSystemAccess
:members:

5 changes: 5 additions & 0 deletions doc/source/mycroft.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ removes_context decorator
-------------------------
.. autofunction:: mycroft.removes_context

mycroft.filesystem
==================

.. toctree::
mycroft.filesystem

mycroft.util
===============
Expand Down
30 changes: 21 additions & 9 deletions mycroft/filesystem/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@


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
Expand All @@ -37,19 +38,30 @@ def __init_path(path):
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))