Refactor duplicate code for calling into media controls
[WebKit-https.git] / Websites / perf.webkit.org / tools / util.py
index 86956b4c6e9a18801c0618d37337b844e2d925ac..31287903f0a11abf37dc061ec9425ed0fb18243b 100644 (file)
@@ -3,7 +3,7 @@ import sys
 import urllib2
 
 
-def submit_commits(commits, dashboard_url, slave_name, slave_password):
+def submit_commits(commits, dashboard_url, slave_name, slave_password, status_to_accept=['OK']):
     try:
         payload = json.dumps({
             'slaveName': slave_name,
@@ -20,8 +20,9 @@ def submit_commits(commits, dashboard_url, slave_name, slave_password):
         except Exception, error:
             raise Exception(error, output)
 
-        if result.get('status') != 'OK':
+        if result.get('status') not in status_to_accept:
             raise Exception(result)
+        return result
     except Exception as error:
         sys.exit('Failed to submit commits: %s' % str(error))
 
@@ -51,3 +52,12 @@ def setup_auth(server):
     password_manager.add_password(realm=auth['realm'], uri=server['url'], user=auth['username'], passwd=auth['password'])
     auth_handler = HTTP_AUTH_HANDLERS[auth['type']](password_manager)
     urllib2.install_opener(urllib2.build_opener(auth_handler))
+
+
+def load_server_config(json_path):
+    with open(json_path) as server_config_json:
+        server_config = json.load(server_config_json)
+        server = server_config['server']
+        server['url'] = server['scheme'] + '://' + server['host'] + ':' + str(server['port'])
+        setup_auth(server)
+        return server_config