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.ensure_file(*paths, **kwargs)¶ Gets a file system proxy to the given root path and ensures it is a file.
Parameters: - paths (
str) – The components of the root path. - content (
strorNone) – The content of the file (if the file didn’t exist).
Returns: A file system proxy.
Return type: - paths (
-
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: FileSystemProxyorNone
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:
objectThis 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.
-
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:
objectThis 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: strReturns: Trueif the path targets a file that exist;Falseotherwise.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: strReturns: Trueif the path targets a directory;Falseotherwise.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: strReturns: Trueif the path targets a file;Falseotherwise.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:
strReturns: 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:
strReturns: 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 (rorw).
Type: path:
strReturns: 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.FileProxyThis 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 (
-
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.FileSystemProxyThis 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: strReturns: Trueif the path targets a file that exist;Falseotherwise.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: strReturns: Trueif the path targets a directory;Falseotherwise.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: strReturns: Trueif the path targets a file;Falseotherwise.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:
strReturns: 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:
strReturns: 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 (rorw).
Type: path:
strReturns: 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.S3FileProxy(client, bucket, key)¶ Bases:
pryv.proxy.base.FileProxyThis class defines a proxy to a file located in an AWS S3 Bucket.
-
__init__(client, bucket, key)¶ Creates a new proxy to an object with the given key located in the AWS S3 Bucket with the given name.
Parameters: - client (
botocore.client.BaseClient) – The AWS S3 client. - bucket (
str) – The name of the AWS S3 Bucket. - key (
str) – The key of the AWS S3 Object.
- client (
-
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.s3.S3FileSystemProxy(bucket, prefix)¶ Bases:
pryv.proxy.base.FileSystemProxyThis 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: strReturns: Trueif the path targets a file that exist;Falseotherwise.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: strReturns: Trueif the path targets a directory;Falseotherwise.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: strReturns: Trueif the path targets a file;Falseotherwise.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:
strReturns: 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:
strReturns: 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 (rorw).
Type: path:
strReturns: 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.s3.with_key(func)¶ Decorates the given function as requiring an AWS S3 Object’s key. This decorator merges the prefix of the decorated file system instance and the given path.
Parameters: func ( function) – The function to decorate.Returns: A decorated function. Return type: function