#!/usr/bin/env python2.7
 
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
 
"""
Generates a list of podling dev mailing lists based on podlings.xml contents
"""
 
import sys
if sys.version_info < (2, 7):
    raise Exception("Python 2.7 or above is required")
 
import xml.dom.minidom
import urllib

PODLINGS_URL = 'http://svn.apache.org/repos/asf/incubator/public/trunk/content/podlings.xml'
SPECIALS = ['wave','blur']

 
def processPodlings(xmlFile):
    """
    Parse a podlings.xml stream
    """
    dom = xml.dom.minidom.parse(xmlFile)
    for row in dom.getElementsByTagName("podling"):
        if row.getAttribute("status") != 'current':
            continue
        podling_id = row.getAttribute("name").strip()
        podling_id = podling_id.lower().replace(' ', '')
        if podling_id == 'odftoolkit':
            print("odf-dev@incubator.apache.org")
        elif podling_id in SPECIALS:
            print("%s-dev@incubator.apache.org" % podling_id)
        else:
            print("dev@%s.incubator.apache.org" % podling_id)
 
def main():
    podlings_xml = urllib.urlopen(PODLINGS_URL)
    processPodlings(podlings_xml)
 
if __name__ == '__main__':
    main()
