def build_zone_files(self, soas, soa_pks_to_rebuild, gen_config=True):
        zone_stmts = {}

        for soa in soas:
            # If anything happens during this soa's build we need to mark
            # it as dirty so it can be rebuild
            try:
                root_domain = soa.root_domain  # This is an expensive lookup
                if not root_domain:
                    # TODO, figure out how to send a nagios alert on this case.
                    self.log("No root domain found in zone {0}".format(soa))
                    fail_mail(
                        "{0} is an orphan. It's being skipped in the "
                        "builds".format(soa), subject="{0} is "
                        "orphaned".format(soa))
                    continue

                force_rebuild = soa.pk in soa_pks_to_rebuild or soa.dirty
                if force_rebuild and self.PUSH_TO_PROD:
                    soa.dirty = False
                    soa.save()

                self.log("====== Processing {0} {1} ======".format(
                    root_domain, soa.serial)
                )

                view_contents = self.build_views(
                    soa, root_domain, gen_config, force_rebuild
                )

                next_serial = soa.get_incremented_serial()

                if force_rebuild:
                    # Bypass save so we don't have to save a possible stale
                    # 'dirty' value to the db.
                    SOA.objects.filter(pk=soa.pk).update(serial=next_serial)
                    self.log(
                        "Zone will be rebuilt at serial {0}"
                        .format(next_serial),
                        root_domain=root_domain
                    )
                else:
                    self.log(
                        "Zone is stable at serial {0}".format(soa.serial),
                        root_domain=root_domain
                    )

                self.do_build(
                    zone_stmts, soa, view_contents, root_domain,
                    gen_config, force_rebuild, next_serial
                )
            except Exception:
                soa.schedule_full_rebuild()
                raise

        return zone_stmts
For every soa in soas, build a views that are valid for its zone. If
dataset/ETHPy150Open mozilla/inventory/mozdns/mozbind/builder.py/DNSBuilder.build_zone_files