commit cc7ca138dabec6090edc9b4e8d18d0239f04aa99 Author: José Matos <jama...@lyx.org> Date: Sat May 13 15:25:44 2017 +0100
Fix call of layout2layout as a module. If we call parser.parse_args(), thus with no arguments, the parser uses sys.argv (because that is the default). We should pass argv since that was the purpose of handling argv in the main function. We pass argv[1:] since when parsing the arguments we always ignore the name of the program. Use the full power of argparse to declare the default value of the end_format. --- lib/scripts/layout2layout.py | 17 ++++++----------- 1 files changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py index 0633c81..56b4339 100644 --- a/lib/scripts/layout2layout.py +++ b/lib/scripts/layout2layout.py @@ -1172,14 +1172,14 @@ def main(argv): parser = argparse.ArgumentParser(**args) - parser.add_argument("-t", "--to", type=int, dest="format", + parser.add_argument("-t", "--to", type=int, dest="format", default= currentFormat, help=("destination layout format, default %i (latest)") % currentFormat) parser.add_argument("input_file", nargs='?', type=cmd_arg, default=None, help="input file (default stdin)") parser.add_argument("output_file", nargs='?', type=cmd_arg, default=None, help="output file (default stdout)") - options = parser.parse_args(argv) + options = parser.parse_args(argv[1:]) # Open files if options.input_file: @@ -1192,19 +1192,14 @@ def main(argv): else: output = sys.stdout - if options.format: - end_format = options.format - else: - end_format = currentFormat - - if end_format > currentFormat: - error("Format %i does not exist" % end_format); + if options.format > currentFormat: + error("Format %i does not exist" % options.format); # Do the real work lines = read(source) format = 1 - while (format < end_format): - format = convert(lines, end_format) + while (format < options.format): + format = convert(lines, options.format) write(output, lines) # Close files