Beispiel #1
0
def report_phone(options, model, predicate, local):
    if predicate is None:
        predicate = is_principal & is_other(instance_p(Person) | instance_p(Company))
    tkw = {'fax': False, 'bold': True}
    itemiser = Itemiser()
    itemiser.update(model.nodes(is_other(instance_p(NamedNode)) & predicate))
    # Remove entries for families for which one or more of the heads was found.
    people = [node for node in itemiser if isinstance(node, Person)]
    for person in people:
        for belongs_to in person.links(outgoing & is_link(Belongs_to)):
            if belongs_to.is_head:
                itemiser.discard(belongs_to.family)
    from sixx.output import Treebuf
    tree = Treebuf(local=local)
    for item in sorted(itemiser.items()):
        if item is not item.single:
            continue
        node = item.node
        tree.nl()
        sub = tree.sub()
        if isinstance(node, Person):
            tree.add(node, underline=True)
            for aka in node.aka:
                tree.add(' (')
                tree.add(aka)
                tree.add(')')
            tree.nl()
            dump_comments(node, sub)
            telephones(node, sub, **tkw)
            for tup in node.find_nodes(
                    (outgoing & is_link(Belongs_to)) |
                    (outgoing & is_link(Resides_at)) |
                    (outgoing & is_link(Works_at))):
                telephones_qual(tup, sub, **tkw)
        elif isinstance(node, Family):
            tree.add(node, underline=True)
            for aka in node.aka:
                tree.add(' (')
                tree.add(aka)
                tree.add(')')
            tree.nl()
            dump_comments(node, sub)
            telephones(node, sub, **tkw)
            for tup in node.find_nodes(outgoing & is_link(Resides_at)):
                comment = []
                for node1 in tup:
                    if isinstance(node1, Resides_at):
                        comment.append(node1.residence.lines[0])
                telephones(tup[-1], sub, comment=', '.join(comment), **tkw)
            for link in sorted(node.links(incoming & is_link(Belongs_to))):
                sub.add(link.person.familiar_name(), underline=True)
                sub.nl()
                subsub = sub.sub()
                telephones(link, subsub, **tkw)
                telephones(link.person, subsub, **tkw)
                for tup in link.person.find_nodes(
                        (outgoing & is_link(Works_at)) |
                        (outgoing & is_link(Resides_at))):
                    telephones_qual(tup, subsub, **tkw)
        elif isinstance(node, Organisation):
            tree.add(node, underline=True)
            if isinstance(node, Department):
                link = node.link(incoming & is_link(Has_department))
                if link:
                    tree.add(', ', link.company)
            for aka in node.aka:
                tree.add(' (')
                tree.add(aka)
                tree.add(')')
            tree.nl()
            dump_comments(node, sub)
            telephones(node, sub, **tkw)
            telephones_org(node, sub, **tkw)
            for loc in node.nodes(outgoing & is_link(Located_at)):
                telephones_org(loc, sub, **tkw)
            for dept in node.nodes(outgoing & is_link(Has_department)):
                sub.add(dept, underline=True)
                sub.nl()
                subsub = sub.sub()
                telephones(dept, subsub, **tkw)
                telephones_org(dept, subsub, **tkw)
    print(str(tree))
Beispiel #2
0
def report_dump(options, model, predicate, local):
    sort_mode = sort_modes.get(options.sort_mode, SortMode.FIRST_NAME)
    # If no predicate given, then select all people, organisations, and
    # families.
    if predicate is None:
        predicate = node_predicate(lambda node: True)
    # Populate the top level of the report with all the nodes that satisfy the
    # predicate.
    itemiser = Itemiser(sort_mode)
    itemiser.update(model.nodes(is_other(instance_p(NamedNode) & predicate)))
    # These sets control where entries are listed.
    seen = set(itemiser)
    see_in = defaultdict(set)
    alias = dict()
    # Form the sorted index of all the top-level entries in the report.
    toplevel = sorted(chain(list(itemiser.items()),
                            itemiser.alias_items(iter(alias.items()))))
    # Remove unnecessary references.
    cull_references(toplevel)
    # Now format the report.
    from sixx.output import Treebuf
    tree = Treebuf(local=local, sort_mode=sort_mode)
    for item in toplevel:
        if item.node is None:
            pass
        elif item is not item.single:
            tree.nl()
            tree.add(item.key, ' -> ', item.single.key)
            tree.nl()
        elif isinstance(item.node, Person):
            tree.nl()
            dump_names(item.node, tree, name=item.key)
            dump_person(item.node, tree.sub(),
                        seen - see_in.get(item.node, set()))
        elif isinstance(item.node, Family):
            tree.nl()
            dump_names(item.node, tree, name=item.key)
            dump_family(item.node, tree.sub(),
                        seen - see_in.get(item.node, set()))
        elif isinstance(item.node, Department):
            tree.nl()
            dump_names(item.node, tree, name=item.key)
            dump_organisation(item.node, tree.sub(),
                              seen - see_in.get(item.node, set()))
        elif isinstance(item.node, Organisation):
            tree.nl()
            dump_names(item.node, tree, name=item.key)
            dump_organisation(item.node, tree.sub(),
                              seen - see_in.get(item.node, set()))
    if options.output_path:
        ofile = file(options.output_path, 'wb', encoding=options.encoding, errors='replace')
    else:
        ofile = sys.stdout
    ofile.write(str(tree))