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 coordinator and task machines."""
13 LOGGING_LEVELS
= ['DEBUG', 'INFO', 'WARNING', 'WARN', 'ERROR']
14 MY_IP
= socket
.gethostbyname(socket
.gethostname())
17 DEFAULT_TIMEOUT_SECS
= 20 * 60 # 30 minutes
18 THIS_DIR
= os
.path
.dirname(os
.path
.abspath(__file__
))
19 SWARMING_DIR
= os
.path
.join(THIS_DIR
, '..', '..', 'tools', 'swarming_client')
23 """Initialize the logging module.
26 argparse.ArgumentError if the --verbosity arg is incorrect.
28 parser
= argparse
.ArgumentParser()
29 logging_action
= parser
.add_argument('--verbosity', default
='ERROR')
30 args
, _
= parser
.parse_known_args()
31 if args
.verbosity
not in LOGGING_LEVELS
:
32 raise argparse
.ArgumentError(
33 logging_action
, 'Only levels %s supported' % str(LOGGING_LEVELS
))
35 format
='%(asctime)s %(filename)s:%(lineno)s %(levelname)s] %(message)s',
36 datefmt
='%H:%M:%S', level
=args
.verbosity
)
39 def ConnectToServer(server
):
40 """Connect to an RPC server."""
41 addr
= 'http://%s:%d' % (server
, SERVER_PORT
)
42 logging
.debug('Connecting to RPC server at %s', addr
)
43 return xmlrpclib
.Server(addr
)