def match_daoset_ids(c01: etree._Element, volume_files: set[str]) -> None: """Checks all dao elements in a volume and checks if they can be found in a volume directory. Prints a warning if a file is never used. """ with open("outputs/missing_files", "a", encoding="utf-8") as log: missing_files = set() for dao in c01.iterdescendants("dao"): try: volume_files.remove(str(dao.attrib["id"])) except KeyError: missing_files.add(dao.attrib["id"]) if missing_files or volume_files: # pylint: disable-next=line-too-long print( f"\n** Controlling MS{c01.find('did').find('unitid').text} **", file=log) # type: ignore[union-attr] if missing_files: print( "The following files are described in excel but do not have an associated scan:", file=log, ) print( "I seguenti file sono descritti in Excel ma non hanno una scansione associata:", file=log, ) for file_name in sorted(missing_files): print(f" - {file_name!r}", file=log) if volume_files: print( "The following files exist as scan but are not described in excel:", file=log, ) print( "I seguenti file esistono come scansione ma non sono descritti in excel:", file=log, ) for file_name in sorted(volume_files): print(f" + {file_name}", file=log)
def descend(el: ET._Element, set_val): put_attr(el, set_val) for d in el.iterdescendants(): put_attr(d, set_val)
def namespaceify(tree: etree._Element, namespace=TEI_NS): """Moves every element in the subtree that does _not_ have a namespace into the given namespace""" prefix = '{' + namespace + '}' for el in chain([tree], tree.iterdescendants()): if '{' not in el.tag: el.tag = prefix + el.tag