#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2010 by Intevation GmbH
# Authors:
# Bjoern Ricks <bjoern.ricks@intevation.de>
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with the software for details.

import sys
import os.path

from porttemplate import PortTemplate
from ConfigParser import SafeConfigParser
from optparse import OptionParser

def main():
    optparser = OptionParser(description="This tool generates MacPort Port" \
                            " files from templates.")
    optparser.add_option("--config", dest="config", help=("The update-port"
                         " config file. Default ports.cfg"), 
                         default="ports.cfg")

    (options, args) = optparser.parse_args()

    if not os.path.exists(options.config):
        print >> sys.stderr, "config %s not found." % options.config

    confparser = SafeConfigParser()
    confparser.read(options.config)
    
    for section in confparser.sections():
        tagurl = confparser.get(section, "tagurl")
        tagsubdir = confparser.get(section, "tagsubdir")
        tagpattern = confparser.get(section, "tagpattern")
        portfile = confparser.get(section, "portfile")
        templatefile = confparser.get(section, "template")
        scm = confparser.get(section, "scm")
        
        print "creating port for %s " % section
        porttemplate = PortTemplate(section, templatefile, portfile, tagurl,
                         tagpattern, tagsubdir, scm)
        porttemplate.write()
        
if __name__ == '__main__':
    main()

# vim:fenc=utf-8:et:sw=4:ts=4:tw=80: 
