Fix scripts to add python3 support

* fixed libraries include
  * fixed incorrect usage of python2 string
  * fixed python2 to python3 script issues (2to3) like print ""
  * fixed data types
  * fixed python3 usage of str instead of string (join, split etc.)
  * added support to determine the absolute path of the executable
    binary of the current Python interpreter
    * thx @Bagira80 for his support

Fixes issue: #67

Signed-off-by: Thomas Höhlig <thoehlig@benocs.com>
This commit is contained in:
Thomas Höhlig
2022-07-21 02:06:42 +02:00
committed by Jim King
parent 03869de68e
commit 4b8160057a
4 changed files with 67 additions and 63 deletions

View File

@@ -118,6 +118,11 @@ def to_existing_absolute_path(string):
def main(): def main():
"""The main function.""" """The main function."""
# Determine the currently running python executable.
python_executable = sys.executable
if python_executable == None or python_executable == "":
python_executable = python
# Find the current Boost source-directory in which this script is located. # Find the current Boost source-directory in which this script is located.
sourceDir = current_boost_dir() sourceDir = current_boost_dir()
if sourceDir == None: if sourceDir == None:
@@ -150,19 +155,19 @@ def main():
# Some verbose debug output. # Some verbose debug output.
if args.verbose: if args.verbose:
print "Arguments extracted from command-line:" print("Arguments extracted from command-line:")
print " verbose = ", args.verbose print(" verbose = ", args.verbose)
print " source directory = ", args.sourceDir print(" source directory = ", args.sourceDir)
print " num elements = ", args.numElements print(" num elements = ", args.numElements)
print " sequence type = ", args.seqType print(" sequence type = ", args.seqType)
print " want: vector = ", args.want_vector print(" want: vector = ", args.want_vector)
print " want: list = ", args.want_list print(" want: list = ", args.want_list)
print " want: set = ", args.want_set print(" want: set = ", args.want_set)
print " want: map = ", args.want_map print(" want: map = ", args.want_map)
# Verify that we received any source-directory. # Verify that we received any source-directory.
if args.sourceDir == None: if args.sourceDir == None:
print "You should specify a valid path to the Boost source-directory." print("You should specify a valid path to the Boost source-directory.")
sys.exit(0) sys.exit(0)
# The directories for header- and source files of Boost.MPL. # The directories for header- and source files of Boost.MPL.
@@ -177,13 +182,13 @@ def main():
sourceDir = os.path.join( args.sourceDir, "preprocessed" ) sourceDir = os.path.join( args.sourceDir, "preprocessed" )
if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ): if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ):
cmdlineParser.print_usage() cmdlineParser.print_usage()
print "error: Cannot find Boost.MPL header/source files in given Boost source-directory!" print("error: Cannot find Boost.MPL header/source files in given Boost source-directory!")
sys.exit(0) sys.exit(0)
# Some verbose debug output. # Some verbose debug output.
if args.verbose: if args.verbose:
print "Chosen header-directory: ", headerDir print("Chosen header-directory: ", headerDir)
print "Chosen source-directory: ", sourceDir print("Chosen source-directory: ", sourceDir)
# Create list of containers for which files shall be pre-processed. # Create list of containers for which files shall be pre-processed.
containers = [] containers = []
@@ -196,23 +201,23 @@ def main():
if args.want_map: if args.want_map:
containers.append('map') containers.append('map')
if containers == []: if containers == []:
print "Nothing to do." print("Nothing to do.")
print "(Why did you prevent generating pre-processed headers for all Boost.MPL container types?)" print("(Why did you prevent generating pre-processed headers for all Boost.MPL container types?)")
sys.exit(0) sys.exit(0)
# Possibly fix the header-comments of input-files needed for pre-processing. # Possibly fix the header-comments of input-files needed for pre-processing.
if args.verbose: if args.verbose:
print "Checking if prior to pre-processing some input-files need fixing." print("Checking if prior to pre-processing some input-files need fixing.")
needFixing = fixmpl.check_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose) needFixing = fixmpl.check_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose)
if needFixing: if needFixing:
if args.verbose: if args.verbose:
print "Fixing of some input-files prior to pre-processing is needed." print("Fixing of some input-files prior to pre-processing is needed.")
print "Will fix them now!" print("Will fix them now!")
fixmpl.fix_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose) fixmpl.fix_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose)
# Some verbose debug output. # Some verbose debug output.
if args.verbose: if args.verbose:
print "Containers for which to pre-process headers: ", containers print("Containers for which to pre-process headers: ", containers)
# Create (additional) input files for generating pre-processed headers of numbered sequence MPL containers. # Create (additional) input files for generating pre-processed headers of numbered sequence MPL containers.
if args.seqType == "both" or args.seqType == "numbered": if args.seqType == "both" or args.seqType == "numbered":
@@ -226,24 +231,24 @@ def main():
if args.seqType == "both" or args.seqType == "numbered": if args.seqType == "both" or args.seqType == "numbered":
if args.want_vector: if args.want_vector:
if args.verbose: if args.verbose:
print "Pre-process headers for Boost.MPL numbered vectors." print("Pre-process headers for Boost.MPL numbered vectors.")
os.system( "python " + os.path.join( sourceDir, "preprocess_vector.py" ) + " all " + args.sourceDir ) os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_vector.py" ) + " all " + args.sourceDir )
if args.want_list: if args.want_list:
if args.verbose: if args.verbose:
print "Pre-process headers for Boost.MPL numbered lists." print("Pre-process headers for Boost.MPL numbered lists.")
os.system( "python " + os.path.join( sourceDir, "preprocess_list.py" ) + " all " + args.sourceDir ) os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_list.py" ) + " all " + args.sourceDir )
if args.want_set: if args.want_set:
if args.verbose: if args.verbose:
print "Pre-process headers for Boost.MPL numbered sets." print("Pre-process headers for Boost.MPL numbered sets.")
os.system( "python " + os.path.join( sourceDir, "preprocess_set.py" ) + " all " + args.sourceDir ) os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_set.py" ) + " all " + args.sourceDir )
if args.want_map: if args.want_map:
if args.verbose: if args.verbose:
print "Pre-process headers for Boost.MPL numbered maps." print("Pre-process headers for Boost.MPL numbered maps.")
os.system( "python " + os.path.join( sourceDir, "preprocess_map.py" ) + " all " + args.sourceDir ) os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_map.py" ) + " all " + args.sourceDir )
if args.seqType == "both" or args.seqType == "variadic": if args.seqType == "both" or args.seqType == "variadic":
if args.verbose: if args.verbose:
print "Pre-process headers for Boost.MPL variadic containers." print("Pre-process headers for Boost.MPL variadic containers.")
os.system( "python " + os.path.join( sourceDir, "preprocess.py" ) + " all " + args.sourceDir ) os.system( python_executable + " " + os.path.join( sourceDir, "preprocess.py" ) + " all " + args.sourceDir )
if __name__ == '__main__': if __name__ == '__main__':

View File

@@ -66,26 +66,26 @@ def check_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set',
result1 = False result1 = False
if seqType == "both" or seqType == "variadic": if seqType == "both" or seqType == "variadic":
if verbose: if verbose:
print "Check if input files for pre-processing Boost.MPL variadic containers need fixing." print("Check if input files for pre-processing Boost.MPL variadic containers need fixing.")
result1 = check_input_files_for_variadic_seq(headerDir, sourceDir) result1 = check_input_files_for_variadic_seq(headerDir, sourceDir)
if verbose: if verbose:
if result1: if result1:
print " At least one input file needs fixing!" print(" At least one input file needs fixing!")
else: else:
print " No input file needs fixing!" print(" No input file needs fixing!")
# Check the input files for containers in their numbered form. # Check the input files for containers in their numbered form.
result2 = False result2 = False
result3 = False result3 = False
if seqType == "both" or seqType == "numbered": if seqType == "both" or seqType == "numbered":
if verbose: if verbose:
print "Check input files for pre-processing Boost.MPL numbered containers." print("Check input files for pre-processing Boost.MPL numbered containers.")
result2 = check_input_files_for_numbered_seq(headerDir, ".hpp", containers) result2 = check_input_files_for_numbered_seq(headerDir, ".hpp", containers)
result3 = check_input_files_for_numbered_seq(sourceDir, ".cpp", containers) result3 = check_input_files_for_numbered_seq(sourceDir, ".cpp", containers)
if verbose: if verbose:
if result2 or result3: if result2 or result3:
print " At least one input file needs fixing!" print(" At least one input file needs fixing!")
else: else:
print " No input file needs fixing!" print(" No input file needs fixing!")
# Return result. # Return result.
return result1 or result2 or result3 return result1 or result2 or result3
@@ -128,12 +128,12 @@ def fix_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set', '
# Fix the input files for containers in their variadic form. # Fix the input files for containers in their variadic form.
if seqType == "both" or seqType == "variadic": if seqType == "both" or seqType == "variadic":
if verbose: if verbose:
print "Fix input files for pre-processing Boost.MPL variadic containers." print("Fix input files for pre-processing Boost.MPL variadic containers.")
fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp) fix_input_files_for_variadic_seq(headerDir, sourceDir, timestamp)
# Fix the input files for containers in their numbered form. # Fix the input files for containers in their numbered form.
if seqType == "both" or seqType == "numbered": if seqType == "both" or seqType == "numbered":
if verbose: if verbose:
print "Fix input files for pre-processing Boost.MPL numbered containers." print("Fix input files for pre-processing Boost.MPL numbered containers.")
fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers) fix_input_files_for_numbered_seq(headerDir, ".hpp", timestamp, containers)
fix_input_files_for_numbered_seq(sourceDir, ".cpp", timestamp, containers) fix_input_files_for_numbered_seq(sourceDir, ".cpp", timestamp, containers)
@@ -164,10 +164,10 @@ def main():
# Some verbose debug output. # Some verbose debug output.
if args.verbose: if args.verbose:
print "Arguments extracted from command-line:" print("Arguments extracted from command-line:")
print " verbose = ", args.verbose print(" verbose = ", args.verbose)
print " check-only = ", args.checkonly print(" check-only = ", args.checkonly)
print " source directory = ", args.sourceDir print(" source directory = ", args.sourceDir)
# The directories for header- and source files of Boost.MPL. # The directories for header- and source files of Boost.MPL.
# NOTE: Assuming 'args.sourceDir' is the source-directory of the entire boost project. # NOTE: Assuming 'args.sourceDir' is the source-directory of the entire boost project.
@@ -181,21 +181,21 @@ def main():
sourceDir = os.path.join( args.sourceDir, "preprocessed" ) sourceDir = os.path.join( args.sourceDir, "preprocessed" )
if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ): if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ):
cmdlineParser.print_usage() cmdlineParser.print_usage()
print "error: Cannot find Boost.MPL header/source files in given Boost source-directory!" print("error: Cannot find Boost.MPL header/source files in given Boost source-directory!")
sys.exit(0) sys.exit(0)
# Some verbose debug output. # Some verbose debug output.
if args.verbose: if args.verbose:
print "Chosen header-directory: ", headerDir print("Chosen header-directory: ", headerDir)
print "Chosen source-directory: ", sourceDir print("Chosen source-directory: ", sourceDir)
if args.checkonly: if args.checkonly:
# Check input files for generating pre-processed headers. # Check input files for generating pre-processed headers.
result = check_input_files(headerDir, sourceDir, verbose = args.verbose) result = check_input_files(headerDir, sourceDir, verbose = args.verbose)
if result: if result:
print "Fixing the input-files used for pre-processing of Boost.MPL headers IS required." print("Fixing the input-files used for pre-processing of Boost.MPL headers IS required.")
else: else:
print "Fixing the input-files used for pre-processing of Boost.MPL headers is NOT required." print("Fixing the input-files used for pre-processing of Boost.MPL headers is NOT required.")
else: else:
# Fix input files for generating pre-processed headers. # Fix input files for generating pre-processed headers.
fix_input_files(headerDir, sourceDir, verbose = args.verbose) fix_input_files(headerDir, sourceDir, verbose = args.verbose)

View File

@@ -12,6 +12,7 @@
# $Revision$ # $Revision$
import fileinput import fileinput
import functools
import os import os
import re import re
import string import string
@@ -22,22 +23,21 @@ max_len = 79
ident = 4 ident = 4
def nearest_ident_pos(text): def nearest_ident_pos(text):
return (len(text)/ident) * ident return int((len(text)/ident) * ident)
def block_format(limits, text, first_sep=' ', sep=',', need_last_ident=1 ): def block_format(limits, text, first_sep=' ', sep=',', need_last_ident=1 ):
if sep == ',' and string.find( text, '<' ) != -1: if sep == ',' and str.find( text, '<' ) != -1:
sep = '%s ' % sep sep = '%s ' % sep
words = string.split( words = str.split(
string.join( string.split( text ), ' ' ) ' '.join( str.split( text ) )
, sep , sep
) )
s = ' ' * limits[0] s = ' ' * limits[0]
max_len = limits[1] max_len = limits[1]
return '%s\n%s' \ return '%s\n%s' \
% ( % (
reduce( functools.reduce(
lambda t,w,max_len=max_len,s=s,sep=sep: lambda t,w,max_len=max_len,s=s,sep=sep:
if_else(t[1] + len(w) < max_len if_else(t[1] + len(w) < max_len
, ('%s%s%s'% (t[0],t[2],w), t[1]+len(w)+len(t[2]), sep) , ('%s%s%s'% (t[0],t[2],w), t[1]+len(w)+len(t[2]), sep)
@@ -52,7 +52,6 @@ def block_format(limits, text, first_sep=' ', sep=',', need_last_ident=1 ):
def handle_args( match ): def handle_args( match ):
if re.compile('^\s*(typedef|struct|static)\s+.*?$').match(match.group(0)): if re.compile('^\s*(typedef|struct|static)\s+.*?$').match(match.group(0)):
return match.group(0) return match.group(0)
return '%s'\ return '%s'\
% block_format( % block_format(
(nearest_ident_pos(match.group(1)),max_len) (nearest_ident_pos(match.group(1)),max_len)
@@ -86,7 +85,7 @@ def handle_inline_args(match):
(nearest_ident_pos(match.group(1))+ident,max_len-len(match.group(9))) (nearest_ident_pos(match.group(1))+ident,max_len-len(match.group(9)))
, match.group(4) , match.group(4)
) )
, string.replace(match.group(1),',',' ') , str.replace(match.group(1),',',' ')
, match.group(9) , match.group(9)
) )
@@ -98,18 +97,18 @@ def handle_simple_list(match):
return if_else(single_arg,'%s<%s>','%s< %s >') %\ return if_else(single_arg,'%s<%s>','%s< %s >') %\
( (
match.group(1) match.group(1)
, string.join(string.split(match.group(2)), '') , ''.join(str.split(match.group(2)))
) )
def handle_static(match): def handle_static(match):
if len(match.group(0)) < max_len: if len(match.group(0)) < max_len:
return match.group(0) return match.group(0)
(first_sep,sep) = if_else(string.find(match.group(0),'+') == -1, (' ',' '),(' ','+')) (first_sep,sep) = if_else(str.find(match.group(0),'+') == -1, (' ',' '),(' ','+'))
return '%s%s\n%s%s' %\ return '%s%s\n%s%s' %\
( (
match.group(1) match.group(1)
, string.join(string.split(match.group(2)), ' ') , ' '.join(str.split(match.group(2)))
, block_format( , block_format(
(nearest_ident_pos(match.group(1))+ident,max_len) (nearest_ident_pos(match.group(1))+ident,max_len)
, match.group(4) , match.group(4)
@@ -120,7 +119,7 @@ def handle_static(match):
) )
def handle_typedefs(match): def handle_typedefs(match):
if string.count(match.group(2), ';') == 1: if str.count(match.group(2), ';') == 1:
return match.group(0) return match.group(0)
join_sep = ';\n%s' % match.group(1) join_sep = ';\n%s' % match.group(1)
@@ -128,7 +127,7 @@ def handle_typedefs(match):
return '%s%s\n' \ return '%s%s\n' \
% ( % (
match.group(1) match.group(1)
, string.join(map(string.strip, string.split(match.group(2), ';')), join_sep) , join_sep.join(list(map(str.strip, str.split(match.group(2), ';'))))
) )
def fix_angle_brackets( match ): def fix_angle_brackets( match ):

View File

@@ -57,10 +57,10 @@ def process_all( root, boost_root, dst_dir, mode ):
def main( all_modes, src_dir, dst_dir ): def main( all_modes, src_dir, dst_dir ):
if len( sys.argv ) < 2: if len( sys.argv ) < 2:
print "\nUsage:\n\t %s <mode> <boost_root> [<source_file>]" % os.path.basename( sys.argv[0] ) print("\nUsage:\n\t %s <mode> <boost_root> [<source_file>]" % os.path.basename( sys.argv[0] ))
print "\nPurpose:\n\t updates preprocessed version(s) of the header(s) in \"%s\" directory" % dst_dir print("\nPurpose:\n\t updates preprocessed version(s) of the header(s) in \"%s\" directory" % dst_dir)
print "\nExample:\n\t the following command will re-generate and update all 'apply.hpp' headers:" print("\nExample:\n\t the following command will re-generate and update all 'apply.hpp' headers:")
print "\n\t\t %s all f:\\cvs\\boost apply.cpp" % os.path.basename( sys.argv[0] ) print("\n\t\t %s all f:\\cvs\\boost apply.cpp" % os.path.basename( sys.argv[0] ))
sys.exit( -1 ) sys.exit( -1 )
if sys.argv[1] == "all": if sys.argv[1] == "all":