 import errno <EOL> from functools import wraps <EOL> import os <EOL> import signal <EOL> import sys <EOL> import re <EOL> import time <EOL> import requests <EOL> from compose . cli import command <EOL> class TimeoutError ( Exception ) : <EOL> pass <EOL> def timeout ( seconds = <NUM_LIT:10> , error_message = os . strerror ( errno . ETIME ) ) : <EOL> def decorator ( func ) : <EOL> def _handle_timeout ( signum , frame ) : <EOL> raise TimeoutError ( error_message ) <EOL> def wrapper ( * args , ** kwargs ) : <EOL> signal . signal ( signal . SIGALRM , _handle_timeout ) <EOL> signal . alarm ( seconds ) <EOL> try : <EOL> result = func ( * args , ** kwargs ) <EOL> finally : <EOL> signal . alarm ( <NUM_LIT:0> ) <EOL> return result <EOL> return wraps ( func ) ( wrapper ) 
 return decorator 
 import errno <EOL> from functools import wraps <EOL> import os <EOL> import signal <EOL> import sys <EOL> import re <EOL> import time <EOL> import requests <EOL> from compose . cli import command <EOL> class TimeoutError ( Exception ) : <EOL> pass <EOL> def timeout ( seconds = <NUM_LIT:10> , error_message = os . strerror ( errno . ETIME ) ) : <EOL> def decorator ( func ) : <EOL> def _handle_timeout ( signum , frame ) : <EOL> raise TimeoutError ( error_message ) <EOL> def wrapper ( * args , ** kwargs ) : <EOL> signal . signal ( signal . SIGALRM , _handle_timeout ) <EOL> signal . alarm ( seconds ) <EOL> try : <EOL> result = func ( * args , ** kwargs ) <EOL> finally : <EOL> signal . alarm ( <NUM_LIT:0> ) <EOL> return result <EOL> return wraps ( func ) ( wrapper ) <EOL> return decorator <EOL> @ timeout ( <NUM_LIT:30> ) <EOL> def wait_for_marathon ( ) : <EOL> """<STR_LIT>""" <EOL> marathon_service = get_marathon_connection_string ( ) <EOL> while True : <EOL> print '<STR_LIT>' % marathon_service <EOL> try : <EOL> response = requests . get ( <EOL> '<STR_LIT>' % marathon_service , timeout = <NUM_LIT:2> ) <EOL> except ( <EOL> requests . exceptions . ConnectionError , <EOL> requests . exceptions . Timeout , <EOL> ) : <EOL> time . sleep ( <NUM_LIT:2> ) <EOL> continue <EOL> if response . status_code == <NUM_LIT:200> : <EOL> print "<STR_LIT>" <EOL> break <EOL> def get_compose_service ( service_name ) : <EOL> """<STR_LIT>""" <EOL> cmd = command . Command ( ) <EOL> project = cmd . get_project ( cmd . get_config_path ( ) ) <EOL> return project . get_service ( service_name ) <EOL> def get_marathon_connection_string ( ) : <EOL> if '<STR_LIT>' in os . environ . get ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> else : <EOL> service_port = get_service_internal_port ( '<STR_LIT>' ) <EOL> local_port = get_compose_service ( '<STR_LIT>' ) . get_container ( ) . get_local_port ( service_port ) <EOL> if sys . platform == '<STR_LIT>' : <EOL> m = re . match ( "<STR_LIT>" , os . environ [ "<STR_LIT>" ] ) <EOL> local_port = "<STR_LIT>" . format ( m . group ( <NUM_LIT:2> ) , local_port . split ( "<STR_LIT::>" ) [ <NUM_LIT:1> ] ) <EOL> return local_port <EOL> def get_service_internal_port ( service_name ) : <EOL> """<STR_LIT>""" <EOL> return get_compose_service ( service_name ) . options [ '<STR_LIT>' ] [ <NUM_LIT:0> ] </s>
