On Tue, Sep 17, 2019 at 10:09:56AM +0200, Uwe Kleine-König wrote: > On some machines the python command is provided by Python 3 while on > most (at least in my bubble) it is still Python 2. Modify the code to > make it usable by both Python versions. > > print_function is available in __future__ since Python 2.6.0a2, which > shouldn't be a relevant restriction. > > The modified script generates the same documentation as the old one; > independent if the script is called using Python 2 (here: 2.7.16) or > Python 3 (here: 3.7.3). > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxxxx> > --- > Documentation/gen_commands.py | 30 ++++++++++++++++++------------ > 1 file changed, 18 insertions(+), 12 deletions(-) > > diff --git a/Documentation/gen_commands.py b/Documentation/gen_commands.py > index 6251b4f22ed9..ff07ee0297f1 100755 > --- a/Documentation/gen_commands.py > +++ b/Documentation/gen_commands.py > @@ -1,5 +1,7 @@ > #!/usr/bin/python > > +from __future__ import print_function > + > import errno > import os > import re > @@ -28,10 +30,15 @@ CONT = re.compile(r"""\s*"(.*?)"\s*\)?\s*$""") > > CMDS = {} > > +def string_escape(s): > + # This used to do s.decode("string_escape") which isn't available on Python 3. > + # Actually we only need to drop '\t', so do this here. > + return s.replace(r'\t', '') I just found a change in my working copy that didn't make it into my patch: - # Actually we only need to drop '\t', so do this here. - return s.replace(r'\t', '') + # Actually we only need to drop '\t' and '\n', so do this here. + return s.replace(r'\t', '').replace(r'\n', '') With this the claim that the generated code is identical actually holds. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ | _______________________________________________ barebox mailing list barebox@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/barebox