Data serializers#

These are not real serializers, these are interfaces between Django dump and load commands that perform serialization and deserialization.

class diskette.core.serializers.DumpdataSerializer(executable=None, logger=None)[source]#

Concrete basic implementation for StorageMixin.

Keyword Arguments:
  • executable (string) – A path to prefix commands, commonly the path to django-admin (or equivalent). This path will suffixed with a single space to ensure separation with command arguments.

  • logger (object) – Instance of a logger object to use. Logger object must implement common logging message methods (like error, info, etc..). See diskette.utils.loggers for available loggers. If not given, a dummy logger will be used that ignores any messages and won’t output anything.

class diskette.core.serializers.DumpdataSerializerAbstract[source]#

Dump data serializer is in charge to serialize applications with Django dumpdata command.

For now, this is JSON format only, ‘format’ option may be implemented later.

get_command_name(application)[source]#

Return effective command name to use.

Either the application defines a custom command or this will be the default one from DumpdataSerializerAbstract.COMMAND_NAME.

Parameters:

application (ApplicationConfig) – Application object.

Returns:

Command name.

Return type:

string

command(application, destination=None, indent=None)[source]#

Build a command line to use dumpdata.

Parameters:

application (ApplicationConfig) – Application object.

Keyword Arguments:
  • destination (Path) – The file path where to write dumped data.

  • indent (integer) – Indentation level in data dumps.

Returns:

Command line to dump application datas.

Return type:

string

call(application, destination=None, indent=None, traceback=False, check=False)[source]#

Programmatically use the Django dumpdata command to dump application.

Parameters:

application (ApplicationConfig) – Application object.

Keyword Arguments:
  • destination (Path) – The file path where to write dumped data.

  • indent (integer) – Indentation level in data dumps.

  • traceback (boolean) – If enabled, Django will output the full traceback when a dump raise an error. On default this is disabled and Django will silently hide exception tracebacks.

  • check (boolean) – Perform operations without writing or querying anything.

Returns:

A JSON payload of call results. On default, this is the JSON

output from dumpdata. However if destination has been given, dumpdata has written output to a file and so the returned JSON will just be a dictionnary with an item destination with written file path.

Return type:

string

class diskette.core.serializers.LoaddataSerializer(executable=None, logger=None)[source]#

Concrete basic implementation for LoaddataSerializerAbstract.

Keyword Arguments:
  • executable (string) – A path to prefix commands, commonly the path to django-admin (or equivalent). This path will suffixed with a single space to ensure separation with command arguments.

  • logger (object) – Instance of a logger object to use. Logger object must implement common logging message methods (like error, info, etc..). See diskette.utils.loggers for available loggers. If not given, a dummy logger will be used that ignores any messages and won’t output anything.

class diskette.core.serializers.LoaddataSerializerAbstract[source]#

Data loader serializer is in charge to load data fixtures in database with Django loaddata command.

For now, this is JSON format only, ‘format’ option may be implemented later.

command(dump, app=None, excludes=None, ignorenonexistent=False)[source]#

Build command line to use loaddata.

Parameters:

dump (Path) – Path to the dump file to load.

Keyword Arguments:
  • app (string) – Application name. If given, only data from this application will be loaded, the other ones will be ignored.

  • excludes (list) – A list of application or FQM labels to ignore from loaded data.

  • ignorenonexistent (boolean) – If enabled, fields and models that does not exists in current models will be ignored instead of raising an error.

Returns:

Command line to run a loaddata job.

Return type:

string

call(dump, app=None, excludes=None, ignorenonexistent=False)[source]#

Programmatically use the Django loaddata command to dump application.

Parameters:

dump (Path) – Path to the dump file to load.

Keyword Arguments:
  • app (string) – Application name. If given, only data from this application will be loaded, the other ones will be ignored.

  • excludes (list) – A list of application or FQM labels to ignore from loaded data.

  • ignorenonexistent (boolean) – If enabled, fields and models that does not exists in current models will be ignored instead of raising an error.

Returns:

Output from command.

Return type:

string