1# 2# Copyright (C) 2018 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# 16 17import logging 18 19from host_controller.command_processor import base_command_processor 20 21 22class CommandExit(base_command_processor.BaseCommandProcessor): 23 """Command processor for exit command. 24 25 Attributes: 26 arg_parser: ConsoleArgumentParser object, argument parser. 27 console: cmd.Cmd console object. 28 command: string, command name which this processor will handle. 29 command_detail: string, detailed explanation for the command. 30 """ 31 32 command = "exit" 33 command_detail = "" 34 35 # @Override 36 def SetUp(self): 37 """Initializes the parser for request command.""" 38 self.arg_parser.add_argument( 39 "--wait_for_jobs", 40 default=True, 41 help="True to wait for the running jobs to complete before exiting." 42 ) 43 44 # @Override 45 def Run(self, arg_line): 46 """Terminates the console. 47 48 Returns: 49 True, which stops the cmdloop. 50 """ 51 args = self.arg_parser.ParseLine(arg_line) 52 53 self.console.onecmd("device --update stop") 54 55 if args.wait_for_jobs: 56 if (type(args.wait_for_jobs) != str or 57 args.wait_for_jobs.lower() == "true"): 58 logging.info("waiting for running jobs to complete...") 59 self.console.WaitForJobsToExit() 60 61 self.console.StopJobThreadAndProcessPool() 62 self.console.__exit__() 63 return True 64