Zhizhou Yang | 81d651f | 2020-02-10 16:51:20 -0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 3 | # |
Zhizhou Yang | 81d651f | 2020-02-10 16:51:20 -0800 | [diff] [blame] | 4 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 5 | # Use of this source code is governed by a BSD-style license that can be |
| 6 | # found in the LICENSE file. |
| 7 | |
cmtice | d96e457 | 2015-05-19 16:19:25 -0700 | [diff] [blame] | 8 | """Script to wrap test_that script. |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 9 | |
| 10 | This script can login to the chromeos machine using the test private key. |
| 11 | """ |
| 12 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 13 | from __future__ import print_function |
| 14 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 15 | __author__ = 'asharif@google.com (Ahmad Sharif)' |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 16 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 17 | import argparse |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 18 | import os |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 19 | import sys |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 20 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 21 | from cros_utils import command_executer |
| 22 | from cros_utils import misc |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 23 | |
| 24 | |
| 25 | def Usage(parser, message): |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 26 | print('ERROR: %s' % message) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 27 | parser.print_help() |
| 28 | sys.exit(0) |
| 29 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 30 | |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 31 | def Main(argv): |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 32 | parser = argparse.ArgumentParser() |
Caroline Tice | f6ef439 | 2017-04-06 17:16:05 -0700 | [diff] [blame] | 33 | parser.add_argument( |
| 34 | '-c', |
| 35 | '--chromeos_root', |
| 36 | dest='chromeos_root', |
| 37 | help='ChromeOS root checkout directory') |
| 38 | parser.add_argument( |
| 39 | '-r', '--remote', dest='remote', help='Remote chromeos device.') |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 40 | options = parser.parse_args(argv) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 41 | if options.chromeos_root is None: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 42 | Usage(parser, 'chromeos_root must be given') |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 43 | |
| 44 | if options.remote is None: |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 45 | Usage(parser, 'remote must be given') |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 46 | |
| 47 | options.chromeos_root = os.path.expanduser(options.chromeos_root) |
| 48 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 49 | command = 'ls -lt /' |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 50 | ce = command_executer.GetCommandExecuter() |
Caroline Tice | f6ef439 | 2017-04-06 17:16:05 -0700 | [diff] [blame] | 51 | ce.CrosRunCommand( |
| 52 | command, chromeos_root=options.chromeos_root, machine=options.remote) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 53 | |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 54 | version_dir_path, script_name = misc.GetRoot(sys.argv[0]) |
| 55 | version_dir = misc.GetRoot(version_dir_path)[1] |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 56 | |
| 57 | # Tests to copy directories and files to the chromeos box. |
Caroline Tice | f6ef439 | 2017-04-06 17:16:05 -0700 | [diff] [blame] | 58 | ce.CopyFiles( |
| 59 | version_dir_path, |
| 60 | '/tmp/' + version_dir, |
| 61 | dest_machine=options.remote, |
| 62 | dest_cros=True, |
| 63 | chromeos_root=options.chromeos_root) |
| 64 | ce.CopyFiles( |
| 65 | version_dir_path, |
| 66 | '/tmp/' + version_dir + '1', |
| 67 | dest_machine=options.remote, |
| 68 | dest_cros=True, |
| 69 | chromeos_root=options.chromeos_root) |
| 70 | ce.CopyFiles( |
| 71 | sys.argv[0], |
| 72 | '/tmp/' + script_name, |
| 73 | recursive=False, |
| 74 | dest_machine=options.remote, |
| 75 | dest_cros=True, |
| 76 | chromeos_root=options.chromeos_root) |
| 77 | ce.CopyFiles( |
| 78 | sys.argv[0], |
| 79 | '/tmp/' + script_name + '1', |
| 80 | recursive=False, |
| 81 | dest_machine=options.remote, |
| 82 | dest_cros=True, |
| 83 | chromeos_root=options.chromeos_root) |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 84 | |
| 85 | # Test to copy directories and files from the chromeos box. |
Caroline Tice | f6ef439 | 2017-04-06 17:16:05 -0700 | [diff] [blame] | 86 | ce.CopyFiles( |
| 87 | '/tmp/' + script_name, |
| 88 | '/tmp/hello', |
| 89 | recursive=False, |
| 90 | src_machine=options.remote, |
| 91 | src_cros=True, |
| 92 | chromeos_root=options.chromeos_root) |
| 93 | ce.CopyFiles( |
| 94 | '/tmp/' + script_name, |
| 95 | '/tmp/' + script_name, |
| 96 | recursive=False, |
| 97 | src_machine=options.remote, |
| 98 | src_cros=True, |
| 99 | chromeos_root=options.chromeos_root) |
asharif | 6f4065c | 2013-02-15 09:04:02 +0000 | [diff] [blame] | 100 | board = ce.CrosLearnBoard(options.chromeos_root, options.remote) |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 101 | print(board) |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 102 | return 0 |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 103 | |
| 104 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 105 | if __name__ == '__main__': |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 106 | Main(sys.argv[1:]) |