diff options
author | Luis Lozano <llozano@chromium.org> | 2013-03-15 14:44:13 -0700 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-03-15 15:51:37 -0700 |
commit | f81680c018729fd4499e1e200d04b48c4b90127c (patch) | |
tree | 940608da8374604b82edfdb2d7df55d065f05d4c /cros_login.py | |
parent | 2296ee0b914aba5bba07becab4ff68884ce9b8a5 (diff) | |
download | toolchain-utils-f81680c018729fd4499e1e200d04b48c4b90127c.tar.gz |
Cleaned up directory after copy of tools from perforce directory
Got rid of stale copies of some tools like "crosperf" and moved all
files under v14 directory (that came from perforce) into the top
directory.
BUG=None
TEST=None
Change-Id: I408d17a36ceb00e74db71403d2351fd466a14f8e
Reviewed-on: https://gerrit-int.chromium.org/33887
Tested-by: Luis Lozano <llozano@chromium.org>
Reviewed-by: Yunlian Jiang <yunlian@google.com>
Commit-Queue: Luis Lozano <llozano@chromium.org>
Diffstat (limited to 'cros_login.py')
-rwxr-xr-x | cros_login.py | 128 |
1 files changed, 128 insertions, 0 deletions
diff --git a/cros_login.py b/cros_login.py new file mode 100755 index 00000000..44b22643 --- /dev/null +++ b/cros_login.py @@ -0,0 +1,128 @@ +#!/usr/bin/python2.6 +# +# Copyright 2010 Google Inc. All Rights Reserved. + +"""Script to get past the login screen of ChromeOS. + +""" + +__author__ = "asharif@google.com (Ahmad Sharif)" + +import datetime +import fcntl +import getpass +import glob +import optparse +import os +import pickle +import socket +import sys +import time +import tempfile +from utils import logger +from utils import command_executer + +LOGIN_PROMPT_VISIBLE_MAGIC_FILE = '/tmp/uptime-login-prompt-visible' +LOGGED_IN_MAGIC_FILE = '/var/run/state/logged-in' + + +script_header=""" +import os +import autox +import time +""" + +wait_for_login_screen=""" + +while True: + print 'Waiting for login screen to appear...' + if os.path.isfile('%s'): + break + time.sleep(1) + print 'Done' + +time.sleep(20) +""" % LOGIN_PROMPT_VISIBLE_MAGIC_FILE + + +do_login=""" +xauth_filename = '/home/chronos/.Xauthority' +os.environ.setdefault('XAUTHORITY', xauth_filename) +os.environ.setdefault('DISPLAY', ':0.0') + +print 'Now sending the hotkeys for logging in.' +ax = autox.AutoX() +# navigate to login screen +ax.send_hotkey('Ctrl+Shift+q') +ax.send_hotkey('Ctrl+Alt+l') +# escape out of any login screen menus (e.g., the network select menu) +time.sleep(2) +ax.send_hotkey('Escape') +time.sleep(2) +ax.send_hotkey('Tab') +time.sleep(0.5) +ax.send_hotkey('Tab') +time.sleep(0.5) +ax.send_hotkey('Tab') +time.sleep(0.5) +ax.send_hotkey('Tab') +time.sleep(0.5) +ax.send_hotkey('Return') +print 'Waiting for Chrome to appear...' +while True: + if os.path.isfile('%s'): + break + time.sleep(1) +print 'Done' +""" % LOGGED_IN_MAGIC_FILE + +def RestartUI(remote, chromeos_root, login=True): + chromeos_root = os.path.expanduser(chromeos_root) + ce = command_executer.GetCommandExecuter() + # First, restart ui. + command = 'rm -rf %s && restart ui' % LOGIN_PROMPT_VISIBLE_MAGIC_FILE + ce.CrosRunCommand(command, machine=remote, + chromeos_root=chromeos_root) + host_login_script = tempfile.mktemp() + device_login_script = '/tmp/login.py' + login_script_list = [script_header, wait_for_login_screen] + if login: + login_script_list.append(do_login) + + full_login_script_contents = "\n".join(login_script_list) + + with open(host_login_script, 'w') as f: + f.write(full_login_script_contents) + ce.CopyFiles(host_login_script, + device_login_script, + dest_machine=remote, + chromeos_root=chromeos_root, + recursive=False, + dest_cros=True) + ret = ce.CrosRunCommand('python %s' % device_login_script, + chromeos_root=chromeos_root, + machine=remote) + if os.path.exists(host_login_script): + os.remove(host_login_script) + return ret + + +def Main(argv): + """The main function.""" + parser = optparse.OptionParser() + parser.add_option('-r', + '--remote', + dest='remote', + help='The remote ChromeOS box.') + parser.add_option('-c', + '--chromeos_root', + dest='chromeos_root', + help='The ChromeOS root.') + + options, args = parser.parse_args(argv) + + return RestartUI(options.remote, options.chromeos_root) + +if __name__ == '__main__': + retval = Main(sys.argv) + sys.exit(retval) |