Package entropy :: Module dump

Module dump

source code


Author: Fabio Erculiani <[email protected]>

Contact: [email protected]

Copyright: Fabio Erculiani

License: GPL-2

Entropy Framework object disk serializer module.

This module contains Entropy Python object serialization functions and disk dumpers.

Serialized objects are stored to disk with proper permissions by default into path given by entropy.const's etpConst['dumpstoragedir'].

Permissions are set using entropy.const's const_setup_perms and const_setup_file functions.

Objects are serialized using Python's cPickle/pickle modules, thus they must be "pickable". Please read Python Library reference for more information.

Functions
None
dumpobj(name, my_object, complete_path=False, ignore_exceptions=True, dump_dir=None, custom_permissions=None)
Dump pickable object to file
source code
file object
serialize(myobj, ser_f, do_seek=True)
Serialize object to ser_f (file)
source code
any Python pickable object
unserialize(serial_f)
Unserialize file to object (file)
source code
any Python pickable object
unserialize_string(mystring)
Unserialize pickle string to object
source code
string
serialize_string(myobj)
Serialize object to string
source code
any Python pickable object or None
loadobj(name, complete_path=False, dump_dir=None, aging_days=None)
Load object from a file
source code
int
getobjmtime(name, dump_dir=None)
Get dumped object mtime
source code
bool
removeobj(name, dump_dir=None)
Remove cached object referenced by its object name
source code
Variables
  COMPAT_PICKLE_PROTOCOL = 0
  D_EXT = '.dmp'
  D_DIR = '/var/lib/entropy/caches'
  E_GID = 1000
  __package__ = 'entropy'
Function Details

dumpobj(name, my_object, complete_path=False, ignore_exceptions=True, dump_dir=None, custom_permissions=None)

source code 

Dump pickable object to file

Parameters:
  • name (string) - name of the object
  • my_object (any Python "pickable" object) - object to dump
  • complete_path (bool) - consider "name" argument as a complete path (this overrides the default dump path given by etpConst['dumpstoragedir'])
  • ignore_exceptions (bool) - ignore any possible exception (EOFError, IOError, OSError,)
  • dump_dir (string) - alternative dump directory
  • custom_permissions (octal) - give custom permission bits
Returns: None
None
Raises:
  • EOFError - could be caused by pickle.dump, ignored if ignore_exceptions is True
  • IOError - could be caused by pickle.dump, ignored if ignore_exceptions is True
  • OSError - could be caused by pickle.dump, ignored if ignore_exceptions is True

serialize(myobj, ser_f, do_seek=True)

source code 

Serialize object to ser_f (file)

Parameters:
  • myobj (any Python picklable object) - Python object to serialize
  • ser_f (file object) - file object to write to
  • do_seek (bool) - move file cursor back to the beginning of ser_f
Returns: file object
file object where data has been written
Raises:
  • RuntimeError - caused by pickle.dump in case of system errors
  • EOFError - caused by pickle.dump in case of race conditions on multi-processing or multi-threading
  • IOError - caused by pickle.dump in case of race conditions on multi-processing or multi-threading
  • pickle.PicklingError - when object cannot be recreated

unserialize(serial_f)

source code 

Unserialize file to object (file)

Parameters:
  • serial_f (file object) - file object which data will be read from
Returns: any Python pickable object
rebuilt object
Raises:
  • pickle.UnpicklingError - when object cannot be recreated

unserialize_string(mystring)

source code 

Unserialize pickle string to object

Parameters:
  • mystring (string) - data stream in string form to reconstruct
Returns: any Python pickable object
reconstructed object
Raises:
  • pickle.UnpicklingError - when object cannot be recreated

serialize_string(myobj)

source code 

Serialize object to string

Parameters:
  • myobj (any Python picklable object) - object to serialize
Returns: string
serialized string
Raises:
  • pickle.PicklingError - when object cannot be recreated

loadobj(name, complete_path=False, dump_dir=None, aging_days=None)

source code 

Load object from a file

Parameters:
  • name (string) - name of the object to load
  • complete_path (bool) - determine whether name argument is a complete disk path to serialized object
  • dump_dir (string) - alternative dump directory
  • aging_days (int) - if int, consider the cached file invalid if older than aging_days.
Returns: any Python pickable object or None
object or None

getobjmtime(name, dump_dir=None)

source code 

Get dumped object mtime

Parameters:
  • name (string) - object name
  • dump_dir (string) - alternative dump directory
Returns: int
mtime of the file containing the serialized object or 0 if not found

removeobj(name, dump_dir=None)

source code 

Remove cached object referenced by its object name

Parameters:
  • name (string) - object name
  • dump_dir (string) - alternative dump directory
Returns: bool
bool representing whether object has been removed or not
Raises:
  • OSError - in case of troubles with os.remove()