From f623cdba8d3dcf801b1483e15b5f0cb19ac77b4a Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 22 Jan 2015 19:16:43 +0100 Subject: Port test controller server to Java --- scripts/TestController.py | 83 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 scripts/TestController.py (limited to 'scripts/TestController.py') diff --git a/scripts/TestController.py b/scripts/TestController.py new file mode 100644 index 00000000000..cb227108f99 --- /dev/null +++ b/scripts/TestController.py @@ -0,0 +1,83 @@ +#!/usr/bin/env python +# ********************************************************************** +# +# Copyright (c) 2003-2015 ZeroC, Inc. All rights reserved. +# +# This copy of Ice is licensed to you under the terms described in the +# ICE_LICENSE file included in this distribution. +# +# ********************************************************************** + +import os, sys, threading, subprocess, getopt, signal + +path = [ ".", "..", "../..", "../../..", "../../../.." ] +head = os.path.dirname(sys.argv[0]) +if len(head) > 0: + path = [os.path.join(head, p) for p in path] +path = [os.path.abspath(p) for p in path if os.path.exists(os.path.join(p, "scripts", "TestUtil.py")) ] + +if len(path) == 0: + raise RuntimeError("can't find toplevel directory!") +sys.path.append(os.path.join(path[0], "scripts")) +import TestUtil + +# +# On OS X, provide an option to allow removing the trust settings +# +if TestUtil.isDarwin(): + try: + opts, args = getopt.getopt(sys.argv[1:], "", ["clean"]) + if ("--clean", "") in opts: + serverCert = os.path.join(path[0], "certs", "s_rsa1024_pub.pem") + if os.system("security verify-cert -c " + serverCert + " >& /dev/null") == 0: + sys.stdout.write("removing trust settings for the HTTP server certificate... ") + sys.stdout.flush() + if os.system("security remove-trusted-cert " + serverCert) != 0: + print("error: couldn't remove trust settings for the HTTP server certificate") + print("ok") + else: + print("trust settings already removed") + sys.exit(0) + except getopt.GetoptError: + pass + +version = "3.6b" +jar = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", + "java/test/controller/build/libs/testController-%(version)s.jar" % {"version": version}) +command = ("java -jar %(jar)s" % {"jar":jar}) + +p = subprocess.Popen(command, shell = True, stdin = subprocess.PIPE, stdout = subprocess.PIPE, + stderr = subprocess.STDOUT, bufsize = 0) + +def signal_handler(signal, frame): + if p: + p.terminate() +signal.signal(signal.SIGINT, signal_handler) + +while(True): + + c = p.stdout.read(1) + if not c: break + if c == '\r': continue + + # Depending on Python version and platform, the value c could be a + # string or a bytes object. + if type(c) != str: + c = c.decode() + sys.stdout.write(c) + sys.stdout.flush() + +if TestUtil.isDarwin(): + # + # On OS X, we set the trust settings on the certificate to prevent + # the Web browsers from prompting the user about the unstrusted + # certificate. Some browsers such as Chrome don't provide the + # option to set this trust settings. + # + serverCert = os.path.join(TestUtil.toplevel, "certs", "s_rsa1024_pub.pem") + if os.system("security verify-cert -c " + serverCert + " >& /dev/null") != 0: + sys.stdout.write("adding trust settings for the HTTP server certificate... ") + sys.stdout.flush() + if os.system("security add-trusted-cert -r trustAsRoot " + serverCert) != 0: + print("error: couldn't add trust settings for the HTTP server certificate") + print("ok") -- cgit v1.2.3