From 87bd27537a3be5e98dcca7dc14147bcbd8f17d09 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sat, 12 Oct 2019 13:33:21 +0800 Subject: [PATCH] 1 --- scripts/cdb/cdb.py | 6 +----- scripts/cdb/cmd.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/scripts/cdb/cdb.py b/scripts/cdb/cdb.py index b5cd381..ddefe19 100644 --- a/scripts/cdb/cdb.py +++ b/scripts/cdb/cdb.py @@ -26,8 +26,4 @@ initTab(tab) tab.call_method("Page.navigate", url="http://localhost:7456/", _timeout=5) while True: - cmdline= input('').strip() - try: - msg = eval(cmdline) - except Exception as e: - print(e) + cmd.processCmd(browser, tab, scriptmgr) diff --git a/scripts/cdb/cmd.py b/scripts/cdb/cmd.py index e69de29..925578b 100644 --- a/scripts/cdb/cmd.py +++ b/scripts/cdb/cmd.py @@ -0,0 +1,31 @@ + +def _b_cmd(browser, tab, scriptmgr, params): + pass + +def _p_cmd(browser, tab, scriptmgr, params): + pass + +def _processCdbCmd(cmd_str, browser, tab, scriptmgr): + cmdlist = cmd_str.split(' ') + if len(cmdlist) < 1: + return + cmd_hash = { + 'b': _b_cmd, + 'p': None, + } + if cmdlist[0] in cmd_hash: + cmd_hash[cmdlist[0]](browser, tab, scriptmgr, cmdlist[1:]) + else: + print('not found %s cmd' % cmdlist[0]) + +def processCmd(browser, tab, scriptmgr): + cmdline= input('').strip() + try: + if len(cmdline) > 0 : + if cmdline[0] == '!': + msg = eval(cmdline[1:]) + else: + _processCdbCmd(cmdline[1:], browser, tab, scriptmgr) + except Exception as e: + print(e) +