1#!/usr/bin/env python3 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2024 Huawei Device Co., Ltd. 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18from abc import ABC, abstractmethod 19from vmb.shell import ShellBase, ShellUnix, ShellDevice 20from vmb.target import Target 21 22 23class CrossShell(ABC): 24 @property 25 @abstractmethod 26 def sh(self) -> ShellUnix: 27 pass 28 29 @property 30 @abstractmethod 31 def andb(self) -> ShellDevice: 32 pass 33 34 @property 35 @abstractmethod 36 def hdc(self) -> ShellDevice: 37 pass 38 39 @property 40 @abstractmethod 41 def target(self) -> Target: 42 pass 43 44 @property 45 def x_sh(self) -> ShellBase: 46 """Dispatch command to a propre shell.""" 47 if Target.HOST == self.target: 48 return self.sh 49 if Target.DEVICE == self.target: 50 return self.andb 51 if Target.OHOS == self.target: 52 return self.hdc 53 raise NotImplementedError(f'No shell for {self.target}!') 54