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