texinfo-dummy-native: A little clean up of template.py
PATCH 1/3 texinfo-dummy-native: A little clean up of template.py
From: Peter Kjellerstedt <[email protected]>
This is mainly whitespace clean up, plus using the with statement when writing files.
---
This is a backport from master.
.../texinfo-dummy/template.py | 63 +++++++++---------- 1 file changed, 30 insertions(+), 33 deletions(-)
meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py +30 -33
@@ -33,21 +33,20 @@ import sys, os olong = "--output=" 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. stub_msg = """ -This stand-in version of %s is not yet fully capable of emulating the real -version from the GNU texinfo suite. If you see this message, file a bug report -with details on the recipe that failed. +This stand-in version of %s is not yet fully capable of emulating +the real version from the GNU texinfo suite. If you see this message, file a +bug report with details on the recipe that failed. """ % this_binary # Autotools setups query the version, so this is actually necessary. Some of # them (lookin' at you, glibc) actually look for the substring "GNU texinfo," # 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. Copyright (C) 2014 Intel Corp. Distributed under the terms of the MIT license.
@@ -55,62 +54,61 @@ license. simple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \ txixml2texi install-info ginstall-info \ - update-info-dir".split () + update-info-dir".split() # 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 # For generating blank output files. -def touch_file (path): - f = open (path, "w") - f.close () +def touch_file(path): + with open(path, "w"): + pass 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: print(version_str) - sys.exit (0) + sys.exit(0) # For debugging log_interceptions = False if log_interceptions: - f = open ("/tmp/intercepted_" + this_binary, "a") - f.write (' '.join ([this_binary] + sys.argv[1:]) + '\n') - f.close () + with open("/tmp/intercepted_" + this_binary, "a") as f: + f.write(' '.join([this_binary] + sys.argv[1:]) + '\n') # Look through the options and flags, and if necessary, touch any output # files. arg_idx = 1 -while arg_idx < len (sys.argv): +while arg_idx < len(sys.argv): arg = sys.argv [arg_idx] - + if arg == "--": break - + # Something like -I . can result in a need for this (specifically the .) - elif len (arg) < 2: + elif len(arg) < 2: pass - + # 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': - touch_file (sys.argv[arg_idx + 1]) - sys.exit (0) - elif arg.startswith (olong): - touch_file (arg.split ("=")[1]) - sys.exit (0) - + elif arg[0] == '-' and arg[1] != '-' and arg[len(arg) - 1] == 'o': + touch_file(sys.argv[arg_idx + 1]) + sys.exit(0) + elif arg.startswith(olong): + touch_file(arg.split("=")[1]) + sys.exit(0) + # Check for functionality that isn't implemented yet. else: assert arg[0] != '-' or arg[1] == '-' or 'E' not in arg or \ this_binary in simple_binaries, \ "-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 - + arg_idx += 1 # The -o/--output option overrides the default. For makeinfo and texi2any,
@@ -119,4 +117,3 @@ while arg_idx < len (sys.argv): assert this_binary in simple_binaries, \ "Don't know how to get default output file name from input file!" + \ stub_msg -
Signature · 1 line
2.21.0
PATCH 2/3 texinfo-dummy-native: Rewrite template.py to use argparse
From: Peter Kjellerstedt <[email protected]>
The original version of template.py parses the arguments manually. This fails when looking for the -E option if, e.g., an -I option is specified without any space before its argument, and that argument contains the letter 'E'.
A minor difference to the original version is that it parsed the arguments in the order they were specified on the command line whereas this version will always handle -E before -o.
---
This is a backport from master.
.../texinfo-dummy/template.py | 55 ++++++------------- 1 file changed, 18 insertions(+), 37 deletions(-)
meta/recipes-extended/texinfo-dummy-native/texinfo-dummy/template.py +18 -37
@@ -28,10 +28,8 @@ # of the executable from argv[0] and emulate the corresponding program, so # multiple copies of this script will exist under different names. -import sys, os +import sys, os, argparse -olong = "--output=" -Elong = "--macro-expand=" this_binary = sys.argv[0].split("/")[-1]
@@ -61,18 +59,9 @@ complex_binaries = "makeinfo texi2any".split() valid_binaries = simple_binaries + complex_binaries -# For generating blank output files. -def touch_file(path): - with open(path, "w"): - pass - assert this_binary in valid_binaries, \ this_binary + " is not one of " + ', '.join(valid_binaries) -if "--version" in sys.argv: - print(version_str) - sys.exit(0) - # For debugging log_interceptions = False if log_interceptions:
@@ -81,35 +70,27 @@ if log_interceptions: # Look through the options and flags, and if necessary, touch any output # files. -arg_idx = 1 -while arg_idx < len(sys.argv): - arg = sys.argv [arg_idx] - - if arg == "--": - break +p = argparse.ArgumentParser() +if this_binary in complex_binaries: + p.add_argument('-E', '--macro-expand', metavar='FILE') +p.add_argument('-o', '--output', metavar='DEST') +p.add_argument('--version', action='store_true') - # Something like -I . can result in a need for this (specifically the .) - elif len(arg) < 2: - pass - - # 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': - touch_file(sys.argv[arg_idx + 1]) - sys.exit(0) - elif arg.startswith(olong): - touch_file(arg.split("=")[1]) - sys.exit(0) +args, unknown = p.parse_known_args() - # Check for functionality that isn't implemented yet. - else: - assert arg[0] != '-' or arg[1] == '-' or 'E' not in arg or \ - this_binary in simple_binaries, \ - "-E option not yet supported" + stub_msg +if args.version: + print(version_str) + sys.exit(0) - assert not arg.startswith(Elong), \ - Elong[:-1] + " option not yet supported" + stub_msg +# Check for functionality that isn't implemented yet. +assert not getattr(args, 'macro_expand', None), \ + "-E/--macro-expand option not yet supported" + stub_msg - arg_idx += 1 +# Check if -o or --output is specified. +if args.output: + with open(args.output, 'w'): + pass + sys.exit(0) # The -o/--output option overrides the default. For makeinfo and texi2any, # that default is to look for a @setfilename command in the input file.
Signature · 1 line
2.21.0
PATCH 3/3 package.bbclass: Clean up writing of runtime pkgdata files
In reply to Peter KjellerstedtFrom: Peter Kjellerstedt <[email protected]>
This introduces a variable, PKGDATA_VARS, that contains the names of the variables that are to be output in the runtime pkgdata files.
---
This is a backport from master.
meta/classes/package.bbclass | 56 ++++++++++++------------------------ 1 file changed, 18 insertions(+), 38 deletions(-)
meta/classes/package.bbclass +18 -38
@@ -1343,6 +1343,8 @@ EXPORT_FUNCTIONS package_name_hook PKGDESTWORK = "${WORKDIR}/pkgdata" +PKGDATA_VARS = "PN PE PV PR PKGE PKGV PKGR LICENSE DESCRIPTION SUMMARY RDEPENDS RPROVIDES RRECOMMENDS RSUGGESTS RREPLACES RCONFLICTS SECTION PKG ALLOW_EMPTY FILES CONFFILES FILES_INFO pkg_postinst pkg_postrm pkg_preinst pkg_prerm" + python emit_pkgdata() { from glob import glob import json
@@ -1447,48 +1449,26 @@ fi total_size += fstat.st_size d.setVar('FILES_INFO', json.dumps(files, sort_keys=True)) - subdata_file = pkgdatadir + "/runtime/%s" % pkg - sf = open(subdata_file, 'w') - write_if_exists(sf, pkg, 'PN') - write_if_exists(sf, pkg, 'PE') - write_if_exists(sf, pkg, 'PV') - write_if_exists(sf, pkg, 'PR') - write_if_exists(sf, pkg, 'PKGE') - write_if_exists(sf, pkg, 'PKGV') - write_if_exists(sf, pkg, 'PKGR') - write_if_exists(sf, pkg, 'LICENSE') - write_if_exists(sf, pkg, 'DESCRIPTION') - write_if_exists(sf, pkg, 'SUMMARY') - write_if_exists(sf, pkg, 'RDEPENDS') - rprov = write_if_exists(sf, pkg, 'RPROVIDES') - write_if_exists(sf, pkg, 'RRECOMMENDS') - write_if_exists(sf, pkg, 'RSUGGESTS') - write_if_exists(sf, pkg, 'RREPLACES') - write_if_exists(sf, pkg, 'RCONFLICTS') - write_if_exists(sf, pkg, 'SECTION') - write_if_exists(sf, pkg, 'PKG') - write_if_exists(sf, pkg, 'ALLOW_EMPTY') - write_if_exists(sf, pkg, 'FILES') - write_if_exists(sf, pkg, 'CONFFILES') process_postinst_on_target(pkg, d.getVar("MLPREFIX")) add_set_e_to_scriptlets(pkg) - write_if_exists(sf, pkg, 'pkg_postinst') - write_if_exists(sf, pkg, 'pkg_postrm') - write_if_exists(sf, pkg, 'pkg_preinst') - write_if_exists(sf, pkg, 'pkg_prerm') - write_if_exists(sf, pkg, 'FILERPROVIDESFLIST') - write_if_exists(sf, pkg, 'FILES_INFO') - for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split(): - write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile) - - write_if_exists(sf, pkg, 'FILERDEPENDSFLIST') - for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split(): - write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile) - - sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size)) - sf.close() + + subdata_file = pkgdatadir + "/runtime/%s" % pkg + with open(subdata_file, 'w') as sf: + for var in (d.getVar('PKGDATA_VARS') or "").split(): + val = write_if_exists(sf, pkg, var) + + write_if_exists(sf, pkg, 'FILERPROVIDESFLIST') + for dfile in (d.getVar('FILERPROVIDESFLIST_' + pkg) or "").split(): + write_if_exists(sf, pkg, 'FILERPROVIDES_' + dfile) + + write_if_exists(sf, pkg, 'FILERDEPENDSFLIST') + for dfile in (d.getVar('FILERDEPENDSFLIST_' + pkg) or "").split(): + write_if_exists(sf, pkg, 'FILERDEPENDS_' + dfile) + + sf.write('%s_%s: %d\n' % ('PKGSIZE', pkg, total_size)) # Symlinks needed for rprovides lookup + rprov = d.getVar('RPROVIDES_%s' % pkg) or d.getVar('RPROVIDES') if rprov: for p in rprov.strip().split(): subdata_sym = pkgdatadir + "/runtime-rprovides/%s/%s" % (p, pkg)
Signature · 1 line
2.21.0