ucsschool.importer.reader package#
Submodules#
ucsschool.importer.reader.base_reader module#
Base class of all input readers.
- class ucsschool.importer.reader.base_reader.BaseReader(filename: str, header_lines: int | None = 0, **kwargs: Any)[source]#
Bases:
objectBase class of all input readers.
Subclasses must override get_roles(), map() and read().
- Parameters:
- next() ImportUser#
Generates ImportUsers from input data.
- Returns:
ImportUser
- Return type:
- get_roles(input_data: Dict[str, Any]) Iterable[str][source]#
IMPLEMENT ME Detect the ucsschool.lib.roles from the input data.
- map(input_data: Dict[str, str], cur_user_roles: Iterable[str]) ImportUser[source]#
IMPLEMENT ME Creates a ImportUser object from a users dict (self.cur_entry). Data will not be modified, just copied.
- Parameters:
- Returns:
ImportUser
- Return type:
- read(*args: Any, **kwargs: Any) Iterator[Dict[str, str]][source]#
IMPLEMENT ME Generator that returns dicts of read users Sets self.entry_count and self.input_data on each read.
- get_data_mapping(input_data: Iterable[str]) Dict[str, Any][source]#
IMPLEMENT ME Create a mapping from the configured input mapping to the actual input data. This is configuration and input format specific. See csv_reader for an example. Used by ImportUser.format_from_scheme().
- get_imported_udm_property_names(import_user: ImportUser) List[str][source]#
IMPLEMENT ME Return all udm attributes which are directly set by the reader class. This is configuration and input format specific. See csv_reader for an example. This function is used to set which attributes should be loaded from ldap into udm_properties for users which will be deleted.
- Parameters:
import_user (ImportUser) – an ImportUser object
- Returns:
list of udm attibute names
- Return type:
ucsschool.importer.reader.csv_reader module#
CSV reader for CSV files using the new import format.
- exception ucsschool.importer.reader.csv_reader.UnsupportedEncodingError(message)[source]#
Bases:
Exception
- class ucsschool.importer.reader.csv_reader.CsvReader(filename: str, header_lines: int | None = 0, **kwargs: Any)[source]#
Bases:
BaseReaderReads CSV files and turns lines to ImportUser objects.
- Parameters:
- encoding = 'utf-8'#
- get_dialect(fp: BinaryIO, encoding: str) Type[Dialect][source]#
Overwrite me to force a certain CSV dialect.
- Parameters:
fp (file) – open file to read from
encoding – encoding in file
- Returns:
CSV dialect
- Return type:
- read(*args: Any, **kwargs: Any) Iterator[Dict[str, str]][source]#
Generate dicts from a CSV file.
- Parameters:
args – ignored
kwargs (dict) – if it has a dict csv_reader_args, that will be used as additional arguments for the
DictReaderconstructor.
- Returns:
iterator over list of dicts
- Return type:
Iterator
- handle_input(mapping_key: str, mapping_value: str, csv_value: str, import_user: ImportUser) bool[source]#
This is a hook into
map().IMPLEMENT ME if you wish to handle certain columns from the CSV file yourself.
- Parameters:
mapping_key (str) – the key in config[“csv”][“mapping”]
mapping_value (str) – the value in config[“csv”][“mapping”]
csv_value (str) – the associated value from the CSV line
import_user (ImportUser) – the object to modify
- Returns:
True if the field was handled here. It will be ignored in map(). False if map() should handle the field.
- Return type:
- get_roles(input_data: Dict[str, Any]) Iterable[str][source]#
Detect the ucsschool.lib.roles from the input data or configuration.
IMPLEMENT ME if the user role is not set in the configuration (file or by cmdline) or in the CSV mapped by __role.
__role can be something else, if configured in
_csv_roles_key.
- map(input_data: Dict[str, str], cur_user_roles: Iterable[str]) ImportUser[source]#
Creates a ImportUser object from a users dict. Data will not be modified, just copied.
- Parameters:
- Returns:
ImportUser instance
- Return type:
- get_data_mapping(input_data: Iterable[str]) Dict[str, Any][source]#
Create a mapping from the configured input mapping to the actual input data. Used by ImportUser.format_from_scheme().
- get_imported_udm_property_names(import_user: ImportUser) List[str][source]#
Return a list of udm attribute names for udm attribute values which are set through config[“csv”][“mapping”]
- Parameters:
import_user (ImportUser) – an ImportUser object
- Returns:
list of udm attibute names
- Return type:
ucsschool.importer.reader.http_api_csv_reader module#
CSV reader for CSV files created for HTTP-API import.
ucsschool.importer.reader.test_csv_reader module#
CSV reader for CSV files created by TestUserCsvExporter.