pryv.proxy
¶
This module defines proxy access functions to file storage. It enables manipulating files in the local file system and AWS S3 in a unified way.
-
pryv.proxy.
ensure_directory
(*paths)¶ Gets a file system proxy to the given root path and ensures it is a directory.
Parameters: paths ( str
) – The components of the root path.Returns: A file system proxy. Return type: FileSystemProxy
-
pryv.proxy.
get
(*paths)¶ Gets a proxy to the root path.
Parameters: paths ( str
) – The components of the root path.Returns: A file system proxy. Return type: FileSystemProxy
pryv.proxy.base
¶
This module defines the FileSystemProxy
and
FileProxy
classes. These are the base classes for the file proxies.
-
class
pryv.proxy.base.
FileProxy
¶ Bases:
object
This class defines a file proxy.
A file proxy enables to manipulate files located on the local system or on an AWS S3 bucket in the same manner.
-
__init__
()¶ Creates a new file proxy.
-
flush
()¶ Flushes the file proxy.
Warning
To override.
-
read
(size=0)¶ Reads data from the file proxy.
Warning
To override.
Parameters: size ( int
) – The number of bytes to read.Returns: Data read.
-
readline
()¶ Reads a line of data from the file proxy.
Warning
To override.
Returns: Data read.
-
write
(data)¶ Writes data to the file proxy.
Warning
To override.
Parameters: data – The data to write.
-
-
class
pryv.proxy.base.
FileSystemProxy
¶ Bases:
object
This class defines a file system proxy.
A file system proxy enables interacting files located on different storage in an unified manner.
-
__init__
()¶ Creates a new abstract file system proxy.
-
exists
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path exists or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a file that exist;False
otherwise.Return type: bool
-
is_directory
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path is a directory or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a directory;False
otherwise.Return type: bool
-
is_file
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path is a file or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a file;False
otherwise.Return type: bool
-
list_directories
(*paths, **kwargs)¶ Lists the directories located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path.
- exclude (
list
) – A list of directory names to exclude.
Type: path:
str
Returns: A list of directory names.
Return type: list
-
list_files
(*paths, **kwargs)¶ Lists the files located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path to the file.
- exclude (
list
) – A list of file names to exclude.
Type: path:
str
Returns: A list of file names.
Return type: list
-
make_directory
(*paths, **kwargs)¶ Creates a directory at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path. Type: path: str
-
open_file
(*paths, **kwargs)¶ Opens the file located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path to the file.
- mode (
str
) – The opening mode (r
orw
).
Type: path:
str
Returns: A file instance.
Return type:
-
remove_file
(*paths, **kwargs)¶ Removes the file located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
-
-
pryv.proxy.base.
join_path
(*paths)¶ Joins the given path components into a single path.
Parameters: paths ( str
) – The path components.Returns: A path. Return type: str
-
pryv.proxy.base.
with_path
(func)¶ Decorates the given function as requiring a path. It converts the given path components into a single path.
Parameters: func ( function
) – The function to decorate.Returns: A decorated function. Return type: function
pryv.proxy.local
¶
This module defines the LocalFileSystemProxy
and
LocalFileProxy
classes that enable manipulating files on the local file
system.
-
class
pryv.proxy.local.
LocalFileProxy
(path, mode)¶ Bases:
pryv.proxy.base.FileProxy
This class defines a proxy to a file located on the local file system.
-
__init__
(path, mode)¶ Creates a new instance of a local file proxy.
Parameters: - path (
str
) – The path to the file. - mode (
str
) – The opening mode of the file.
- path (
-
flush
()¶ Flushes the file proxy.
Warning
To override.
-
read
(size=None)¶ Reads data from the file proxy.
Warning
To override.
Parameters: size ( int
) – The number of bytes to read.Returns: Data read.
-
readline
()¶ Reads a line of data from the file proxy.
Warning
To override.
Returns: Data read.
-
write
(data)¶ Writes data to the file proxy.
Warning
To override.
Parameters: data – The data to write.
-
-
class
pryv.proxy.local.
LocalFileSystemProxy
(path)¶ Bases:
pryv.proxy.base.FileSystemProxy
This class defines a proxy to the local file system.
-
__init__
(path)¶ Creates a new instance of a proxy to the local file system. :param path:
-
exists
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path exists or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a file that exist;False
otherwise.Return type: bool
-
is_directory
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path is a directory or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a directory;False
otherwise.Return type: bool
-
is_file
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path is a file or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a file;False
otherwise.Return type: bool
-
list_directories
(*paths, **kwargs)¶ Lists the directories located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path.
- exclude (
list
) – A list of directory names to exclude.
Type: path:
str
Returns: A list of directory names.
Return type: list
-
list_files
(*paths, **kwargs)¶ Lists the files located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path to the file.
- exclude (
list
) – A list of file names to exclude.
Type: path:
str
Returns: A list of file names.
Return type: list
-
make_directory
(*paths, **kwargs)¶ Creates a directory at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path. Type: path: str
-
open_file
(*paths, **kwargs)¶ Opens the file located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path to the file.
- mode (
str
) – The opening mode (r
orw
).
Type: path:
str
Returns: A file instance.
Return type:
-
remove_file
(*paths, **kwargs)¶ Removes the file located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
-
-
pryv.proxy.local.
with_full_path
(func)¶ Decorates the given function as requiring a full path. This decorator merges the root path of decorated file system instance and the given path (either as a single parameter or as a list of path components).
Parameters: func ( function
) – The function to decorate.Returns: A decorated function. Return type: function
pryv.proxy.s3
¶
This module defines the S3FileSystemProxy
and
S3FileProxy
classes that enable manipulating files located on an AWS S3
bucket.
-
class
pryv.proxy.s3.
S3FileSystemProxy
(bucket, prefix)¶ Bases:
pryv.proxy.base.FileSystemProxy
This class defines a proxy to a file system located on an AWS S3 bucket.
-
__init__
(bucket, prefix)¶ Creates a new instance of a proxy to an AWS S3 bucket.
Parameters: - bucket (
str
) – The name of the bucket. - prefix (
str
) – The key prefix to the objects.
- bucket (
-
exists
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path exists or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a file that exist;False
otherwise.Return type: bool
-
is_directory
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path is a directory or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a directory;False
otherwise.Return type: bool
-
is_file
(*paths, **kwargs)¶ Gets a value indicating whether the file at the given path is a file or not.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
Returns: True
if the path targets a file;False
otherwise.Return type: bool
-
list_directories
(*paths, **kwargs)¶ Lists the directories located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path.
- exclude (
list
) – A list of directory names to exclude.
Type: path:
str
Returns: A list of directory names.
Return type: list
-
list_files
(*paths, **kwargs)¶ Lists the files located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path to the file.
- exclude (
list
) – A list of file names to exclude.
Type: path:
str
Returns: A list of file names.
Return type: list
-
make_directory
(*paths, **kwargs)¶ Creates a directory at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path. Type: path: str
-
open_file
(*paths, **kwargs)¶ Opens the file located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: - path – The path to the file.
- mode (
str
) – The opening mode (r
orw
).
Type: path:
str
Returns: A file instance.
Return type:
-
remove_file
(*paths, **kwargs)¶ Removes the file located at the given path.
Note
The path can be given either as a single parameter or by components.
Parameters: path – The path to the file. Type: path: str
-