]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephfs-shell: check version before importing Cmd2ArgparseError
authorRishabh Dave <ridave@redhat.com>
Thu, 19 May 2022 15:33:54 +0000 (21:03 +0530)
committerRishabh Dave <ridave@redhat.com>
Thu, 19 May 2022 15:33:54 +0000 (21:03 +0530)
Cmd2ArgparseError is available only cmd2 version 1.0.1 onwards. Before
that, SystemExit(2) is raised. This commit creates an empty class
Cmd2ArgparseError for earlier version so that similar error won't creep
up again.

Fixes: https://tracker.ceph.com/issues/55716
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/tools/cephfs/cephfs-shell

index 7b8597a457b4806dc8cec0ff7a99938167047d04..ca50588b01db1a085ab9d1028fedeb69d472db43 100755 (executable)
@@ -16,10 +16,19 @@ import shlex
 import stat
 import errno
 
+from distutils.version import LooseVersion
+
 from cmd2 import Cmd
 from cmd2 import __version__ as cmd2_version
-from cmd2.exceptions import Cmd2ArgparseError
-from distutils.version import LooseVersion
+# XXX: In cmd2 versions < 1.0.1, we'll get SystemExit(2) instead of
+# Cmd2ArgparseError
+if LooseVersion(cmd2_version) >= LooseVersion("1.0.1"):
+    from cmd2.exceptions import Cmd2ArgparseError
+else:
+    # HACK: so that we don't have check for version everywhere
+    # Cmd2ArgparseError is used.
+    class Cmd2ArgparseError:
+        pass
 
 if sys.version_info.major < 3:
     raise RuntimeError("cephfs-shell is only compatible with python3")
@@ -476,6 +485,10 @@ class CephFSShell(Cmd):
                 set_exit_code_msg(msg=None)
             else:
                 set_exit_code_msg(msg=f'{type(e).__name__}: {e}')
+        # In cmd2 versions < 1.1.0 we'll get SystemExit(2) instead of
+        # Cmd2ArgparseError
+        except SystemExit:
+            raise
 
     class path_to_bytes(argparse.Action):
         def __call__(self, parser, namespace, values, option_string=None):