#!/usr/local/bin/python
import string,sys
sys.stdout = open('committers.html', 'w')

# populate dictionary fullname from passwd file

fullname = {}
for line in open('/etc/passwd','r').readlines():
  data = string.split(line,':')
  fullname[data[0]] = string.split(data[4],',')[0]

# populate dictionary module from avail file

module = {}
for line in open('/home/cvs/CVSROOT/avail','r').readlines():
  data = string.split(line,'|')
  if data[0]=='avail':
    for name in string.split(data[2][0:-1], ','):
      if not module.has_key(name): module[name]=[]
      for id in string.split(data[1], ','):
        if not id in module[name]: module[name].append(id)

# front matter

print '<html>'
print '<head>'
print '<title>Apache Committers by Module</title>'
print '</head>'
print '<bodygcolor="#ffffff" text="#000000" link="#525D76">'
print '<h1>Apache Committers by Module</h1>'
print '<table cellspacing="0" width="100%" border="0">'
print '<tr>'
print '<td colspan="2">'
# print '<a href="http://jakarta.apache.org">'
# print '<img border="0" align="left"'
# print ' src="http://jakarta.apache.org/images/jakarta-logo.gif" />';
# print '</a>'
print '</td>'
print '</tr>'
print '</table>'
print '<table cellspacing="4" width="100%" border="0">'
print '<tr>'
print '<td colspan="2">'
print '<hr size="1" noshade="" />'
print '</td>'
print '</tr>'
print '<tr>'
print '<td nowrap="true" valign="top">'
print '<h2>SubProjects</h2>'

# produce an index

modules = module.keys()
modules.sort()

cols=5
rows=(len(modules)+cols-1)/cols
print '<table border="0">'
for row in range(0,rows):
  print '<tr>'
  for col in range(0,cols):
    try:
      name=modules[row+col*rows]
      print '<td><a href="#' + name + '">' + name + '</a></td>'
    except:
      break
  print '</tr>'
print '</table>'

# produce a sorted list of committers to each project

print '<hr size="1" noshade="" />'
for name in modules:
  print '<h2 id="' + name + '">' + name + '</h2>'
  print '<table border="1">'
  module[name].sort()
  for id in module[name]:
    if fullname.has_key(id):
      print '  <tr>'
      print '    <td>' + id + '</td>'
      print '    <td>' + fullname[id] + '</td>'
      print '  </tr>'
  print '</table>'

# closing

print '</body>'
print '</html>'
