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,142 @@ |
+# 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. |
+ |
Nirnimesh
2012/08/06 19:13:53
Docstring for this script please
yihongg
2012/08/08 01:04:48
Done.
|
+import os |
+import sys |
+import subprocess |
+ |
+ |
+def _ReplacePrefPane(operation): |
+ """Constructs mock pref pane to replace the actual pref pane.""" |
+ pref_pane_dir = os.path.join("/Library", "PreferencePanes") |
Nirnimesh
2012/08/06 19:13:53
This applies to Mac only. Clearly call out so.
yihongg
2012/08/08 01:04:48
Done.
|
+ |
+ mock_pref_pane = os.path.join(pref_pane_dir, "mock_pref_pane") |
+ pref_pane = os.path.join(pref_pane_dir, "org.chromium.chromoting.prefPane") |
+ mock_pref_pane_python = os.path.join(os.getcwd(), "chrome", "test", |
Nirnimesh
2012/08/06 19:13:53
chrome/test/pyautolib should not refer to chrome/t
yihongg
2012/08/08 01:04:48
This is to construct a bash script which contains
|
+ "functional", "chromoting", |
+ "mock_pref_pane.py") |
+ |
+ subprocess.call(["rm", "-rf", mock_pref_pane]) |
+ |
+ mock_pref_pane_file = open(mock_pref_pane, "w") |
+ mock_pref_pane_file.write("#!/bin/bash\n") |
+ mock_pref_pane_file.write("\n") |
+ mock_pref_pane_file.write("suid-python" + |
+ " " + mock_pref_pane_python + " " + operation) |
+ mock_pref_pane_file.close() |
+ |
+ subprocess.call(["chmod", "a+x", mock_pref_pane]) |
+ subprocess.call(["rm", "-rf", pref_pane]) |
+ subprocess.call(["ln", "-s", mock_pref_pane, pref_pane]) |
+ |
+ |
+def main(): |
Nirnimesh
2012/08/06 19:13:53
main() -> Main()
main is unusually long. Please r
yihongg
2012/08/08 01:04:48
Put the majority code in ChromotingHelper and used
|
+ """Chromoting helper script to install/uninstall/enable/disable host.""" |
Nirnimesh
2012/08/06 19:13:53
on all platforms?
yihongg
2012/08/08 01:04:48
Currently mainly mac and windows. install/uninstal
|
+ if sys.argv[1] == "install": |
Nirnimesh
2012/08/06 19:13:53
The flow is too difficult to follow. Please refer
yihongg
2012/08/08 01:04:48
Done.
|
+ if sys.platform.startswith("win"): |
+ host_msi = os.path.join(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) |
+ host_dir = "remoting-me2me-host-mac" |
+ output_dir = os.path.join(host_dir, "output") |
+ |
+ # Remove remoting-me2me-host-mac dir just in case |
+ subprocess.call("rm -f -R " + host_dir, shell=True) |
+ |
+ # Unzip the host archive and prepare the files/dirs |
+ subprocess.call("unzip remoting-me2me-host-mac.zip", shell=True) |
+ subprocess.call("mkdir " + output_dir, shell=True) |
+ |
+ # Prepare security identity for code signing purpose |
+ os.seteuid(0) |
+ key_chain = "/Library/Keychains/ChromotingTest" |
+ password = "1111" |
+ chromoting_test_dir = os.path.join(current_dir, "chrome", "test", |
+ "functional", "chromoting") |
+ key = os.path.join(chromoting_test_dir, "chromoting_key.p12") |
+ cert = os.path.join(chromoting_test_dir, "chromoting_cert.p12") |
+ subprocess.call(["security", "delete-keychain", key_chain]) |
+ subprocess.call(["security", "create-keychain", "-p", |
+ password, key_chain]) |
+ subprocess.call(["security", "import", key, |
+ "-k", key_chain, "-P", password, "-A"]) |
+ subprocess.call(["security", "import", cert, |
+ "-k", key_chain, "-P", password]) |
+ os.seteuid(login_uid) |
+ |
+ # Sign the host |
+ do_signing = os.path.join(host_dir, "do_signing.sh") |
+ subprocess.call(do_signing + " " + output_dir + " " + host_dir + " " + |
+ 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 output_file in os.listdir(output_dir): |
+ if output_file.endswith(".dmg"): |
+ version = os.path.basename(output_file)[len("ChromotingHost-"):-4] |
+ |
+ # Mount before installation |
+ dmg = os.path.join(output_dir, "ChromotingHost-" + version + ".dmg") |
+ subprocess.call("hdiutil" + " mount " + dmg, shell=True) |
+ |
+ # Install host |
+ os.seteuid(0) |
+ mpkg = os.path.join("/Volumes", "Chromoting Host " + version, |
+ "Chromoting Host.mpkg") |
+ subprocess.call(["/usr/sbin/installer", "-pkg", |
+ mpkg, "-target", "/"]) |
+ os.seteuid(login_uid) |
+ |
+ # Unmount after installation |
+ mounted = os.path.join("/Volumes", "Chromoting Host " + version) |
+ subprocess.call("hdiutil unmount \"" + mounted + "\"", shell=True) |
+ |
+ # Clean up remoting-me2me-host-mac dir |
+ subprocess.call("rm -f -R " + host_dir, 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 = os.path.join(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' |
+ uninstall_app = os.path.join("/", "Applications", |
+ "Chromoting Host Uninstaller.app") |
+ subprocess.call(["open", "-a", uninstall_app]) |
+ else: |
+ print("Nothing to be done for uninstall") |
+ elif sys.argv[1] in ["enable", "disable", "changepin"]: |
+ if sys.platform.startswith("darwin"): |
+ assert os.geteuid() == 0, 'Need superuser privileges' |
+ _ReplacePrefPane(sys.argv[1]) |
+ else: |
+ print("Nothing to be done for enable") |
Nirnimesh
2012/08/06 19:13:53
remove parens
use ' instead of " throughout this f
yihongg
2012/08/08 01:04:48
Done.
|
+ else: |
+ print >> sys.stderr, ( |
Nirnimesh
2012/08/06 19:13:53
remove space after >>
Nirnimesh
2012/08/06 19:13:53
remove parens
yihongg
2012/08/08 01:04:48
Done.
yihongg
2012/08/08 01:04:48
Done.
yihongg
2012/08/08 01:04:48
Done.
yihongg
2012/08/08 01:04:48
Done.
yihongg
2012/08/08 01:04:48
Done.
|
+ "Invalid syntax") |
Nirnimesh
2012/08/06 19:13:53
move to previous line
yihongg
2012/08/08 01:04:48
Done.
|
+ return 1 |
+ return 0 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |