def wait_for_winexesvc(host, port, username, password, timeout=900):
 start = time.time()
 log.debug('Attempting winexe connection to host {0} on port {1}'.format(host, port))
 creds = "-U '{0}%{1}' //{2}".format(username, password, host)
 logging_creds = "-U '{0}%XXX-REDACTED-XXX' //{1}".format(username, host)
 try_count = 0
 while True:
  try_count += 1
  try:
   ret_code = win_cmd('winexe {0} "sc query winexesvc"'.format(creds), logging_command=logging_creds)
   if (ret_code == 0):
    log.debug('winexe connected...')
    return True
   log.debug('Return code was {0}'.format(ret_code))
   time.sleep(1)
  except socket.error as exc:
   log.debug('Caught exception in wait_for_winexesvc: {0}'.format(exc))
   time.sleep(1)
   if ((time.time() - start) > timeout):
    log.error('winexe connection timed out: {0}'.format(timeout))
    return False
   log.debug('Retrying winexe connection to host {0} on port {1} (try {2})'.format(host, port, try_count))

def wait_for_winexesvc ( host , port , username , password , timeout = 900 ) : start = time . time ( ) log . debug ( 'Attempting winexe connection to host {0} on port {1}' . format ( host , port ) ) creds = "-U '{0}%{1}' //{2}" . format ( username , password , host ) logging_creds = "-U '{0}%XXX-REDACTED-XXX' //{1}" . format ( username , host ) try_count = 0 while True : try_count += 1 try : ret_code = win_cmd ( 'winexe {0} "sc query winexesvc"' . format ( creds ) , logging_command = logging_creds ) if ( ret_code == 0 ) : log . debug ( 'winexe connected...' ) return True log . debug ( 'Return code was {0}' . format ( ret_code ) ) time . sleep ( 1 ) except socket . error as exc : log . debug ( 'Caught exception in wait_for_winexesvc: {0}' . format ( exc ) ) time . sleep ( 1 ) if ( ( time . time ( ) - start ) > timeout ) : log . error ( 'winexe connection timed out: {0}' . format ( timeout ) ) return False log . debug ( 'Retrying winexe connection to host {0} on port {1} (try {2})' . format ( host , port , try_count ) )
wait until winexe connection can be established .