-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
F: 实现基于stevedore的插件实现,并将原expect方法移到hand包中
- Loading branch information
Showing
3 changed files
with
38 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from mohand.hand import HandDict | ||
|
||
hand = HandDict() | ||
# print('HandDict@mohand_plugin_expect:', hand) | ||
# print('HandDict@mohand_plugin_expect:', id(hand)) | ||
|
||
|
||
def expect(*dargs, **dkwargs): | ||
def wrapper(func): | ||
@hand._click.command( | ||
name=func.__name__.lower(), | ||
help=func.__doc__) | ||
@hand._click.option( | ||
'--cmd', | ||
default=dkwargs.get('cmd'), | ||
help='用于构造上下文环境的终端命令,将传入 pexpect.spawn') | ||
@hand._click.option( | ||
'--timeout', '-t', | ||
type=hand._click.INT, | ||
default=dkwargs.get('timeout'), | ||
help='expect 的超时时间') | ||
def _wrapper(*args, **kwargs): | ||
print("decrator param:", dargs, dkwargs) | ||
print("function param:", args, kwargs) | ||
kwargs.pop('cmd', None) | ||
kwargs.pop('timeout', None) | ||
return func(*args, **kwargs) | ||
return _wrapper | ||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,8 @@ | ||
import click | ||
from mohand import hand | ||
from mohand_plugin_expect.hand import expect | ||
|
||
from mohand.main import main | ||
from mohand.decrator import register | ||
|
||
|
||
@register | ||
def expect(*dargs, **dkwargs): | ||
def wrapper(func): | ||
@main.command( | ||
name=func.__name__.lower(), | ||
help=func.__doc__) | ||
@click.option( | ||
'--cmd', | ||
default=dkwargs.get('cmd'), | ||
help='用于构造上下文环境的终端命令,将传入 pexpect.spawn') | ||
@click.option( | ||
'--timeout', '-t', | ||
type=click.INT, | ||
default=dkwargs.get('timeout'), | ||
help='expect 的超时时间') | ||
def _wrapper(*args, **kwargs): | ||
print("decrator param:", dargs, dkwargs) | ||
print("function param:", args, kwargs) | ||
kwargs.pop('cmd', None) | ||
kwargs.pop('timeout', None) | ||
return func(*args, **kwargs) | ||
return _wrapper | ||
return wrapper | ||
class ExpectHand(hand.HandBase): | ||
def register(self): | ||
# print('ExpectHand:', expect) | ||
return expect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters