'Write the master index of all Sitemap files'

def WriteIndex(self):

    filename = self._filegen.GeneratePath(SITEINDEX_SUFFIX)
    if (not filename):
        output.Fatal("Unexpected:    Couldn't    generate    output    index    filename.")
    output.Log(('Writing    index    file    "%s"    with    %d    Sitemaps' % (filename, self._sitemaps)), 1)
    lastmod = TimestampISO8601(time.time())
    try:
        fd = open(filename, 'wt')
        fd.write(SITEINDEX_HEADER)
        for mapnumber in range(0, self._sitemaps):
            mapurl = self._filegen.GenerateURL(mapnumber, self._base_url)
            mapattributes = {'loc': mapurl, 'lastmod': lastmod}
            fd.write((SITEINDEX_ENTRY % mapattributes))
        fd.write(SITEINDEX_FOOTER)
        fd.close()
        fd = None
    except IOError:
        output.Fatal(("Couldn't    write    out    to    file:    %s" % filename))
    os.chmod(filename, 420)
