def slurp_role(element_name, attributes): """Look at a specific <role>-element""" if element_name != "rolle": return # what *kind* of role is this? role_kind = attributes[role_parser.target_key] if len(role_kind) != 1: # A warning about this has has already been issued return role_kind = role_kind[0] if role_kind not in fs_handler.valid_roles: logger.debug("Ignoring '%s' role for: %s", role_kind, repr(attributes)) return if not timeslot_is_valid(lower(attributes)): logger.debug("Ignoring '%s' - data too old/in the future: " "attrs=%s", role_kind, lower(attributes)) return attrs = fs_handler.fixup_attributes(attributes) if attrs["rollekode"] not in fs_handler.valid_role_codes: logger.debug("Ignoring '%s' role, role code %s: attrs=%s", role_kind, attrs["rollekode"], attrs) return logger.debug("Collecting role '%s' with %s", role_kind, repr(attributes)) group_key = fs_handler.attributes2key(role_kind, attrs) if group_key is None: return fs_handler.register_description(group_key, attrs) if group_key is None: logger.warn("Failed to create group key for role=%s/attrs=%s", role_kind, attrs) return if not fs_handler.role_is_exportable(role_kind, attrs): logger.debug("Ignoring role=%s/attrs=%s (not exportable to LMS)", role_kind, attrs) return fnr = "%06d%05d" % (int(attrs["fodselsdato"]), int(attrs["personnr"])) result.setdefault(group_key, set()).add(fnr)
def collect_student_info(edu_info_file, fs_handler): """Read student data and build a suitable data structure. Since we have student rooms for undenh, undakt and kullklasse, these are the XML tags we are interested in. The rest is of no consequence. """ result = dict() # FIXME: it's silly to iterate the same file multiple times # for (xml_tag, edu_info_type) in (("undenh", "student-undenh"), ("undakt", "student-undakt"), ("kullklasse", "student-kullklasse"), ("kull", "student-kull")): logger.debug("Processing <%s> elements", xml_tag) for entry in EduGenericIterator(edu_info_file, xml_tag): attrs = fs_handler.fixup_attributes(entry) if not timeslot_is_valid(attrs): logger.debug("Ignoring '%s' - data too old/in the future: " "attrs=%s", xml_tag, attrs) continue key = fs_handler.attributes2key(edu_info_type, attrs) if key is None: continue fs_handler.register_description(key, attrs) if key is None: logger.warn("Failed to create group key for entry=%s/attrs=%s", xml_tag, attrs) continue if not fs_handler.edu_entry_is_exportable(xml_tag, attrs): logger.debug("Ignoring %s/attrs=%s (not exportable to LMS)", xml_tag, attrs) continue fnr = "%06d%05d" % (int(attrs["fodselsdato"]), int(attrs["personnr"])) result.setdefault(key, set()).add(fnr) logger.debug("%s student groups (%s individual memberships) arose from %s", len(result), sum(len(y) for y in result.itervalues()), edu_info_file) return result