laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/30075 
)

 (

7 is the latest approved patch-set.
No files were changed between the latest approved patch-set and the submitted 
one.
 )Change subject: pySim-shell: fix compatibility problem with cmd2 >= 2.3.0 (bg)
......................................................................

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 <kmvanbr...@gmail.com>
Date:   Mon Oct 11 15:20:46 2021 -0400

and

Commit f217861feae45a0a1abb56436e68c5dd859d64c0
Author: Kevin Van Brunt <kmvanbr...@gmail.com>
Date:   Wed Feb 16 13:34:13 2022 -0500

Change-Id: I9fd32c0fd8f6d40e00a318602af97c288605e8e5
---
M pySim-shell.py
1 file changed, 52 insertions(+), 16 deletions(-)

Approvals:
  fixeria: Looks good to me, but someone else must approve
  laforge: Looks good to me, approved
  Jenkins Builder: Verified




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 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 @@

         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 @@
             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):

--
To view, visit https://gerrit.osmocom.org/c/pysim/+/30075
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I9fd32c0fd8f6d40e00a318602af97c288605e8e5
Gerrit-Change-Number: 30075
Gerrit-PatchSet: 10
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: fixeria <vyanits...@sysmocom.de>
Gerrit-Reviewer: laforge <lafo...@osmocom.org>
Gerrit-CC: msuraev <msur...@sysmocom.de>
Gerrit-MessageType: merged

Reply via email to