1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 """Common library methods used by both host and client controllers."""
12 LOGGING_LEVELS
= ['DEBUG', 'INFO', 'WARNING', 'WARN', 'ERROR']
13 MY_IP
= socket
.gethostbyname(socket
.gethostname())
16 DEFAULT_TIMEOUT_SECS
= 20 * 60 # 30 minutes
20 """Initialize the logging module.
23 argparse.ArgumentError if the --verbosity arg is incorrect.
25 parser
= argparse
.ArgumentParser()
26 logging_action
= parser
.add_argument('--verbosity', default
='ERROR')
27 args
, _
= parser
.parse_known_args()
28 if args
.verbosity
not in LOGGING_LEVELS
:
29 raise argparse
.ArgumentError(
30 logging_action
, 'Only levels %s supported' % str(LOGGING_LEVELS
))
32 format
='%(asctime)s %(filename)s:%(lineno)s %(levelname)s] %(message)s',
33 datefmt
='%H:%M:%S', level
=args
.verbosity
)
36 def ConnectToServer(server
):
37 """Connect to an RPC server."""
38 addr
= 'http://%s:%d' % (server
, SERVER_PORT
)
39 logging
.debug('Connecting to RPC server at %s', addr
)
40 return xmlrpclib
.Server(addr
)