ucsschool.importer.writer package

Submodules

ucsschool.importer.writer.base_writer module

Base class for output writers.

class ucsschool.importer.writer.base_writer.BaseWriter(*arg, **kwargs)[source]

Bases: object

Abstraction of a data dump mechanism like CSV, JSON, XML, sockets etc.

Create a writer.

Parameters:
  • arg (tuple) – arguments for implementing class
  • kwargs (dict) – arguments for implementing class
open(filename, mode='wb')[source]

Get a handle on the output file or something similar to be used as a context manager. IMPLEMENTME with the method appropriate for the output type.

Parameters:
  • filename (str) – filename to write data to
  • mode (str) – passed to used open() method
Returns:

a context manager

write_header(header)[source]

Write an optional header (line) before the main data. IMPLEMENTME if you wish to write a header line.

Parameters:header – object to write as header
Returns:None

Write a optional footer (line) after the main data. IMPLEMENTME if you wish to write a footer.

Parameters:footer – object to write as footer
Returns:None
write_obj(obj)[source]

Write object to output. IMPLEMENTME if it’s not just outfile.write(obj).

Parameters:obj – object or error to write
Returns:result of write operation, if any

ucsschool.importer.writer.csv_writer module

Write the result of a user import job to a CSV file.

class ucsschool.importer.writer.csv_writer.CsvWriter(field_names, dialect=None)[source]

Bases: ucsschool.importer.writer.base_writer.BaseWriter

Create a CSV file writer.

Parameters:
  • field_names (list(str)) – names of the columns
  • dialect (csv.Dialect) – If unset will try to detect dialect of input file or fall back to “excel”.
open(filename, mode='wb')[source]

Open the output file.

Parameters:
  • filename (str) – filename to write data to
  • mode (str) – passed to builtin open() method
Returns:

DictWriter instance

Return type:

csv.DictWriter

write_header(header)[source]

Write a header line before the main data.

Parameters:header – object to write as header (ignored)
Returns:None
write_obj(obj)[source]

Write object to output.

Parameters:obj (dict) – data to write
Returns:None

ucsschool.importer.writer.new_user_password_csv_exporter module

Write the passwords of newly created users to a CSV file.

class ucsschool.importer.writer.new_user_password_csv_exporter.NewUserPasswordCsvExporter(*arg, **kwargs)[source]

Bases: ucsschool.importer.writer.result_exporter.ResultExporter

Export passwords of new users to a CSV file.

field_names = ('username', 'password', 'role', 'lastname', 'firstname', 'schools', 'classes')
get_iter(user_import)[source]

Return only the new users.

get_writer()[source]

Use the user result csv writer.

serialize(user)[source]

ucsschool.importer.writer.result_exporter module

Base class for result exporters.

class ucsschool.importer.writer.result_exporter.ResultExporter(*arg, **kwargs)[source]

Bases: object

Write a CSV/JSON/XML file representing the result of an import job. Create one writer per object type.

Clients of this class should only call dump().

Subclasses implement get_iter() to create a stream of objects to serialize and run serialize() on each of them.

Create a CSV file writer.

Parameters:
  • arg (list) – arguments for implementing class
  • kwargs (dict) – arguments for implementing class
dump(import_handler, filename)[source]

Create file about added/modified/deleted objects and errors.

Parameters:
  • import_handler (UserImport) – object that contains data to dump from an import job (for example UserImport)
  • filename (str) – filename to write data to

Data for an optional footer (line) after the main data. IMPLEMENTME if you wish to write a footer.

Returns:object that can be used by the writer to create a footer
get_header()[source]

Data for an optional header (line) before the main data. IMPLEMENTME if you wish to write a header line.

Returns:object that can be used by the writer to create a header
get_iter(import_handler)[source]

Iterator over all created objects and errors of an import job. IMPLEMENTME to change the order of objects and errors in the generated output.

Parameters:import_handler – object that contains data to dump from an import job
Returns:iterator for both import objects and UcsSchoolImportError objects
Return type:Iterator
get_writer()[source]

Object that will write the data to disk/network in the desired format. IMPLEMENTME

Returns:an object of a BaseWriter subclass
Return type:BaseWriter
serialize(obj)[source]

Make a dict of attr_name->strings from an import object. IMPLEMENTME to dump a single object (user/computer/error) delivered by the iterator from get_iter().

Parameters:obj – object to serialize
Returns:attr_name->strings that will be used to write the output file
Return type:dict

ucsschool.importer.writer.test_user_csv_exporter module

Class to export test user data from TestUserCreator to CSV.

class ucsschool.importer.writer.test_user_csv_exporter.TestUserCsvExporter(*arg, **kwargs)[source]

Bases: ucsschool.importer.writer.result_exporter.ResultExporter

Create a CSV file writer.

Parameters:
  • arg (list) – arguments for implementing class
  • kwargs (dict) – arguments for implementing class
field_names = ('Schulen', 'Benutzertyp', 'Vorname', 'Nachname', 'Klassen', 'Beschreibung', 'Telefon', 'EMail')
get_iter(user_import)[source]
get_writer()[source]
serialize(user)[source]
class ucsschool.importer.writer.test_user_csv_exporter.HttpApiTestUserCsvExporter(*arg, **kwargs)[source]

Bases: ucsschool.importer.writer.test_user_csv_exporter.TestUserCsvExporter

Create a CSV file writer.

Parameters:
  • arg (list) – arguments for implementing class
  • kwargs (dict) – arguments for implementing class
field_names = ('Schule', 'Vorname', 'Nachname', 'Klassen', 'Beschreibung', 'Telefon', 'EMail')
serialize(user)[source]

ucsschool.importer.writer.user_import_csv_result_exporter module

Write the result of a user import job to a CSV file.

class ucsschool.importer.writer.user_import_csv_result_exporter.UserImportCsvResultExporter(*arg, **kwargs)[source]

Bases: ucsschool.importer.writer.result_exporter.ResultExporter

Export the results of the user import to a CSV file.

Parameters:
  • arg (tuple) – ignored
  • kwargs (dict) – ignored
field_names = ('line', 'success', 'error', 'action', 'role', 'username', 'schools', 'firstname', 'lastname', 'birthday', 'email', 'disabled', 'classes', 'source_uid', 'record_uid', 'error_msg')
get_iter(user_import)[source]

Iterator over all ImportUsers and errors of the user import. First errors, then added, modified and deleted users.

Parameters:user_import (UserImport) – UserImport object used for the import
Returns:iterator over both ImportUsers and UcsSchoolImportError objects
Return type:Iterator(ImportUsers or UcsSchoolImportError)
get_writer()[source]

Object that will write the data to disk/network in the desired format.

Returns:an object that knows how to write data
serialize(obj)[source]

Make a dict of attr_name->strings from an import object.

Parameters:obj – object to serialize
Returns:mapping attr_name->strings that will be used to write the output file
Return type:dict