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 | # |
Mike Frysinger | fdcd39d | 2022-09-13 14:19:58 -0400 | [diff] [blame] | 4 | # Copyright 2020 The ChromiumOS Authors |
Zhizhou Yang | 81d651f | 2020-02-10 16:51:20 -0800 | [diff] [blame] | 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 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 13 | |
| 14 | __author__ = "asharif@google.com (Ahmad Sharif)" |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 15 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 16 | import argparse |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 17 | import os |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 18 | import sys |
kbaclawski | 20082a0 | 2013-02-16 02:12:57 +0000 | [diff] [blame] | 19 | |
Caroline Tice | 88272d4 | 2016-01-13 09:48:29 -0800 | [diff] [blame] | 20 | from cros_utils import command_executer |
| 21 | from cros_utils import misc |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 22 | |
| 23 | |
| 24 | def Usage(parser, message): |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 25 | print("ERROR: %s" % message) |
| 26 | parser.print_help() |
| 27 | sys.exit(0) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 28 | |
Luis Lozano | f2a3ef4 | 2015-12-15 13:49:30 -0800 | [diff] [blame] | 29 | |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 30 | def Main(argv): |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 31 | parser = argparse.ArgumentParser() |
| 32 | parser.add_argument( |
| 33 | "-c", |
| 34 | "--chromeos_root", |
| 35 | dest="chromeos_root", |
| 36 | help="ChromeOS root checkout directory", |
| 37 | ) |
| 38 | parser.add_argument( |
| 39 | "-r", "--remote", dest="remote", help="Remote chromeos device." |
| 40 | ) |
| 41 | options = parser.parse_args(argv) |
| 42 | if options.chromeos_root is None: |
| 43 | Usage(parser, "chromeos_root must be given") |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 44 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 45 | if options.remote is None: |
| 46 | Usage(parser, "remote must be given") |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 47 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 48 | options.chromeos_root = os.path.expanduser(options.chromeos_root) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 49 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 50 | command = "ls -lt /" |
| 51 | ce = command_executer.GetCommandExecuter() |
| 52 | ce.CrosRunCommand( |
| 53 | command, chromeos_root=options.chromeos_root, machine=options.remote |
| 54 | ) |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 55 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 56 | version_dir_path, script_name = misc.GetRoot(sys.argv[0]) |
| 57 | version_dir = misc.GetRoot(version_dir_path)[1] |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 58 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 59 | # Tests to copy directories and files to the chromeos box. |
| 60 | ce.CopyFiles( |
| 61 | version_dir_path, |
| 62 | "/tmp/" + version_dir, |
| 63 | dest_machine=options.remote, |
| 64 | dest_cros=True, |
| 65 | chromeos_root=options.chromeos_root, |
| 66 | ) |
| 67 | ce.CopyFiles( |
| 68 | version_dir_path, |
| 69 | "/tmp/" + version_dir + "1", |
| 70 | dest_machine=options.remote, |
| 71 | dest_cros=True, |
| 72 | chromeos_root=options.chromeos_root, |
| 73 | ) |
| 74 | ce.CopyFiles( |
| 75 | sys.argv[0], |
| 76 | "/tmp/" + script_name, |
| 77 | recursive=False, |
| 78 | dest_machine=options.remote, |
| 79 | dest_cros=True, |
| 80 | chromeos_root=options.chromeos_root, |
| 81 | ) |
| 82 | ce.CopyFiles( |
| 83 | sys.argv[0], |
| 84 | "/tmp/" + script_name + "1", |
| 85 | recursive=False, |
| 86 | dest_machine=options.remote, |
| 87 | dest_cros=True, |
| 88 | chromeos_root=options.chromeos_root, |
| 89 | ) |
asharif | 29775b2 | 2013-02-15 05:15:38 +0000 | [diff] [blame] | 90 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 91 | # Test to copy directories and files from the chromeos box. |
| 92 | ce.CopyFiles( |
| 93 | "/tmp/" + script_name, |
| 94 | "/tmp/hello", |
| 95 | recursive=False, |
| 96 | src_machine=options.remote, |
| 97 | src_cros=True, |
| 98 | chromeos_root=options.chromeos_root, |
| 99 | ) |
| 100 | ce.CopyFiles( |
| 101 | "/tmp/" + script_name, |
| 102 | "/tmp/" + script_name, |
| 103 | recursive=False, |
| 104 | src_machine=options.remote, |
| 105 | src_cros=True, |
| 106 | chromeos_root=options.chromeos_root, |
| 107 | ) |
| 108 | board = ce.CrosLearnBoard(options.chromeos_root, options.remote) |
| 109 | print(board) |
| 110 | return 0 |
asharif | bb91850 | 2013-02-15 05:15:01 +0000 | [diff] [blame] | 111 | |
| 112 | |
George Burgess IV | 74bd380 | 2022-09-02 16:59:27 -0700 | [diff] [blame] | 113 | if __name__ == "__main__": |
| 114 | Main(sys.argv[1:]) |