1#!/usr/bin/env 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(
30      '-c',
31      '--chromeos_root',
32      dest='chromeos_root',
33      help='ChromeOS root checkout directory')
34  parser.add_argument(
35      '-r', '--remote', dest='remote', help='Remote chromeos device.')
36  options = parser.parse_args(argv)
37  if options.chromeos_root is None:
38    Usage(parser, 'chromeos_root must be given')
39
40  if options.remote is None:
41    Usage(parser, 'remote must be given')
42
43  options.chromeos_root = os.path.expanduser(options.chromeos_root)
44
45  command = 'ls -lt /'
46  ce = command_executer.GetCommandExecuter()
47  ce.CrosRunCommand(
48      command, chromeos_root=options.chromeos_root, machine=options.remote)
49
50  version_dir_path, script_name = misc.GetRoot(sys.argv[0])
51  version_dir = misc.GetRoot(version_dir_path)[1]
52
53  # Tests to copy directories and files to the chromeos box.
54  ce.CopyFiles(
55      version_dir_path,
56      '/tmp/' + version_dir,
57      dest_machine=options.remote,
58      dest_cros=True,
59      chromeos_root=options.chromeos_root)
60  ce.CopyFiles(
61      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(
67      sys.argv[0],
68      '/tmp/' + script_name,
69      recursive=False,
70      dest_machine=options.remote,
71      dest_cros=True,
72      chromeos_root=options.chromeos_root)
73  ce.CopyFiles(
74      sys.argv[0],
75      '/tmp/' + script_name + '1',
76      recursive=False,
77      dest_machine=options.remote,
78      dest_cros=True,
79      chromeos_root=options.chromeos_root)
80
81  # Test to copy directories and files from the chromeos box.
82  ce.CopyFiles(
83      '/tmp/' + script_name,
84      '/tmp/hello',
85      recursive=False,
86      src_machine=options.remote,
87      src_cros=True,
88      chromeos_root=options.chromeos_root)
89  ce.CopyFiles(
90      '/tmp/' + script_name,
91      '/tmp/' + script_name,
92      recursive=False,
93      src_machine=options.remote,
94      src_cros=True,
95      chromeos_root=options.chromeos_root)
96  board = ce.CrosLearnBoard(options.chromeos_root, options.remote)
97  print(board)
98  return 0
99
100
101if __name__ == '__main__':
102  Main(sys.argv[1:])
103