From 961b803ec4b04e83fdec54b03c9d3345de17c3d0 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Thu, 27 Apr 2023 17:30:22 +0200 Subject: [PATCH] pySim-shell: fix compatibility problem with cmd2 >= 2.3.0 (bg) cmd2.fg and cmd2.bg have been deprecated in cmd2 2.3.0 and removed in cmd2 2.4.0. Let's work around this by a version check. Related upstream commits: (See also: https://github.com/python-cmd2/cmd2) Commit f57b08672af97f9d973148b6c30d74fe4e712d14 Author: Kevin Van Brunt Date: Mon Oct 11 15:20:46 2021 -0400 and Commit f217861feae45a0a1abb56436e68c5dd859d64c0 Author: Kevin Van Brunt Date: Wed Feb 16 13:34:13 2022 -0500 Change-Id: I9fd32c0fd8f6d40e00a318602af97c288605e8e5 --- pySim-shell.py | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/pySim-shell.py b/pySim-shell.py index ae783c64..51cd9c6f 100755 --- a/pySim-shell.py +++ b/pySim-shell.py @@ -24,7 +24,18 @@ import traceback import cmd2 from packaging import version -from cmd2 import style, fg +from cmd2 import style +# cmd2 >= 2.3.0 has deprecated the bg/fg in favor of Bg/Fg :( +if version.parse(cmd2.__version__) < version.parse("2.3.0"): + from cmd2 import fg, bg + RED = fg.red + LIGHT_RED = fg.bright_red + LIGHT_GREEN = fg.bright_green +else: + from cmd2 import Fg, Bg # pylint: disable=no-name-in-module + RED = Fg.RED + LIGHT_RED = Fg.LIGHT_RED + LIGHT_GREEN = Fg.LIGHT_GREEN from cmd2 import CommandSet, with_default_category, with_argparser import argparse @@ -142,7 +153,7 @@ class PysimApp(cmd2.Cmd): super().__init__(persistent_history_file='~/.pysim_shell_history', allow_cli_args=False, auto_load_commands=False, startup_script=script, **kwargs) - self.intro = style('Welcome to pySim-shell!', fg=fg.red) + self.intro = style('Welcome to pySim-shell!', fg=RED) self.default_category = 'pySim-shell built-in commands' self.card = None self.rs = None @@ -302,23 +313,23 @@ class PysimApp(cmd2.Cmd): sys.stderr = self._stderr_backup def _show_failure_sign(self): - self.poutput(style(" +-------------+", fg=fg.bright_red)) - self.poutput(style(" + ## ## +", fg=fg.bright_red)) - self.poutput(style(" + ## ## +", fg=fg.bright_red)) - self.poutput(style(" + ### +", fg=fg.bright_red)) - self.poutput(style(" + ## ## +", fg=fg.bright_red)) - self.poutput(style(" + ## ## +", fg=fg.bright_red)) - self.poutput(style(" +-------------+", fg=fg.bright_red)) + self.poutput(style(" +-------------+", fg=LIGHT_RED)) + self.poutput(style(" + ## ## +", fg=LIGHT_RED)) + self.poutput(style(" + ## ## +", fg=LIGHT_RED)) + self.poutput(style(" + ### +", fg=LIGHT_RED)) + self.poutput(style(" + ## ## +", fg=LIGHT_RED)) + self.poutput(style(" + ## ## +", fg=LIGHT_RED)) + self.poutput(style(" +-------------+", fg=LIGHT_RED)) self.poutput("") def _show_success_sign(self): - self.poutput(style(" +-------------+", fg=fg.bright_green)) - self.poutput(style(" + ## +", fg=fg.bright_green)) - self.poutput(style(" + ## +", fg=fg.bright_green)) - self.poutput(style(" + # ## +", fg=fg.bright_green)) - self.poutput(style(" + ## # +", fg=fg.bright_green)) - self.poutput(style(" + ## +", fg=fg.bright_green)) - self.poutput(style(" +-------------+", fg=fg.bright_green)) + self.poutput(style(" +-------------+", fg=LIGHT_GREEN)) + self.poutput(style(" + ## +", fg=LIGHT_GREEN)) + self.poutput(style(" + ## +", fg=LIGHT_GREEN)) + self.poutput(style(" + # ## +", fg=LIGHT_GREEN)) + self.poutput(style(" + ## # +", fg=LIGHT_GREEN)) + self.poutput(style(" + ## +", fg=LIGHT_GREEN)) + self.poutput(style(" +-------------+", fg=LIGHT_GREEN)) self.poutput("") def _process_card(self, first, script_path):