Mercurial > libervia-backend
diff sat_frontends/jp/cmd_shell.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 003b8b4b56a7 |
children | fee60f17ebac |
line wrap: on
line diff
--- a/sat_frontends/jp/cmd_shell.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat_frontends/jp/cmd_shell.py Tue Aug 13 19:08:41 2019 +0200 @@ -18,7 +18,7 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. -import base +from . import base import cmd import sys from sat.core.i18n import _ @@ -31,7 +31,7 @@ __commands__ = ["Shell"] INTRO = _( - u"""Welcome to {app_name} shell, the Salut à Toi shell ! + """Welcome to {app_name} shell, the Salut à Toi shell ! This enrironment helps you using several {app_name} commands with similar parameters. @@ -44,7 +44,7 @@ class Shell(base.CommandBase, cmd.Cmd): def __init__(self, host): base.CommandBase.__init__( - self, host, "shell", help=_(u"launch jp in shell (REPL) mode") + self, host, "shell", help=_("launch jp in shell (REPL) mode") ) cmd.Cmd.__init__(self) @@ -54,22 +54,22 @@ def update_path(self): self._cur_parser = self.host.parser - self.help = u"" + self.help = "" for idx, path_elt in enumerate(self.path): try: self._cur_parser = arg_tools.get_cmd_choices(path_elt, self._cur_parser) except exceptions.NotFound: - self.disp(_(u"bad command path"), error=True) + self.disp(_("bad command path"), error=True) self.path = self.path[:idx] break else: self.help = self._cur_parser - self.prompt = A.color(C.A_PROMPT_PATH, u"/".join(self.path)) + A.color( - C.A_PROMPT_SUF, u"> " + self.prompt = A.color(C.A_PROMPT_PATH, "/".join(self.path)) + A.color( + C.A_PROMPT_SUF, "> " ) try: - self.actions = arg_tools.get_cmd_choices(parser=self._cur_parser).keys() + self.actions = list(arg_tools.get_cmd_choices(parser=self._cur_parser).keys()) except exceptions.NotFound: self.actions = [] @@ -100,9 +100,9 @@ # Situation should be better when we'll move away from python-dbus if self.verbose: self.disp( - _(u"COMMAND {external}=> {args}").format( - external=_(u"(external) ") if external else u"", - args=u" ".join(self.format_args(args)), + _("COMMAND {external}=> {args}").format( + external=_("(external) ") if external else "", + args=" ".join(self.format_args(args)), ) ) if not external: @@ -124,7 +124,7 @@ self.disp( A.color( C.A_FAILURE, - u"command failed with an error code of {err_no}".format( + "command failed with an error code of {err_no}".format( err_no=ret_code ), ), @@ -145,12 +145,12 @@ def do_help(self, args): """show help message""" if not args: - self.disp(A.color(C.A_HEADER, _(u"Shell commands:")), no_lf=True) + self.disp(A.color(C.A_HEADER, _("Shell commands:")), no_lf=True) super(Shell, self).do_help(args) if not args: - self.disp(A.color(C.A_HEADER, _(u"Action commands:"))) + self.disp(A.color(C.A_HEADER, _("Action commands:"))) help_list = self._cur_parser.format_help().split("\n\n") - print("\n\n".join(help_list[1 if self.path else 2 :])) + print(("\n\n".join(help_list[1 if self.path else 2 :]))) def do_debug(self, args): """launch internal debugger""" @@ -166,8 +166,8 @@ if args: self.verbose = C.bool(args[0]) self.disp( - _(u"verbose mode is {status}").format( - status=_(u"ENABLED") if self.verbose else _(u"DISABLED") + _("verbose mode is {status}").format( + status=_("ENABLED") if self.verbose else _("DISABLED") ) ) @@ -211,7 +211,7 @@ # so we need to add it in arguments to use current user profile if self.verbose: self.disp( - _(u"arg profile={profile} (logged profile)").format( + _("arg profile={profile} (logged profile)").format( profile=self.profile ) ) @@ -233,25 +233,25 @@ args = self.parse_args(args) if not args: if not self.use: - self.disp(_(u"no argument in USE")) + self.disp(_("no argument in USE")) else: - self.disp(_(u"arguments in USE:")) - for arg, value in self.use.iteritems(): + self.disp(_("arguments in USE:")) + for arg, value in self.use.items(): self.disp( _( A.color( C.A_SUBHEADER, arg, A.RESET, - u" = ", + " = ", arg_tools.escape(value), ) ) ) elif len(args) != 2: - self.disp(u"bad syntax, please use:\nuse [arg] [value]", error=True) + self.disp("bad syntax, please use:\nuse [arg] [value]", error=True) else: - self.use[args[0]] = u" ".join(args[1:]) + self.use[args[0]] = " ".join(args[1:]) if self.verbose: self.disp( "set {name} = {value}".format( @@ -271,25 +271,25 @@ except KeyError: self.disp( A.color( - C.A_FAILURE, _(u"argument {name} not found").format(name=arg) + C.A_FAILURE, _("argument {name} not found").format(name=arg) ), error=True, ) else: if self.verbose: - self.disp(_(u"argument {name} removed").format(name=arg)) + self.disp(_("argument {name} removed").format(name=arg)) def do_whoami(self, args): - u"""print profile currently used""" + """print profile currently used""" self.disp(self.profile) def do_quit(self, args): - u"""quit the shell""" - self.disp(_(u"good bye!")) + """quit the shell""" + self.disp(_("good bye!")) self.host.quit() def do_exit(self, args): - u"""alias for quit""" + """alias for quit""" self.do_quit(args) def start(self):