1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-30 12:29:55 +00:00

texinfo-dummy-native: A little clean up of template.py

This is mainly whitespace clean up, plus using the with statement when
writing files.

(From OE-Core rev: f09cb832fa8e83e7e5faf6bd9464481aef5b4547)

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@axis.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Peter Kjellerstedt
2019-05-23 20:42:53 +02:00
committed by Richard Purdie
parent cdbb785595
commit cf5dd9812c
@@ -33,20 +33,19 @@ import sys, os
olong = "--output=" olong = "--output="
Elong = "--macro-expand=" Elong = "--macro-expand="
this_binary = sys.argv[0].split("/")[-1]
this_binary = sys.argv[0].split ("/")[-1]
# To be outputted if functionality that hasn't been stubbed yet is invoked. # To be outputted if functionality that hasn't been stubbed yet is invoked.
stub_msg = """ stub_msg = """
This stand-in version of %s is not yet fully capable of emulating the real This stand-in version of %s is not yet fully capable of emulating
version from the GNU texinfo suite. If you see this message, file a bug report the real version from the GNU texinfo suite. If you see this message, file a
with details on the recipe that failed. bug report with details on the recipe that failed.
""" % this_binary """ % this_binary
# Autotools setups query the version, so this is actually necessary. Some of # Autotools setups query the version, so this is actually necessary. Some of
# them (lookin' at you, glibc) actually look for the substring "GNU texinfo," # them (lookin' at you, glibc) actually look for the substring "GNU texinfo,"
# so we put that substring in there without actually telling a lie. # so we put that substring in there without actually telling a lie.
version_str = """ %s (fake texinfo, emulating GNU texinfo) 5.2 version_str = """%s (fake texinfo, emulating GNU texinfo) 5.2
Super amazing version which is totally not fake in any way whatsoever. Super amazing version which is totally not fake in any way whatsoever.
Copyright (C) 2014 Intel Corp. Distributed under the terms of the MIT Copyright (C) 2014 Intel Corp. Distributed under the terms of the MIT
@@ -55,52 +54,51 @@ license.
simple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \ simple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \
txixml2texi install-info ginstall-info \ txixml2texi install-info ginstall-info \
update-info-dir".split () update-info-dir".split()
# These utilities use a slightly different set of options and flags. # These utilities use a slightly different set of options and flags.
complex_binaries = "makeinfo texi2any".split () complex_binaries = "makeinfo texi2any".split()
valid_binaries = simple_binaries + complex_binaries valid_binaries = simple_binaries + complex_binaries
# For generating blank output files. # For generating blank output files.
def touch_file (path): def touch_file(path):
f = open (path, "w") with open(path, "w"):
f.close () pass
assert this_binary in valid_binaries, \ assert this_binary in valid_binaries, \
this_binary + " is not one of " + ', '.join (valid_binaries) this_binary + " is not one of " + ', '.join(valid_binaries)
if "--version" in sys.argv: if "--version" in sys.argv:
print(version_str) print(version_str)
sys.exit (0) sys.exit(0)
# For debugging # For debugging
log_interceptions = False log_interceptions = False
if log_interceptions: if log_interceptions:
f = open ("/tmp/intercepted_" + this_binary, "a") with open("/tmp/intercepted_" + this_binary, "a") as f:
f.write (' '.join ([this_binary] + sys.argv[1:]) + '\n') f.write(' '.join([this_binary] + sys.argv[1:]) + '\n')
f.close ()
# Look through the options and flags, and if necessary, touch any output # Look through the options and flags, and if necessary, touch any output
# files. # files.
arg_idx = 1 arg_idx = 1
while arg_idx < len (sys.argv): while arg_idx < len(sys.argv):
arg = sys.argv [arg_idx] arg = sys.argv [arg_idx]
if arg == "--": if arg == "--":
break break
# Something like -I . can result in a need for this (specifically the .) # Something like -I . can result in a need for this (specifically the .)
elif len (arg) < 2: elif len(arg) < 2:
pass pass
# Check if -o or --output is specified. These can be used at most once. # Check if -o or --output is specified. These can be used at most once.
elif arg[0] == '-' and arg[1] != '-' and arg[len (arg) - 1] == 'o': elif arg[0] == '-' and arg[1] != '-' and arg[len(arg) - 1] == 'o':
touch_file (sys.argv[arg_idx + 1]) touch_file(sys.argv[arg_idx + 1])
sys.exit (0) sys.exit(0)
elif arg.startswith (olong): elif arg.startswith(olong):
touch_file (arg.split ("=")[1]) touch_file(arg.split("=")[1])
sys.exit (0) sys.exit(0)
# Check for functionality that isn't implemented yet. # Check for functionality that isn't implemented yet.
else: else:
@@ -108,7 +106,7 @@ while arg_idx < len (sys.argv):
this_binary in simple_binaries, \ this_binary in simple_binaries, \
"-E option not yet supported" + stub_msg "-E option not yet supported" + stub_msg
assert not arg.startswith (Elong), \ assert not arg.startswith(Elong), \
Elong[:-1] + " option not yet supported" + stub_msg Elong[:-1] + " option not yet supported" + stub_msg
arg_idx += 1 arg_idx += 1
@@ -119,4 +117,3 @@ while arg_idx < len (sys.argv):
assert this_binary in simple_binaries, \ assert this_binary in simple_binaries, \
"Don't know how to get default output file name from input file!" + \ "Don't know how to get default output file name from input file!" + \
stub_msg stub_msg