Mike Frysinger | c7f1593 | 2013-03-20 13:43:35 -0400 | [diff] [blame] | 1 | #!/usr/bin/python |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 2 | # |
| 3 | # Copyright 2010 Google Inc. All Rights Reserved. |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 4 | """Script to wrap test_that script. |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 5 | |
| 6 | This script can login to the chromeos machine using the test private key. |
| 7 | """ |
| 8 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 9 | __author__ = 'asharif@google.com (Ahmad Sharif)' |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 10 | |
| 11 | import optparse |
| 12 | import os |
| 13 | import re |
| 14 | import sys |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 15 | |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 16 | from utils import command_executer |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 17 | from utils import misc |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 18 | |
| 19 | |
| 20 | def Usage(parser, message): |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 21 | print 'ERROR: ' + message |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 22 | parser.print_help() |
| 23 | sys.exit(0) |
| 24 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 25 | |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 26 | def Main(argv): |
| 27 | parser = optparse.OptionParser() |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 28 | parser.add_option('-c', |
| 29 | '--chromeos_root', |
| 30 | dest='chromeos_root', |
| 31 | help='ChromeOS root checkout directory') |
| 32 | parser.add_option('-r', |
| 33 | '--remote', |
| 34 | dest='remote', |
| 35 | help='Remote chromeos device.') |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 36 | options = parser.parse_args(argv)[0] |
| 37 | if options.chromeos_root is None: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 38 | Usage(parser, 'chromeos_root must be given') |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 39 | |
| 40 | if options.remote is None: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 41 | Usage(parser, 'remote must be given') |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 42 | |
| 43 | options.chromeos_root = os.path.expanduser(options.chromeos_root) |
| 44 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 45 | command = 'ls -lt /' |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 46 | ce = command_executer.GetCommandExecuter() |
| 47 | ce.CrosRunCommand(command, |
| 48 | chromeos_root=options.chromeos_root, |
| 49 | machine=options.remote) |
| 50 | |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 51 | version_dir_path, script_name = misc.GetRoot(sys.argv[0]) |
| 52 | version_dir = misc.GetRoot(version_dir_path)[1] |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 53 | |
| 54 | # Tests to copy directories and files to the chromeos box. |
| 55 | ce.CopyFiles(version_dir_path, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 56 | '/tmp/' + version_dir, |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 57 | dest_machine=options.remote, |
| 58 | dest_cros=True, |
| 59 | chromeos_root=options.chromeos_root) |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 60 | ce.CopyFiles(version_dir_path, |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 61 | '/tmp/' + version_dir + '1', |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 62 | dest_machine=options.remote, |
| 63 | dest_cros=True, |
| 64 | chromeos_root=options.chromeos_root) |
| 65 | ce.CopyFiles(sys.argv[0], |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 66 | '/tmp/' + script_name, |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 67 | recursive=False, |
| 68 | dest_machine=options.remote, |
| 69 | dest_cros=True, |
| 70 | chromeos_root=options.chromeos_root) |
| 71 | ce.CopyFiles(sys.argv[0], |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 72 | '/tmp/' + script_name + '1', |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 73 | recursive=False, |
| 74 | dest_machine=options.remote, |
| 75 | dest_cros=True, |
| 76 | chromeos_root=options.chromeos_root) |
| 77 | |
| 78 | # Test to copy directories and files from the chromeos box. |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 79 | ce.CopyFiles('/tmp/' + script_name, |
| 80 | '/tmp/hello', |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 81 | recursive=False, |
| 82 | src_machine=options.remote, |
| 83 | src_cros=True, |
| 84 | chromeos_root=options.chromeos_root) |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 85 | ce.CopyFiles('/tmp/' + script_name, |
| 86 | '/tmp/' + script_name, |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 87 | recursive=False, |
| 88 | src_machine=options.remote, |
| 89 | src_cros=True, |
| 90 | chromeos_root=options.chromeos_root) |
asharif | 6f4065c | 2013-02-15 09:04:02 +0000 | [diff] [blame] | 91 | board = ce.CrosLearnBoard(options.chromeos_root, options.remote) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 92 | print board |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 93 | return 0 |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 94 | |
| 95 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame^] | 96 | if __name__ == '__main__': |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 97 | Main(sys.argv) |