#!/usr/bin/python
# Copyright (c) Members of the EGEE Collaboration. 2004. 
# See http://www.eu-egee.org/partners/ for details on the copyright
# holders.  
#
# 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.
# get information from pbs/torque LRMS, spit it out in uniform format


# generate generic information on maximum job
# counts per VO.  This version works with Maui.

import sys
import getopt
import string
import commands

from TorqueInfoUtils import MAUIHandler

def usage():
    print "Usage: vomaxjobs-maui [-h <schedulerhost>] [-k keyfile] [-i inputfile]"
    


def main():
    try:

        schedhost = None
        infile = None
        keyarg = None

        opts, args = getopt.getopt(sys.argv[1:], "h:i:k:",
                                   ["host=","input=","keyfile="])

        for opt, arg in opts:
            if opt in ("-h", "--host"):
                schedhost = arg
            elif opt in ("-i", "--input"):
                infile = arg
            elif opt in ("-k", "--keyfile"):
                keyarg = arg
        
        if MAUIHandler.available():
            container = MAUIHandler.parseJobLimit(schedhost, keyarg, infile)
            sys.stdout.write(str(container.limitTable) + "\n")
        else:
            sys.stdout.write("{}\n")

    except getopt.GetoptError:
        print sys.argv[0] + ": error parsing command line\n"
        usage()
        sys.exit(2)
    except:
        etype, evalue, etraceback = sys.exc_info()
        sys.excepthook(etype, evalue, etraceback)
        sys.exit(3)


if __name__ == "__main__":
    main()

