<s> import sys <EOL> import tty <EOL> import time <EOL> import termios <EOL> import signal <EOL> import push . deploy <EOL> SIGNAL_MESSAGES = { signal . SIGINT : "<STR_LIT>" , <EOL> signal . SIGHUP : "<STR_LIT>" } <EOL> def read_character ( ) : <EOL> "<STR_LIT>" <EOL> fd = sys . stdin . fileno ( ) <EOL> old_settings = termios . tcgetattr ( fd ) <EOL> try : <EOL> tty . setcbreak ( fd ) <EOL> ch = sys . stdin . read ( <NUM_LIT:1> ) <EOL> finally : <EOL> termios . tcsetattr ( fd , termios . TCSADRAIN , old_settings ) <EOL> return ch <EOL> def wait_for_input ( log , deployer ) : <EOL> """<STR_LIT>""" <EOL> print >> log , ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> while True : <EOL> c = read_character ( ) <EOL> if c == "<STR_LIT:a>" : <EOL> print >> log , "<STR_LIT>" <EOL> return <NUM_LIT:0> <EOL> elif c == "<STR_LIT:x>" : <EOL> deployer . cancel_push ( '<STR_LIT>' ) <EOL> elif c == "<STR_LIT:c>" : <EOL> return <NUM_LIT:1> <EOL> else : <EOL> try : <EOL> num_hosts = int ( c ) <EOL> except ValueError : <EOL> continue <EOL> if num_hosts > <NUM_LIT:0> : <EOL> return num_hosts <EOL> def sleep_with_countdown ( log , sleeptime ) : <EOL> if sleeptime == <NUM_LIT:0> : <EOL> return <EOL> print >> log , "<STR_LIT>" , <EOL> log . flush ( ) <EOL> for i in xrange ( sleeptime , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> print >> log , "<STR_LIT>" % i , <EOL> log . flush ( ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> print >> log , "<STR_LIT>" <EOL> def register ( config , args , deployer , log ) : <EOL> def sighandler ( sig , stack ) : <EOL> reason = SIGNAL_MESSAGES [ sig ] <EOL> deployer . cancel_push ( reason ) <EOL> @ deployer . push_began <EOL> def on_push_began ( deployer ) : <EOL> signal . signal ( signal . SIGINT , sighandler ) <EOL> signal . signal ( signal . SIGHUP , sighandler ) <EOL> if args . testing : <EOL> log . warning ( "<STR_LIT>" ) <EOL> log . notice ( "<STR_LIT>" ) <EOL> log . notice ( "<STR_LIT>" , log . log_path ) <EOL> @ deployer . synchronize_began <EOL> def on_sync_began ( deployer ) : <EOL> log . notice ( "<STR_LIT>" ) <EOL> @ deployer . resolve_refs_began <EOL> def on_resolve_refs_began ( deployer ) : <EOL> log . notice ( "<STR_LIT>" ) <EOL> @ deployer . deploy_to_build_host_began <EOL> def on_deploy_to_build_host_began ( deployer ) : <EOL> log . notice ( "<STR_LIT>" ) <EOL> @ deployer . build_static_began <EOL> def on_build_static_began ( deployer ) : <EOL> log . notice ( "<STR_LIT>" ) <EOL> @ deployer . process_host_began <EOL> def on_process_host_began ( deployer , host ) : <EOL> log . notice ( '<STR_LIT>' , host ) <EOL> @ deployer . process_host_ended <EOL> def on_process_host_ended ( deployer , host ) : <EOL> host_index = args . hosts . index ( host ) + <NUM_LIT:1> <EOL> host_count = len ( args . hosts ) <EOL> percentage = int ( ( float ( host_index ) / host_count ) * <NUM_LIT:100> ) <EOL> log . notice ( '<STR_LIT>' , <EOL> host , host_index , host_count , percentage ) <EOL> if args . hosts [ - <NUM_LIT:1> ] == host : <EOL> pass <EOL> elif args . hosts_before_pause == <NUM_LIT:1> : <EOL> args . hosts_before_pause = wait_for_input ( log , deployer ) <EOL> else : <EOL> args . hosts_before_pause -= <NUM_LIT:1> <EOL> sleep_with_countdown ( log , args . sleeptime ) <EOL> @ deployer . push_ended <EOL> def on_push_ended ( deployer ) : <EOL> log . notice ( "<STR_LIT>" ) <EOL> @ deployer . push_aborted <EOL> def on_push_aborted ( deployer , exception ) : <EOL> if isinstance ( exception , push . deploy . PushAborted ) : <EOL> log . critical ( "<STR_LIT>" , exception ) <EOL> def host_error_prompt ( host , exception ) : <EOL> log . critical ( "<STR_LIT>" , host , exception ) <EOL> print >> log , ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> while True : <EOL> c = read_character ( ) <EOL> if c == "<STR_LIT:x>" : <EOL> return push . deploy . Deployer . ABORT <EOL> elif c == "<STR_LIT:c>" : <EOL> return push . deploy . Deployer . CONTINUE <EOL> elif c == "<STR_LIT:r>" : <EOL> return push . deploy . Deployer . RETRY <EOL> deployer . host_error_prompt = host_error_prompt </s>
