1#!/usr/bin/env python 2# -*- coding: utf-8 -*- 3 4# Copyright (c) 2020-2021 Huawei Device Co., Ltd. 5# 6# HDF is dual licensed: you can use it either under the terms of 7# the GPL, or the BSD license, at your option. 8# See the LICENSE file in the root of this repository for complete details. 9 10 11from hdf_tool_exception import HdfToolException 12from command_line.hdi_operate.hdi_add_handler import HdiAddHandler 13from command_line.hdi_operate.hdi_get_handler import HdiGetHandler 14from .hdf_add_handler import HdfAddHandler 15from .hdf_delete_handler import HdfDeleteHandler 16from .hdf_get_handler import HdfGetHandler 17from .hdf_set_handler import HdfSetHandler 18from .hdf_ping_handler import HdfPingHandler 19from .hdf_command_error_code import CommandErrorCode 20from .hdi_operate.hdi_delete_handler import HdiDeleteHandler 21 22 23class HdfToolCommands(object): 24 def __init__(self): 25 self.commands = { 26 'add': HdfAddHandler, 27 'delete': HdfDeleteHandler, 28 'get': HdfGetHandler, 29 'set': HdfSetHandler, 30 'ping': HdfPingHandler, 31 'addi': HdiAddHandler, 32 'geti': HdiGetHandler, 33 'deletei': HdiDeleteHandler, 34 } 35 36 def run(self, cmd, args): 37 if cmd in self.commands: 38 result = self.commands.get(cmd)(args).run() 39 return result 40 else: 41 raise HdfToolException('unknown cmd: "%s"' % cmd, 42 CommandErrorCode.INTERFACE_ERROR) 43 44 def help(self): 45 helps = ['command list:'] 46 for cmd in self.commands.keys(): 47 helps.append(cmd) 48 return ' '.join(helps) 49