Mercurial > libervia-backend
diff sat_frontends/jp/cmd_input.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_input.py Wed Jul 31 11:31:22 2019 +0200 +++ b/sat_frontends/jp/cmd_input.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 from sat.core.i18n import _ from sat.core import exceptions from sat_frontends.jp.constants import Const as C @@ -56,7 +56,7 @@ def add_parser_options(self): self.parser.add_argument( - "--encoding", default="utf-8", help=_(u"encoding of the input data") + "--encoding", default="utf-8", help=_("encoding of the input data") ) self.parser.add_argument( "-i", @@ -64,7 +64,7 @@ action="append_const", const=(OPT_STDIN, None), dest="arguments", - help=_(u"standard input"), + help=_("standard input"), ) self.parser.add_argument( "-s", @@ -72,7 +72,7 @@ type=self.opt(OPT_SHORT), action="append", dest="arguments", - help=_(u"short option"), + help=_("short option"), ) self.parser.add_argument( "-l", @@ -80,7 +80,7 @@ type=self.opt(OPT_LONG), action="append", dest="arguments", - help=_(u"long option"), + help=_("long option"), ) self.parser.add_argument( "-p", @@ -88,7 +88,7 @@ type=self.opt(OPT_POS), action="append", dest="arguments", - help=_(u"positional argument"), + help=_("positional argument"), ) self.parser.add_argument( "-x", @@ -96,19 +96,19 @@ action="append_const", const=(OPT_IGNORE, None), dest="arguments", - help=_(u"ignore value"), + help=_("ignore value"), ) self.parser.add_argument( "-D", "--debug", action="store_true", - help=_(u"don't actually run commands but echo what would be launched"), + help=_("don't actually run commands but echo what would be launched"), ) self.parser.add_argument( - "--log", type=argparse.FileType("wb"), help=_(u"log stdout to FILE") + "--log", type=argparse.FileType("wb"), help=_("log stdout to FILE") ) self.parser.add_argument( - "--log-err", type=argparse.FileType("wb"), help=_(u"log stderr to FILE") + "--log-err", type=argparse.FileType("wb"), help=_("log stderr to FILE") ) self.parser.add_argument("command", nargs=argparse.REMAINDER) @@ -123,7 +123,7 @@ arg_type, arg_name = arguments[self.args_idx] except IndexError: self.disp( - _(u"arguments in input data and in arguments sequence don't match"), + _("arguments in input data and in arguments sequence don't match"), error=True, ) self.host.quit(C.EXIT_DATA_ERROR) @@ -150,13 +150,13 @@ self.disp( A.color( C.A_SUBHEADER, - _(u"values: "), + _("values: "), A.RESET, - u", ".join(self._values_ori), + ", ".join(self._values_ori), ), 2, ) - self.disp(A.color(A.BOLD, _(u"**SKIPPING**\n"))) + self.disp(A.color(A.BOLD, _("**SKIPPING**\n"))) self.reset() self.idx += 1 raise exceptions.CancelError @@ -180,7 +180,7 @@ else: self.parser.error( _( - u"Invalid argument, an option type is expected, got {type_}:{name}" + "Invalid argument, an option type is expected, got {type_}:{name}" ).format(type_=arg_type, name=arg_name) ) @@ -188,39 +188,39 @@ """run requested command with parsed arguments""" if self.args_idx != len(self.args.arguments): self.disp( - _(u"arguments in input data and in arguments sequence don't match"), + _("arguments in input data and in arguments sequence don't match"), error=True, ) self.host.quit(C.EXIT_DATA_ERROR) self.disp( - A.color(C.A_HEADER, _(u"command {idx}").format(idx=self.idx)), + A.color(C.A_HEADER, _("command {idx}").format(idx=self.idx)), no_lf=not self.args.debug, ) stdin = "".join(self._stdin) if self.args.debug: self.disp( A.color( - C.A_SUBHEADER, _(u"values: "), A.RESET, u", ".join(self._values_ori) + C.A_SUBHEADER, _("values: "), A.RESET, ", ".join(self._values_ori) ), 2, ) if stdin: - self.disp(A.color(C.A_SUBHEADER, u"--- STDIN ---")) - self.disp(stdin.decode("utf-8")) - self.disp(A.color(C.A_SUBHEADER, u"-------------")) + self.disp(A.color(C.A_SUBHEADER, "--- STDIN ---")) + self.disp(stdin) + self.disp(A.color(C.A_SUBHEADER, "-------------")) self.disp( - u"{indent}{prog} {static} {options} {positionals}".format( - indent=4 * u" ", + "{indent}{prog} {static} {options} {positionals}".format( + indent=4 * " ", prog=sys.argv[0], - static=" ".join(self.args.command).decode("utf-8"), - options=u" ".join([o.decode("utf-8") for o in self._opts]), - positionals=u" ".join([p.decode("utf-8") for p in self._pos]), + static=" ".join(self.args.command), + options=" ".join([o for o in self._opts]), + positionals=" ".join([p for p in self._pos]), ) ) - self.disp(u"\n") + self.disp("\n") else: - self.disp(u" (" + u", ".join(self._values_ori) + u")", 2, no_lf=True) + self.disp(" (" + ", ".join(self._values_ori) + ")", 2, no_lf=True) args = [sys.argv[0]] + self.args.command + self._opts + self._pos p = subprocess.Popen( args, @@ -238,9 +238,9 @@ log_err.write(log_tpl.format(command=" ".join(args), buff=stderr)) ret = p.wait() if ret == 0: - self.disp(A.color(C.A_SUCCESS, _(u"OK"))) + self.disp(A.color(C.A_SUCCESS, _("OK"))) else: - self.disp(A.color(C.A_FAILURE, _(u"FAILED"))) + self.disp(A.color(C.A_FAILURE, _("FAILED"))) self.reset() self.idx += 1 @@ -260,7 +260,7 @@ class Csv(InputCommon): def __init__(self, host): - super(Csv, self).__init__(host, "csv", _(u"comma-separated values")) + super(Csv, self).__init__(host, "csv", _("comma-separated values")) def add_parser_options(self): InputCommon.add_parser_options(self) @@ -269,7 +269,7 @@ "--row", type=int, default=0, - help=_(u"starting row (previous ones will be ignored)"), + help=_("starting row (previous ones will be ignored)"), ) self.parser.add_argument( "-S", @@ -277,7 +277,7 @@ action="append_const", const=("split", None), dest="arguments", - help=_(u"split value in several options"), + help=_("split value in several options"), ) self.parser.add_argument( "-E", @@ -285,8 +285,8 @@ action="append", type=self.opt("empty"), dest="arguments", - help=_(u"action to do on empty value ({choices})").format( - choices=u", ".join(OPT_EMPTY_CHOICES) + help=_("action to do on empty value ({choices})").format( + choices=", ".join(OPT_EMPTY_CHOICES) ), ) @@ -300,8 +300,8 @@ return value if value else False else: self.parser.error( - _(u"--empty value must be one of {choices}").format( - choices=u", ".join(OPT_EMPTY_CHOICES) + _("--empty value must be one of {choices}").format( + choices=", ".join(OPT_EMPTY_CHOICES) ) ) @@ -331,5 +331,5 @@ host, "input", use_profile=False, - help=_(u"launch command with external input"), + help=_("launch command with external input"), )