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