aboutsummaryrefslogtreecommitdiffstats
path: root/pySim-shell.py
diff options
context:
space:
mode:
authorHarald Welte <laforge@osmocom.org>2023-04-27 17:30:22 +0200
committerPhilipp Maier <pmaier@sysmocom.de>2023-05-17 17:30:49 +0200
commit961b803ec4b04e83fdec54b03c9d3345de17c3d0 (patch)
treee5017de6862d8ec6267fb4359ff6240d56bd050c /pySim-shell.py
parentc85d4067fdbf641f6ca63be862023c0aca726c29 (diff)
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 <kmvanbrunt@gmail.com> Date: Mon Oct 11 15:20:46 2021 -0400 and Commit f217861feae45a0a1abb56436e68c5dd859d64c0 Author: Kevin Van Brunt <kmvanbrunt@gmail.com> Date: Wed Feb 16 13:34:13 2022 -0500 Change-Id: I9fd32c0fd8f6d40e00a318602af97c288605e8e5
Diffstat (limited to 'pySim-shell.py')
-rwxr-xr-xpySim-shell.py43
1 files changed, 27 insertions, 16 deletions
diff --git a/pySim-shell.py b/pySim-shell.py
index ae783c6..51cd9c6 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):