#!/usr/bin/python

import os, sys
import ConfigParser
from optparse import Option

import agversion
agversion.select(3)
from AccessGrid.interfaces.VenueServer_client import VenueServerIW
from AccessGrid.Venue import VenueIW
from AccessGrid.Toolkit import CmdlineApplication

app = CmdlineApplication()

urlOption = Option("-u", "--url", dest="url", default=None,
                   help="Specify a venue server url on the command line.")
app.AddCmdLineOption(urlOption)

args = app.Initialize()

venueServerUrl = app.GetOption("url")
venueServer = VenueServerIW(venueServerUrl)
venues = venueServer.GetVenues()

for venue in venues:
    theVenue = VenueIW(venue.uri)
    streams = theVenue.GetStreams()
    if len(streams) > 0:
        audioStream = None
        videoStream = None
        for stream in streams:
            for capability in stream.capability:
                if capability.type == "audio":
                    audioStream = stream
                elif capability.type == "video":
                    videoStream = stream
        
        if audioStream != None and videoStream != None:
            print(venue.name + "," + audioStream.location.host + "," + str(audioStream.location.port) + "," + videoStream.location.host + "," + str(videoStream.location.port)) 

