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: -
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: 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
-
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: Returns: DictWriter instance
Return type:
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')¶
-
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: -
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: -
field_names
= ('Schulen', 'Benutzertyp', 'Vorname', 'Nachname', 'Klassen', 'Beschreibung', 'Telefon', 'EMail')¶
-
-
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: -
field_names
= ('Schule', 'Vorname', 'Nachname', 'Klassen', 'Beschreibung', 'Telefon', 'EMail')¶
-
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: -
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)
-