Watson - Filesystem¶
Manage multiple filesystems through a convenient API.
Build Status¶
Installation¶
pip install watson-filesystem
Testing¶
Watson can be tested with py.test. Simply activate your virtualenv and run python setup.py test
.
Contributing¶
If you would like to contribute to Watson, please feel free to issue a pull request via Github with the associated tests for your code. Your name will be added to the AUTHORS file under contributors.
Table of Contents¶
Usage¶
Using the filesystem module is easily initialized by the following:
from watson.filesystem import Filesystem, backends
fs = Filesystem(backends.Local())
print(fs.read('path/to/file')) # contents of file
In order to maintain a simplistic API, all the backends can be imported from watson.filesystem.backends.NAME_OF_BACKEND.
For more information regarding the various API methods avaiable, please see the reference library.
Reference Library¶
watson.filesystem.api¶
-
class
watson.filesystem.api.
Filesystem
(backend)[source]¶ The abstracted api that the user will interface with when dealing with different types of filesystems.
Example:
from watson import filesystem fs = filesystem.Filesystem(filesystem.backends.Local()) content = fs.read('/path/to/file') print(content)
-
append
(file, content, options=None)[source]¶ Appends specific content to a file.
Similar function to write(), except that any content will be appended to the end of the file.
Parameters: - file (string) – The file to write to
- content (mixed) – The content to write to the file.
- options (dict) – A dict of args that will be passed to open()
-
copy
(path, new_path)[source]¶ Copies a file/directory to a new location.
Parameters: - path (string) – The path to copy to
- new_path (string) – The new location for the file/directory
-
create
(path, is_dir=False)[source]¶ Creates a new file/directory.
If any parent directories in the path do not exist they will be created.
Parameters: - path (string) – The path to create
- is_dir (boolean) – Whether or not to create the path as a directory
-
delete
(path)[source]¶ Deletes a path from the filesystem.
If a directory is specified, its contents will also be removed.
Parameters: path (string) – The path to delete
-
exists
(path)[source]¶ Verifies if a path exists.
Parameters: path (string) – The path to verify Returns: Boolean based on whether or not it exists.
-
move
(path, new_path)[source]¶ Moves a file/directory to a new location.
Parameters: - path (string) – The path to move to
- new_path (string) – The new location for the file/directory
-
read
(file, options=None)[source]¶ Reads a file (and then closes it).
Parameters: - file (string) – The file to read
- options (dict) – A dict of args that will be passed to open()
-
write
(file, content, options=None)[source]¶ Writes some specific content to a file.
Performing this call will overwrite any content that exists within the file. If the file does not exist (or the path), it will be created.
Parameters: - file (string) – The file to write to
- content (mixed) – The content to write to the file.
- options (dict) – A dict of args that will be passed to open()
-