1# 2# Copyright 2016 - The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16import logging 17 18from vts.utils.python.common import cmd_utils 19 20 21class CloudClientController(object): 22 '''Controller class to interact with TradeFed. 23 24 Attributes: 25 path_cmdfile: string, path to TradeFed cmdfile 26 ''' 27 DEFAULT_PATH_CMDFILE = 'cmdfile.txt' 28 29 def __init__(self, path_cmdfile=None): 30 if not path_cmdfile: 31 path_cmdfile = self.DEFAULT_PATH_CMDFILE 32 self._path_cmdfile = path_cmdfile 33 34 def ExecuteTfCommands(self, cmds): 35 '''Execute a TradeFed command or a list of TradeFed commands. 36 37 Args: 38 cmds: string or list of string, commands 39 ''' 40 if not isinstance(cmds, list): 41 cmds = [cmds] 42 43 cmd = '\n'.join(cmds) 44 45 with open(self._path_cmdfile, 'w') as f: 46 f.write(cmd)