def FetchLogs(opener, api_host):
 fetch_dir = os.path.join((options.options.fetch_dir or os.getcwd()), 'logs')
 logging.info(('writing logs for user %s to %s' % (options.options.user_id, fetch_dir)))
 _InitDir(fetch_dir)
 io_loop = ioloop.IOLoop.instance()
 http_client = httpclient.AsyncHTTPClient(io_loop)
 log_urls = GetLogUrls(opener, api_host)
 with util.Barrier(io_loop.stop) as b:
  for log_record in log_urls:
   output_file = os.path.join(fetch_dir, log_record['filename'])
   if (os.path.exists(output_file) and options.options.cache_logs):
    log_record['local_filename'] = output_file
    continue
   _InitDir(os.path.dirname(output_file))
   try:
    _FetchLog(http_client, log_record['url'], output_file, b.Callback())
    log_record['local_filename'] = output_file
   except:
    logging.exception(('failed to fetch %s' % log_record['url']))
    log_record['local_filename'] = None
 io_loop.start()
 logging.info(('fetched %d log files for user %s' % (len(log_urls), options.options.user_id)))
 return log_urls

def FetchLogs ( opener , api_host ) : fetch_dir = os . path . join ( ( options . options . fetch_dir or os . getcwd ( ) ) , 'logs' ) logging . info ( ( 'writing logs for user %s to %s' % ( options . options . user_id , fetch_dir ) ) ) _InitDir ( fetch_dir ) io_loop = ioloop . IOLoop . instance ( ) http_client = httpclient . AsyncHTTPClient ( io_loop ) log_urls = GetLogUrls ( opener , api_host ) with util . Barrier ( io_loop . stop ) as b : for log_record in log_urls : output_file = os . path . join ( fetch_dir , log_record [ 'filename' ] ) if ( os . path . exists ( output_file ) and options . options . cache_logs ) : log_record [ 'local_filename' ] = output_file continue _InitDir ( os . path . dirname ( output_file ) ) try : _FetchLog ( http_client , log_record [ 'url' ] , output_file , b . Callback ( ) ) log_record [ 'local_filename' ] = output_file except : logging . exception ( ( 'failed to fetch %s' % log_record [ 'url' ] ) ) log_record [ 'local_filename' ] = None io_loop . start ( ) logging . info ( ( 'fetched %d log files for user %s' % ( len ( log_urls ) , options . options . user_id ) ) ) return log_urls
queries logs urls from the admin service api and fetches the files into --fetch_dir .