Chromium Code Reviews| Index: chrome/test/pyautolib/chromoting_helper.py |
| =================================================================== |
| --- chrome/test/pyautolib/chromoting_helper.py (revision 0) |
| +++ chrome/test/pyautolib/chromoting_helper.py (revision 0) |
| @@ -0,0 +1,129 @@ |
| +# Copyright (c) 2012 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. |
| + |
| +"""Chromoting helper script to install/uninstall/enable/disable host.""" |
| + |
| +import os |
| +import sys |
| +import zipfile |
| +import subprocess |
| + |
| +def replacePrefPane(mock_pref_pane): |
| + pref_pane_dir = "/Library/PreferencePanes" |
| + chromoting_test_dir = "chrome/test/functional/chromoting" |
|
Nirnimesh
2012/07/31 20:15:10
use os.path.join
yihongg1
2012/08/03 00:40:06
Done.
|
| + subprocess.call(["rm", "-rf", pref_pane_dir + "/" + mock_pref_pane]) |
| + subprocess.call(["cp", "-f", chromoting_test_dir + "/" + mock_pref_pane, pref_pane_dir]) |
| + subprocess.call(["chmod", "a+x", pref_pane_dir + "/" + mock_pref_pane]) |
| + subprocess.call(["rm", "-rf", pref_pane_dir + "/org.chromium.chromoting.prefPane"]) |
| + subprocess.call(["ln", "-s", pref_pane_dir + "/" + mock_pref_pane, |
| + pref_pane_dir + "/org.chromium.chromoting.prefPane"]) |
| + |
| +def main(): |
| + if sys.argv[1] == 'install': |
| + if sys.platform.startswith('win'): |
| + host_msi = sys.argv[2] + "\\remoting-host.msi" |
| + subprocess.Popen(["msiexec", "/i", host_msi, "/passive"]).wait() |
| + elif sys.platform.startswith('darwin'): |
| + assert os.geteuid() == 0, 'Need superuser privileges' |
| + |
| + # Run most of the steps here with login user |
| + login_uid = os.getuid() |
| + os.seteuid(login_uid) |
| + |
| + # Change the working dir to the dir that has the host zip file |
| + current_dir = os.getcwd() |
| + bin_dir = sys.argv[2] |
| + os.chdir(bin_dir) |
| + |
| + # Remove remoting-me2me-host-mac dir just in case |
| + subprocess.call("rm -f -R remoting-me2me-host-mac", shell=True) |
| + |
| + # Unzip the host archive and prepare the files/dirs |
| + subprocess.call("unzip remoting-me2me-host-mac.zip", shell=True) |
| + subprocess.call("mkdir remoting-me2me-host-mac/output", shell=True) |
| + |
| + # Prepare security identity for code signing purpose |
| + os.seteuid(0) |
| + key_chain = "/Library/Keychains/ChromotingTest" |
| + password = "1111" |
| + chromoting_test_dir = current_dir + "/chrome/test/functional/chromoting" |
| + subprocess.call(["security", "delete-keychain", key_chain]) |
| + subprocess.call(["security", "create-keychain", "-p", password, key_chain]) |
| + subprocess.call(["security", "import", chromoting_test_dir + "/chromoting_key.p12", |
| + "-k", key_chain, "-P", password, "-A"]) |
| + subprocess.call(["security", "import", chromoting_test_dir + "/chromoting_cert.p12", |
| + "-k", key_chain, "-P", password]) |
| + os.seteuid(login_uid) |
| + |
| + # Sign the host |
| + subprocess.call("./remoting-me2me-host-mac/do_signing.sh remoting-me2me-host-mac/output remoting-me2me-host-mac " |
| + + key_chain + " \"Chromoting Test\"", shell=True) |
| + |
| + # Remove security identify |
| + os.seteuid(0) |
| + subprocess.call(["security", "delete-keychain", key_chain]) |
| + os.seteuid(login_uid) |
| + |
| + # Figure out the dmg name |
| + version = "" |
| + for file in os.listdir("remoting-me2me-host-mac/output"): |
| + if file.endswith(".dmg"): |
| + version = os.path.basename(file)[len("ChromotingHost-"):-4] |
| + |
| + # Mount before installation |
| + subprocess.call("hdiutil mount remoting-me2me-host-mac/output/ChromotingHost-" + version + ".dmg", shell=True) |
| + |
| + # Install host |
| + os.seteuid(0) |
| + subprocess.call(["/usr/sbin/installer", |
| + "-pkg", "/Volumes/Chromoting Host " + version + "/Chromoting Host.mpkg", |
| + "-target", "/"]) |
| + os.seteuid(login_uid) |
| + |
| + # Unmount after installation |
| + subprocess.call("hdiutil unmount \"/Volumes/Chromoting Host " + version + "\"", shell=True) |
| + |
| + # Clean up remoting-me2me-host-mac dir |
| + subprocess.call("rm -f -R remoting-me2me-host-mac", shell=True) |
| + |
| + # Resume the original working dir |
| + os.chdir(current_dir) |
| + else: |
| + print("Nothing to be done for install") |
| + elif sys.argv[1] == 'uninstall': |
| + if sys.platform.startswith('win'): |
| + host_msi = sys.argv[2] + "\\remoting-host.msi" |
| + subprocess.Popen(["msiexec", "/x", host_msi, "/passive"]).wait() |
| + elif sys.platform.startswith('darwin'): |
| + assert os.geteuid() == 0, 'Need superuser privileges' |
| + subprocess.call(["open", "-a", "/Applications/Chromoting Host Uninstaller.app"]) |
| + else: |
| + print("Nothing to be done for uninstall") |
| + elif sys.argv[1] == 'enable': |
| + if sys.platform.startswith('darwin'): |
| + assert os.geteuid() == 0, 'Need superuser privileges' |
| + replacePrefPane("mock_pref_pane_enable") |
| + else: |
| + print("Nothing to be done for enable") |
| + elif sys.argv[1] == 'disable': |
| + if sys.platform.startswith('darwin'): |
| + assert os.geteuid() == 0, 'Need superuser privileges' |
| + replacePrefPane("mock_pref_pane_disable") |
| + else: |
| + print("Nothing to be done for disable") |
| + elif sys.argv[1] == 'changepin': |
| + if sys.platform.startswith('darwin'): |
| + assert os.geteuid() == 0, 'Need superuser privileges' |
| + replacePrefPane("mock_pref_pane_changepin") |
| + else: |
| + print("Nothing to be done for changepin") |
| + else: |
| + print >>sys.stderr, ( |
| + 'Invalid syntax') |
| + return 1 |
| + return 0 |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main()) |