#!/usr/bin/env python
##############################################################################
# Part of the Agnos RPC Framework
#    http://agnos.sourceforge.net
#
# Copyright 2011, International Business Machines Corp.
#                 Author: Tomer Filiba (tomerf@il.ibm.com)
#
# Licensed 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.
##############################################################################

"""
example usage:
    agnos-py /path/to/my/package -o /another/path
which results in the following files under /another/path:
    * myservice.xml - the idl of myservice
    * myservice_bindings.py - agnos-generated binding code
    * myservice_server.py - executable server file
"""
import os
import sys
from optparse import OptionParser
from agnos_compiler.pysrcgen.generator import main 


parser = OptionParser()
parser.add_option("-o", "--outdir", dest="outdir", default=None,
                  help="generate output into OUTDIR; the default directory used is that of the input file",  
                  metavar="OUTDIR")
parser.add_option("--idlfile", dest="idlfile", default=None,
                  help="specify the generated idl file (by default, it is named as the service)", 
                  metavar="FILENAME")
parser.add_option("--serverfile", dest="serverfile", default=None,
                  help="specify the generated server file name (by default, it is named as the service, suffixed by '_server.py')", 
                  metavar="FILENAME")
parser.add_option("-p", "--packagename", dest="packagename", default=None,
                  help="specify the root package name (by default, the top directory is used)", 
                  metavar="NAME")
parser.add_option("--historyfile", dest="history_file", default=None,
                  help="specify the history file to use (by default, '_history' is appended to the idlfile's name)", 
                  metavar="NAME")
parser.add_option("-O", "--opt", dest="options", action="append", default=[],
                  help="pass target-specific options, see agnosc for more info", 
                  metavar="OPTIONS")


if __name__ == "__main__":
    options, args = parser.parse_args()
    if not args:
        parser.error("must specify agnos input file(s)")
    for fn in args:
        main(fn, outdir = options.outdir, packagename = options.packagename,
            serverfile = options.serverfile, idlfile = options.idlfile,
            history_file = options.history_file, target_options = options.options)


