From: Rishabh Dave Date: Thu, 26 Sep 2019 07:59:55 +0000 (+0530) Subject: cephfs-shell: make compatible with cmd2 versions after 0.9.13 X-Git-Tag: v15.1.0~1257^2~1 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=92cab709d62e1ae1bacaaddbf25c5d4639f88ce1;p=ceph-ci.git cephfs-shell: make compatible with cmd2 versions after 0.9.13 "load" command from cmd2 has been renamed to "run_script". Update the documentation for the same. Fixes: https://tracker.ceph.com/issues/42057 Signed-off-by: Rishabh Dave --- diff --git a/doc/cephfs/cephfs-shell.rst b/doc/cephfs/cephfs-shell.rst index 3825598fa49..de62abc13c7 100644 --- a/doc/cephfs/cephfs-shell.rst +++ b/doc/cephfs/cephfs-shell.rst @@ -328,18 +328,21 @@ Usage: * file_path - path to a file to open in editor -load ----- +run_script +---------- Runs commands in script file that is encoded as either ASCII or UTF-8 text. +Each command in the script should be separated by a newline. Usage: - load + run_script + * file_path - a file path pointing to a script -* Script should contain one command per line, just like command would betyped in console. +.. note:: This command is available as ``load`` for cmd2 versions 0.9.13 + or less. shell ----- diff --git a/src/tools/cephfs/cephfs-shell b/src/tools/cephfs/cephfs-shell index 7dd1fe17ad9..60bd7f5e1e4 100755 --- a/src/tools/cephfs/cephfs-shell +++ b/src/tools/cephfs/cephfs-shell @@ -5,7 +5,6 @@ import argparse import os import os.path import sys -from cmd2 import Cmd import cephfs as libcephfs import shutil import traceback @@ -16,6 +15,10 @@ import re import shlex import stat +from cmd2 import Cmd +from cmd2 import __version__ as cmd2_version +from distutils.version import LooseVersion + if sys.version_info.major < 3: raise RuntimeError("cephfs-shell is only compatible with python3") @@ -1332,7 +1335,10 @@ if __name__ == '__main__': if args.config: config_file = args.config if args.batch: - args.commands = ['load ' + args.batch, ',quit'] + if LooseVersion(cmd2_version) <= LooseVersion("0.9.13"): + args.commands = ['load ' + args.batch, ',quit'] + else: + args.commands = ['run_script ' + args.batch, ',quit'] if args.test: args.commands.extend(['-t,'] + [arg + ',' for arg in args.test]) sys.argv.clear()