1# coding: utf-8 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14from __future__ import unicode_literals 15 16 17class Module(object): 18 _host = None 19 20 @classmethod 21 def get_module(cls, _host): 22 klass = cls.get_module_class(_host) 23 return type(klass.__name__, (klass,), { 24 "_host": _host, 25 "run": _host.run, 26 "run_expect": _host.run_expect, 27 "run_test": _host.run_test, 28 "check_output": _host.check_output, 29 "find_command": _host.find_command, 30 }) 31 32 @classmethod 33 def get_module_class(cls, host): 34 return cls 35 36 37class InstanceModule(Module): 38 39 @classmethod 40 def get_module(cls, _host): 41 klass = super(InstanceModule, cls).get_module(_host) 42 return klass() 43