Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Unified Diff: testing/legion/common_lib.py

Issue 890773003: Adding the initial code for Omnibot multi-machine support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing some silly subprocess code. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: testing/legion/common_lib.py
diff --git a/testing/legion/common_lib.py b/testing/legion/common_lib.py
new file mode 100644
index 0000000000000000000000000000000000000000..1f4f68e9ebf3a980c64e5052cc6b9317d33ec786
--- /dev/null
+++ b/testing/legion/common_lib.py
@@ -0,0 +1,48 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Common library methods used by both host and client controllers."""
+
+import argparse
+import logging
+import socket
+import sys
+import xmlrpclib
+
+LOGGING_FORMAT = ('%(asctime)s %(filename)s:%(lineno)s %(levelname)s] '
M-A Ruel 2015/02/03 01:48:41 I'd probably wouldn't make it a named constant unl
Mike Meade 2015/02/03 17:47:57 Done.
+ '%(message)s')
+LOGGING_DATE_FORMAT = '%H:%M:%S'
+LOGGING_LEVELS = ['DEBUG', 'INFO', 'WARNING', 'WARN', 'ERROR']
+MY_IP = socket.gethostbyname(socket.gethostname())
+SERVER_ADDRESS = ''
+SERVER_PORT = 31710
+DEFAULT_TIMEOUT_SECS = 20 * 60 # 30 minutes
+
+
+def InitLogging():
+ """Initialize the logging module.
+
+ Raises:
+ argparse.ArgumentError if the --verbosity arg is incorrect.
+ """
+ parser = argparse.ArgumentParser()
+ logging_action = parser.add_argument('--verbosity', default='ERROR')
M-A Ruel 2015/02/03 01:48:41 I generally use instead action='count' then use it
Mike Meade 2015/02/03 17:47:57 Acknowledged.
+ args, _ = parser.parse_known_args()
+ if args.verbosity not in LOGGING_LEVELS:
+ raise argparse.ArgumentError(
+ logging_action, 'Only levels %s supported' % str(LOGGING_LEVELS))
+ logging.basicConfig(format=LOGGING_FORMAT, datefmt=LOGGING_DATE_FORMAT,
+ level=args.verbosity)
+
+
+def PrintCommandLine():
M-A Ruel 2015/02/03 01:48:41 What's the use case? In particular I don't think t
Mike Meade 2015/02/03 17:47:57 Done.
+ """Print the command line used to run this program."""
+ print ' '.join(sys.argv)
+
+
+def ConnectToServer(server):
+ """Connect to an RPC server."""
+ addr = 'http://%s:%d' % (server, SERVER_PORT)
+ logging.debug('Connecting to RPC server at %s', addr)
+ return xmlrpclib.Server(addr)

Powered by Google App Engine
This is Rietveld 408576698