diff sat_frontends/jp/cmd_shell.py @ 3040:fee60f17ebac

jp: jp asyncio port: /!\ this commit is huge. Jp is temporarily not working with `dbus` bridge /!\ This patch implements the port of jp to asyncio, so it is now correctly using the bridge asynchronously, and it can be used with bridges like `pb`. This also simplify the code, notably for things which were previously implemented with many callbacks (like pagination with RSM). During the process, some behaviours have been modified/fixed, in jp and backends, check diff for details.
author Goffi <goffi@goffi.org>
date Wed, 25 Sep 2019 08:56:41 +0200
parents ab2696e34d29
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_shell.py	Wed Sep 25 08:53:38 2019 +0200
+++ b/sat_frontends/jp/cmd_shell.py	Wed Sep 25 08:56:41 2019 +0200
@@ -18,16 +18,16 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 
-from . import base
 import cmd
 import sys
+import shlex
+import subprocess
+from . import base
 from sat.core.i18n import _
 from sat.core import exceptions
 from sat_frontends.jp.constants import Const as C
 from sat_frontends.jp import arg_tools
 from sat.tools.common.ansi import ANSI as A
-import shlex
-import subprocess
 
 __commands__ = ["Shell"]
 INTRO = _(
@@ -44,7 +44,8 @@
 class Shell(base.CommandBase, cmd.Cmd):
     def __init__(self, host):
         base.CommandBase.__init__(
-            self, host, "shell", help=_("launch jp in shell (REPL) mode")
+            self, host, "shell",
+            help=_("launch jp in shell (REPL) mode")
         )
         cmd.Cmd.__init__(self)
 
@@ -152,13 +153,15 @@
             help_list = self._cur_parser.format_help().split("\n\n")
             print(("\n\n".join(help_list[1 if self.path else 2 :])))
 
-    def do_debug(self, args):
-        """launch internal debugger"""
-        try:
-            import ipdb as pdb
-        except ImportError:
-            import pdb
-        pdb.set_trace()
+    # FIXME: debug crashes on exit and is not that useful,
+    #        keeping it until refactoring, may be removed entirely then
+    # def do_debug(self, args):
+    #     """launch internal debugger"""
+    #     try:
+    #         import ipdb as pdb
+    #     except ImportError:
+    #         import pdb
+    #     pdb.set_trace()
 
     def do_verbose(self, args):
         """show verbose mode, or (de)activate it"""
@@ -188,10 +191,7 @@
 
     def do_version(self, args):
         """show current SàT/jp version"""
-        try:
-            self.host.run(["--version"])
-        except SystemExit:
-            pass
+        self.run_cmd(['--version'])
 
     def do_shell(self, args):
         """launch an external command (you can use ![command] too)"""
@@ -292,7 +292,9 @@
         """alias for quit"""
         self.do_quit(args)
 
-    def start(self):
+    async def start(self):
+        # FIXME: "shell" is currently kept synchronous as it works well as it
+        #        and it will be refactored soon.
         default_profile = self.host.bridge.profileNameGet(C.PROF_KEY_DEFAULT)
         self._not_default_profile = self.profile != default_profile
         self.path = []
@@ -300,4 +302,4 @@
         self.use = {}
         self.verbose = False
         self.update_path()
-        self.cmdloop(INTRO.encode("utf-8"))
+        self.cmdloop(INTRO)