#!/usr/bin/env python
""" 
A plugin extendable hostlist infrastructure, command line
utility.

This utility provides functions for getting a list of hosts
from various systems as well as compressing the list into
a simplified list.

This module uses the hostlists_plugins python scripts
to actually obtain the listings.  
"""

# noinspection PyStatementEffect
"""
 Copyright (c) 2010 Yahoo! Inc. All rights reserved.
 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. See accompanying LICENSE file.
"""
from hostlists import *
from optparse import OptionParser

if __name__ == "__main__":
    parser = OptionParser(usage="usage: %prog [options] plugin:parameters")
    parser.add_option("-s","--sep",dest="sep",default=',',help="Separator character, default=\",\"")
    parser.add_option("--onepass",dest="onepass",default=False,action="store_true")
    parser.add_option("--expand","-e",dest="expand",default=False,action="store_true",help="Expand the host list and display one host per line")
    (options, args) = parser.parse_args()
    hostnames = range_split(','.join(args))
    if options.expand:
        print '\n'.join(expand(hostnames, onepass=options.onepass))
    else:
        print ', '.join(compress(expand(hostnames, onepass=options.onepass)))
