<s> import sys <EOL> import argparse <EOL> import logging <EOL> from . import utils <EOL> from . call_manager import CallManager <EOL> from . call_manager import Call <EOL> try : <EOL> import yaml <EOL> except ImportError : <EOL> yaml = None <EOL> def main ( argv = None ) : <EOL> parser = argparse . ArgumentParser ( ) <EOL> if yaml is None : <EOL> parser . error ( '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , <EOL> type = argparse . FileType ( '<STR_LIT:r>' ) , <EOL> required = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> type = argparse . FileType ( '<STR_LIT:r>' ) , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> type = argparse . FileType ( '<STR_LIT:w>' ) , <EOL> default = '<STR_LIT:->' , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( argv or sys . argv [ <NUM_LIT:1> : ] ) <EOL> config = utils . config ( args . config ) <EOL> config [ '<STR_LIT>' ] = args . output <EOL> call_manager = CallManager ( ** config ) <EOL> task = call_manager . connect ( ) <EOL> logging . basicConfig ( stream = sys . stderr , level = logging . INFO ) <EOL> logging . getLogger ( '<STR_LIT>' ) . setLevel ( logging . ERROR ) <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> def done ( future ) : <EOL> result = future . result ( ) <EOL> log . info ( '<STR_LIT>' , result ) <EOL> if isinstance ( result , Call ) : <EOL> while not result . queue . empty ( ) : <EOL> print ( result . queue . get_nowait ( ) ) <EOL> def show ( f = None ) : <EOL> if f : <EOL> print ( f . result ( ) ) <EOL> f = utils . asyncio . Task ( result . queue . get ( ) ) <EOL> f . add_done_callback ( show ) <EOL> show ( ) <EOL> def send_action ( f ) : <EOL> if args . input : <EOL> action = yaml . load ( args . input ) <EOL> if action . get ( '<STR_LIT>' ) . lower ( ) == '<STR_LIT>' : <EOL> future = call_manager . send_originate ( action ) <EOL> elif action . get ( '<STR_LIT>' ) . lower ( ) == '<STR_LIT>' : <EOL> future = call_manager . send_agi_command ( action ) <EOL> elif '<STR_LIT>' in [ k . lower ( ) for k in action . keys ( ) ] : <EOL> future = call_manager . send_command ( action ) <EOL> else : <EOL> future = call_manager . send_action ( action ) <EOL> log . info ( '<STR_LIT>' , action ) <EOL> future . add_done_callback ( done ) <EOL> def connected ( f ) : <EOL> if call_manager . authenticated_future is not None : <EOL> call_manager . authenticated_future . add_done_callback ( send_action ) <EOL> else : <EOL> send_action ( f ) <EOL> task . add_done_callback ( connected ) <EOL> try : <EOL> call_manager . loop . run_forever ( ) <EOL> except KeyboardInterrupt : <EOL> args . output . close ( ) </s>
