mirror of
https://github.com/boostorg/mpl.git
synced 2025-08-01 05:44:37 +02:00
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:
@@ -118,6 +118,11 @@ def to_existing_absolute_path(string):
|
||||
def main():
|
||||
"""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.
|
||||
sourceDir = current_boost_dir()
|
||||
if sourceDir == None:
|
||||
@@ -150,19 +155,19 @@ def main():
|
||||
|
||||
# Some verbose debug output.
|
||||
if args.verbose:
|
||||
print "Arguments extracted from command-line:"
|
||||
print " verbose = ", args.verbose
|
||||
print " source directory = ", args.sourceDir
|
||||
print " num elements = ", args.numElements
|
||||
print " sequence type = ", args.seqType
|
||||
print " want: vector = ", args.want_vector
|
||||
print " want: list = ", args.want_list
|
||||
print " want: set = ", args.want_set
|
||||
print " want: map = ", args.want_map
|
||||
print("Arguments extracted from command-line:")
|
||||
print(" verbose = ", args.verbose)
|
||||
print(" source directory = ", args.sourceDir)
|
||||
print(" num elements = ", args.numElements)
|
||||
print(" sequence type = ", args.seqType)
|
||||
print(" want: vector = ", args.want_vector)
|
||||
print(" want: list = ", args.want_list)
|
||||
print(" want: set = ", args.want_set)
|
||||
print(" want: map = ", args.want_map)
|
||||
|
||||
# Verify that we received any source-directory.
|
||||
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)
|
||||
|
||||
# The directories for header- and source files of Boost.MPL.
|
||||
@@ -177,13 +182,13 @@ def main():
|
||||
sourceDir = os.path.join( args.sourceDir, "preprocessed" )
|
||||
if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ):
|
||||
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)
|
||||
|
||||
# Some verbose debug output.
|
||||
if args.verbose:
|
||||
print "Chosen header-directory: ", headerDir
|
||||
print "Chosen source-directory: ", sourceDir
|
||||
print("Chosen header-directory: ", headerDir)
|
||||
print("Chosen source-directory: ", sourceDir)
|
||||
|
||||
# Create list of containers for which files shall be pre-processed.
|
||||
containers = []
|
||||
@@ -196,23 +201,23 @@ def main():
|
||||
if args.want_map:
|
||||
containers.append('map')
|
||||
if containers == []:
|
||||
print "Nothing to do."
|
||||
print "(Why did you prevent generating pre-processed headers for all Boost.MPL container types?)"
|
||||
print("Nothing to do.")
|
||||
print("(Why did you prevent generating pre-processed headers for all Boost.MPL container types?)")
|
||||
sys.exit(0)
|
||||
|
||||
# Possibly fix the header-comments of input-files needed for pre-processing.
|
||||
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)
|
||||
if needFixing:
|
||||
if args.verbose:
|
||||
print "Fixing of some input-files prior to pre-processing is needed."
|
||||
print "Will fix them now!"
|
||||
print("Fixing of some input-files prior to pre-processing is needed.")
|
||||
print("Will fix them now!")
|
||||
fixmpl.fix_input_files(headerDir, sourceDir, containers, args.seqType, args.verbose)
|
||||
|
||||
# Some verbose debug output.
|
||||
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.
|
||||
if args.seqType == "both" or args.seqType == "numbered":
|
||||
@@ -226,24 +231,24 @@ def main():
|
||||
if args.seqType == "both" or args.seqType == "numbered":
|
||||
if args.want_vector:
|
||||
if args.verbose:
|
||||
print "Pre-process headers for Boost.MPL numbered vectors."
|
||||
os.system( "python " + os.path.join( sourceDir, "preprocess_vector.py" ) + " all " + args.sourceDir )
|
||||
print("Pre-process headers for Boost.MPL numbered vectors.")
|
||||
os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_vector.py" ) + " all " + args.sourceDir )
|
||||
if args.want_list:
|
||||
if args.verbose:
|
||||
print "Pre-process headers for Boost.MPL numbered lists."
|
||||
os.system( "python " + os.path.join( sourceDir, "preprocess_list.py" ) + " all " + args.sourceDir )
|
||||
print("Pre-process headers for Boost.MPL numbered lists.")
|
||||
os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_list.py" ) + " all " + args.sourceDir )
|
||||
if args.want_set:
|
||||
if args.verbose:
|
||||
print "Pre-process headers for Boost.MPL numbered sets."
|
||||
os.system( "python " + os.path.join( sourceDir, "preprocess_set.py" ) + " all " + args.sourceDir )
|
||||
print("Pre-process headers for Boost.MPL numbered sets.")
|
||||
os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_set.py" ) + " all " + args.sourceDir )
|
||||
if args.want_map:
|
||||
if args.verbose:
|
||||
print "Pre-process headers for Boost.MPL numbered maps."
|
||||
os.system( "python " + os.path.join( sourceDir, "preprocess_map.py" ) + " all " + args.sourceDir )
|
||||
print("Pre-process headers for Boost.MPL numbered maps.")
|
||||
os.system( python_executable + " " + os.path.join( sourceDir, "preprocess_map.py" ) + " all " + args.sourceDir )
|
||||
if args.seqType == "both" or args.seqType == "variadic":
|
||||
if args.verbose:
|
||||
print "Pre-process headers for Boost.MPL variadic containers."
|
||||
os.system( "python " + os.path.join( sourceDir, "preprocess.py" ) + " all " + args.sourceDir )
|
||||
print("Pre-process headers for Boost.MPL variadic containers.")
|
||||
os.system( python_executable + " " + os.path.join( sourceDir, "preprocess.py" ) + " all " + args.sourceDir )
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@@ -66,26 +66,26 @@ def check_input_files(headerDir, sourceDir, containers=['vector', 'list', 'set',
|
||||
result1 = False
|
||||
if seqType == "both" or seqType == "variadic":
|
||||
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)
|
||||
if verbose:
|
||||
if result1:
|
||||
print " At least one input file needs fixing!"
|
||||
print(" At least one input file needs fixing!")
|
||||
else:
|
||||
print " No input file needs fixing!"
|
||||
print(" No input file needs fixing!")
|
||||
# Check the input files for containers in their numbered form.
|
||||
result2 = False
|
||||
result3 = False
|
||||
if seqType == "both" or seqType == "numbered":
|
||||
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)
|
||||
result3 = check_input_files_for_numbered_seq(sourceDir, ".cpp", containers)
|
||||
if verbose:
|
||||
if result2 or result3:
|
||||
print " At least one input file needs fixing!"
|
||||
print(" At least one input file needs fixing!")
|
||||
else:
|
||||
print " No input file needs fixing!"
|
||||
print(" No input file needs fixing!")
|
||||
# Return result.
|
||||
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.
|
||||
if seqType == "both" or seqType == "variadic":
|
||||
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 the input files for containers in their numbered form.
|
||||
if seqType == "both" or seqType == "numbered":
|
||||
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(sourceDir, ".cpp", timestamp, containers)
|
||||
|
||||
@@ -164,10 +164,10 @@ def main():
|
||||
|
||||
# Some verbose debug output.
|
||||
if args.verbose:
|
||||
print "Arguments extracted from command-line:"
|
||||
print " verbose = ", args.verbose
|
||||
print " check-only = ", args.checkonly
|
||||
print " source directory = ", args.sourceDir
|
||||
print("Arguments extracted from command-line:")
|
||||
print(" verbose = ", args.verbose)
|
||||
print(" check-only = ", args.checkonly)
|
||||
print(" source directory = ", args.sourceDir)
|
||||
|
||||
# The directories for header- and source files of Boost.MPL.
|
||||
# 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" )
|
||||
if not os.path.exists( headerDir ) or not os.path.exists( sourceDir ):
|
||||
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)
|
||||
|
||||
# Some verbose debug output.
|
||||
if args.verbose:
|
||||
print "Chosen header-directory: ", headerDir
|
||||
print "Chosen source-directory: ", sourceDir
|
||||
print("Chosen header-directory: ", headerDir)
|
||||
print("Chosen source-directory: ", sourceDir)
|
||||
|
||||
if args.checkonly:
|
||||
# Check input files for generating pre-processed headers.
|
||||
result = check_input_files(headerDir, sourceDir, verbose = args.verbose)
|
||||
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:
|
||||
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:
|
||||
# Fix input files for generating pre-processed headers.
|
||||
fix_input_files(headerDir, sourceDir, verbose = args.verbose)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
# $Revision$
|
||||
|
||||
import fileinput
|
||||
import functools
|
||||
import os
|
||||
import re
|
||||
import string
|
||||
@@ -22,22 +23,21 @@ max_len = 79
|
||||
ident = 4
|
||||
|
||||
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 ):
|
||||
if sep == ',' and string.find( text, '<' ) != -1:
|
||||
if sep == ',' and str.find( text, '<' ) != -1:
|
||||
sep = '%s ' % sep
|
||||
|
||||
words = string.split(
|
||||
string.join( string.split( text ), ' ' )
|
||||
words = str.split(
|
||||
' '.join( str.split( text ) )
|
||||
, sep
|
||||
)
|
||||
|
||||
s = ' ' * limits[0]
|
||||
max_len = limits[1]
|
||||
return '%s\n%s' \
|
||||
% (
|
||||
reduce(
|
||||
functools.reduce(
|
||||
lambda t,w,max_len=max_len,s=s,sep=sep:
|
||||
if_else(t[1] + len(w) < max_len
|
||||
, ('%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 ):
|
||||
if re.compile('^\s*(typedef|struct|static)\s+.*?$').match(match.group(0)):
|
||||
return match.group(0)
|
||||
|
||||
return '%s'\
|
||||
% block_format(
|
||||
(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)))
|
||||
, match.group(4)
|
||||
)
|
||||
, string.replace(match.group(1),',',' ')
|
||||
, str.replace(match.group(1),',',' ')
|
||||
, match.group(9)
|
||||
)
|
||||
|
||||
@@ -98,18 +97,18 @@ def handle_simple_list(match):
|
||||
return if_else(single_arg,'%s<%s>','%s< %s >') %\
|
||||
(
|
||||
match.group(1)
|
||||
, string.join(string.split(match.group(2)), '')
|
||||
, ''.join(str.split(match.group(2)))
|
||||
)
|
||||
|
||||
def handle_static(match):
|
||||
if len(match.group(0)) < max_len:
|
||||
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' %\
|
||||
(
|
||||
match.group(1)
|
||||
, string.join(string.split(match.group(2)), ' ')
|
||||
, ' '.join(str.split(match.group(2)))
|
||||
, block_format(
|
||||
(nearest_ident_pos(match.group(1))+ident,max_len)
|
||||
, match.group(4)
|
||||
@@ -120,7 +119,7 @@ def handle_static(match):
|
||||
)
|
||||
|
||||
def handle_typedefs(match):
|
||||
if string.count(match.group(2), ';') == 1:
|
||||
if str.count(match.group(2), ';') == 1:
|
||||
return match.group(0)
|
||||
|
||||
join_sep = ';\n%s' % match.group(1)
|
||||
@@ -128,7 +127,7 @@ def handle_typedefs(match):
|
||||
return '%s%s\n' \
|
||||
% (
|
||||
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 ):
|
||||
|
@@ -57,10 +57,10 @@ def process_all( root, boost_root, dst_dir, mode ):
|
||||
|
||||
def main( all_modes, src_dir, dst_dir ):
|
||||
if len( sys.argv ) < 2:
|
||||
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 "\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("\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("\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] ))
|
||||
sys.exit( -1 )
|
||||
|
||||
if sys.argv[1] == "all":
|
||||
|
Reference in New Issue
Block a user