numam-spdk/scripts/spdkcli.py
James Bergsten 0c93fc7330 scripts:Fix Python errors in checking scripts
Python3 (3.6.7) gives W605 errors in regular expressions, causing the
SPDK style checks to fail on the Python scripts doing the style checking.

This fix allows these Python scripts to run without errors.

This is a known issue - see https://github.com/PyCQA/pycodestyle/issues/814

Change-Id: I71cdff5d6c89e19b200c989f3d9da35bb4f7189d
Signed-off-by: James Bergsten <jamesx.bergsten@intel.com>
Reviewed-on: https://review.gerrithub.io/c/443955
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Reviewed-by: Karol Latecki <karol.latecki@intel.com>
Reviewed-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
2019-02-12 18:37:09 +00:00

70 lines
2.4 KiB
Python
Executable File

#!/usr/bin/env python3
import sys
import argparse
import configshell_fb
from os import getuid
from configshell_fb import ConfigShell, shell, ExecutionError
from spdkcli import UIRoot
from pyparsing import (alphanums, Optional, Suppress, Word, Regex,
removeQuotes, dblQuotedString, OneOrMore)
def add_quotes_to_shell(spdk_shell):
command = shell.locatedExpr(Word(alphanums + '_'))('command')
value = dblQuotedString.addParseAction(removeQuotes)
value_word = Word(alphanums + r';,=_\+/.<>()~@:-%[]')
keyword = Word(alphanums + r'_\-')
kparam = shell.locatedExpr(keyword + Suppress('=') +
Optional(value | value_word, default=''))('kparams*')
pparam = shell.locatedExpr(value | value_word)('pparams*')
parameters = OneOrMore(kparam | pparam)
bookmark = Regex(r'@([A-Za-z0-9:_.]|-)+')
pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') \
| '..' | '.'
path = shell.locatedExpr(bookmark | pathstd | '*')('path')
spdk_shell._parser = Optional(path) + Optional(command) + Optional(parameters)
def main():
"""
Start SPDK CLI
:return:
"""
spdk_shell = ConfigShell("~/.scripts")
add_quotes_to_shell(spdk_shell)
parser = argparse.ArgumentParser(description="SPDK command line interface")
parser.add_argument("-s", dest="socket", help="RPC socket path", default="/var/tmp/spdk.sock")
parser.add_argument("-v", dest="verbose", help="Print request/response JSON for configuration calls",
default=False, action="store_true")
parser.add_argument("commands", metavar="command", type=str, nargs="*", default="",
help="commands to execute by SPDKCli as one-line command")
args = parser.parse_args()
root_node = UIRoot(args.socket, spdk_shell)
root_node.verbose = args.verbose
try:
root_node.refresh()
except BaseException:
pass
if len(args.commands) > 0:
try:
spdk_shell.run_cmdline(" ".join(args.commands))
except Exception as e:
sys.stderr.write("%s\n" % e)
sys.exit(1)
sys.exit(0)
spdk_shell.con.display("SPDK CLI v0.1")
spdk_shell.con.display("")
while not spdk_shell._exit:
try:
spdk_shell.run_interactive()
except ExecutionError as e:
spdk_shell.log.error("%s" % e)
if __name__ == "__main__":
main()