1*4882a593Smuzhiyun#! /usr/bin/env python3 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun# template.py (and other filenames) 4*4882a593Smuzhiyun# By Max Eliaser (max.eliaser@intel.com) 5*4882a593Smuzhiyun 6*4882a593Smuzhiyun# Copyright (c) 2014 Intel Corp. 7*4882a593Smuzhiyun 8*4882a593Smuzhiyun# Permission is hereby granted, free of charge, to any person obtaining a copy 9*4882a593Smuzhiyun# of this software and associated documentation files (the "Software"), to deal 10*4882a593Smuzhiyun# in the Software without restriction, including without limitation the rights 11*4882a593Smuzhiyun# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12*4882a593Smuzhiyun# copies of the Software, and to permit persons to whom the Software is 13*4882a593Smuzhiyun# furnished to do so, subject to the following conditions: 14*4882a593Smuzhiyun 15*4882a593Smuzhiyun# The above copyright notice and this permission notice shall be included in 16*4882a593Smuzhiyun# all copies or substantial portions of the Software. 17*4882a593Smuzhiyun 18*4882a593Smuzhiyun# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19*4882a593Smuzhiyun# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20*4882a593Smuzhiyun# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21*4882a593Smuzhiyun# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22*4882a593Smuzhiyun# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23*4882a593Smuzhiyun# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 24*4882a593Smuzhiyun# THE SOFTWARE. 25*4882a593Smuzhiyun 26*4882a593Smuzhiyun# This program acts like a dummy version of the texinfo utilities, creating 27*4882a593Smuzhiyun# the right output files but leaving them blank. It will parse out the name 28*4882a593Smuzhiyun# of the executable from argv[0] and emulate the corresponding program, so 29*4882a593Smuzhiyun# multiple copies of this script will exist under different names. 30*4882a593Smuzhiyun 31*4882a593Smuzhiyunimport sys, os, argparse 32*4882a593Smuzhiyun 33*4882a593Smuzhiyun 34*4882a593Smuzhiyunthis_binary = sys.argv[0].split("/")[-1] 35*4882a593Smuzhiyun 36*4882a593Smuzhiyun# To be outputted if functionality that hasn't been stubbed yet is invoked. 37*4882a593Smuzhiyunstub_msg = """ 38*4882a593SmuzhiyunThis stand-in version of %s is not yet fully capable of emulating 39*4882a593Smuzhiyunthe real version from the GNU texinfo suite. If you see this message, file a 40*4882a593Smuzhiyunbug report with details on the recipe that failed. 41*4882a593Smuzhiyun""" % this_binary 42*4882a593Smuzhiyun 43*4882a593Smuzhiyun# Autotools setups query the version, so this is actually necessary. Some of 44*4882a593Smuzhiyun# them (lookin' at you, glibc) actually look for the substring "GNU texinfo," 45*4882a593Smuzhiyun# so we put that substring in there without actually telling a lie. 46*4882a593Smuzhiyunversion_str = """%s (fake texinfo, emulating GNU texinfo) 5.2 47*4882a593Smuzhiyun 48*4882a593SmuzhiyunSuper amazing version which is totally not fake in any way whatsoever. 49*4882a593SmuzhiyunCopyright (C) 2014 Intel Corp. Distributed under the terms of the MIT 50*4882a593Smuzhiyunlicense. 51*4882a593Smuzhiyun""" % this_binary 52*4882a593Smuzhiyun 53*4882a593Smuzhiyunsimple_binaries = "pod2texi texi2dvi pdftexi2dvi texindex texi2pdf \ 54*4882a593Smuzhiyun txixml2texi install-info ginstall-info \ 55*4882a593Smuzhiyun update-info-dir".split() 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun# These utilities use a slightly different set of options and flags. 58*4882a593Smuzhiyuncomplex_binaries = "makeinfo texi2any".split() 59*4882a593Smuzhiyun 60*4882a593Smuzhiyunvalid_binaries = simple_binaries + complex_binaries 61*4882a593Smuzhiyun 62*4882a593Smuzhiyunassert this_binary in valid_binaries, \ 63*4882a593Smuzhiyun this_binary + " is not one of " + ', '.join(valid_binaries) 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun# For debugging 66*4882a593Smuzhiyunlog_interceptions = False 67*4882a593Smuzhiyunif log_interceptions: 68*4882a593Smuzhiyun with open("/tmp/intercepted_" + this_binary, "a") as f: 69*4882a593Smuzhiyun f.write(' '.join([this_binary] + sys.argv[1:]) + '\n') 70*4882a593Smuzhiyun 71*4882a593Smuzhiyun# Look through the options and flags, and if necessary, touch any output 72*4882a593Smuzhiyun# files. 73*4882a593Smuzhiyunp = argparse.ArgumentParser() 74*4882a593Smuzhiyunif this_binary in complex_binaries: 75*4882a593Smuzhiyun p.add_argument('-E', '--macro-expand', metavar='FILE') 76*4882a593Smuzhiyunp.add_argument('-o', '--output', metavar='DEST') 77*4882a593Smuzhiyunp.add_argument('--version', action='store_true') 78*4882a593Smuzhiyun 79*4882a593Smuzhiyunargs, unknown = p.parse_known_args() 80*4882a593Smuzhiyun 81*4882a593Smuzhiyunif args.version: 82*4882a593Smuzhiyun print(version_str) 83*4882a593Smuzhiyun sys.exit(0) 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun# Check for functionality that isn't implemented yet. 86*4882a593Smuzhiyunassert not getattr(args, 'macro_expand', None), \ 87*4882a593Smuzhiyun "-E/--macro-expand option not yet supported" + stub_msg 88*4882a593Smuzhiyun 89*4882a593Smuzhiyun# Check if -o or --output is specified. 90*4882a593Smuzhiyunif args.output: 91*4882a593Smuzhiyun with open(args.output, 'w'): 92*4882a593Smuzhiyun pass 93*4882a593Smuzhiyun sys.exit(0) 94*4882a593Smuzhiyun 95*4882a593Smuzhiyun# The -o/--output option overrides the default. For makeinfo and texi2any, 96*4882a593Smuzhiyun# that default is to look for a @setfilename command in the input file. 97*4882a593Smuzhiyun# Otherwise, printing nothing to stdout and then exiting should suffice. 98*4882a593Smuzhiyunassert this_binary in simple_binaries, \ 99*4882a593Smuzhiyun "Don't know how to get default output file name from input file!" + \ 100*4882a593Smuzhiyun stub_msg 101