PersistentData

PersistentData is a class that allows to save and store data across perceval launches. Most importantly, it is used to save RemoteConfig, JobGroup

Warning

The folder created by PersistentData is never emptied automatically. This means that using features that make use of PersistentData may use a lot of disk after many uses.

Usage example:

>>> import perceval as pcvl
>>> pdata = pcvl.PersistentData()
>>> pdata.write_file("my_file.txt", "my_data", pcvl.FileFormat.TEXT)
>>> print(pdata.read_file("my_file.txt", pcvl.FileFormat.TEXT))
my_data
>>> pdata.delete_file("my_file.txt")

Note

The default folder is created inside the user folder, so the persistent data are not shared between users.

class perceval.utils.persistent_data.PersistentData(directory=None)

PersistentData is a class that stores data on the drive to save data between launches of perceval. On init, it creates a directory (if it doesn’t exist) for storing perceval persistent data Default directory depends on the os:

  • Linux: ‘/home/my_user/.local/share/perceval-quandela’

  • Windows: ‘C:\Users\my_user\AppData\Local\quandela\perceval-quandela’

  • Darwin: ‘/Users/my_user/Library/Application Support/perceval-quandela’

If the directory cannot be created or read/write in, a warning will inform the user

clear_all_data()

Delete all persistent data except for log

create_sub_directory(relative_path)

Creates a sub folder in persistent data directory if non-existent

Parameters:

relative_path (str) – the folders path to create relative to self.directory

Return type:

str

Returns:

full absolute path

delete_file(filename)

Delete a file in persistent data directory if file doesn’t exist, raise a user warning

Parameters:

filename (str) – name of the file to delete (with extension)

property directory: str

return persistent data directory

Returns:

persistent data directory

get_folder_size()

Get the directory data size

Return type:

int

Returns:

directory data size in bytes

get_full_path(element_name)

Get the full path of an element supposedly in persistent data directory

Parameters:

element_name (str) – name of the element (with extension)

Return type:

str

Returns:

full path of the file

has_file(filename)

Find if persistent data has file

Parameters:

filename (str) – name of the file to find (with extension)

Return type:

bool

Returns:

True is the file exists, else False

is_readable()

Return if the directory is readable

Return type:

bool

Returns:

True if the directory is readable, False else

is_writable()

Return if the directory is writable

Return type:

bool

Returns:

True if the directory is writable, False else

load_config()

Load perceval config from persistent data

Return type:

dict

Returns:

config

read_file(filename, file_format)

Read data from a file in persistent data directory

Parameters:

filename (str) – name of the file to read (with extension)

Raises:

FileNotFoundError – Raise an exception if file is not found

Return type:

bytes | str

Returns:

data

save_config(config)

Save config into persistent data, update any config previously saved

Parameters:

config (dict) – config to save

write_file(filename, data, file_format)

Write data into a file in persistent data directory

Parameters:
  • filename (str) – name of the file to write in (with extension)

  • data (bytes | str) – data to write

enum perceval.utils._enums.FileFormat(value)

An enumeration.

Valid values are as follows:

BINARY = <FileFormat.BINARY: 0>
TEXT = <FileFormat.TEXT: 1>