mirror of
https://github.com/open-source-parsers/jsoncpp.git
synced 2025-01-06 00:31:10 +01:00
allow python3
This commit is contained in:
parent
0dc03d0848
commit
83b43caf8e
140
amalgamate.py
140
amalgamate.py
@ -15,36 +15,36 @@ class AmalgamationFile:
|
|||||||
self.blocks = []
|
self.blocks = []
|
||||||
|
|
||||||
def add_text( self, text ):
|
def add_text( self, text ):
|
||||||
if not text.endswith( '\n' ):
|
if not text.endswith( "\n" ):
|
||||||
text += '\n'
|
text += "\n"
|
||||||
self.blocks.append( text )
|
self.blocks.append( text )
|
||||||
|
|
||||||
def add_file( self, relative_input_path, wrap_in_comment=False ):
|
def add_file( self, relative_input_path, wrap_in_comment=False ):
|
||||||
def add_marker( prefix ):
|
def add_marker( prefix ):
|
||||||
self.add_text( '' )
|
self.add_text( "" )
|
||||||
self.add_text( '// ' + '/'*70 )
|
self.add_text( "// " + "/"*70 )
|
||||||
self.add_text( '// %s of content of file: %s' % (prefix, relative_input_path.replace('\\','/')) )
|
self.add_text( "// %s of content of file: %s" % (prefix, relative_input_path.replace("\\","/")) )
|
||||||
self.add_text( '// ' + '/'*70 )
|
self.add_text( "// " + "/"*70 )
|
||||||
self.add_text( '' )
|
self.add_text( "" )
|
||||||
add_marker( 'Beginning' )
|
add_marker( "Beginning" )
|
||||||
f = open( os.path.join( self.top_dir, relative_input_path ), 'rt' )
|
f = open( os.path.join( self.top_dir, relative_input_path ), "rt" )
|
||||||
content = f.read()
|
content = f.read()
|
||||||
if wrap_in_comment:
|
if wrap_in_comment:
|
||||||
content = '/*\n' + content + '\n*/'
|
content = "/*\n" + content + "\n*/"
|
||||||
self.add_text( content )
|
self.add_text( content )
|
||||||
f.close()
|
f.close()
|
||||||
add_marker( 'End' )
|
add_marker( "End" )
|
||||||
self.add_text( '\n\n\n\n' )
|
self.add_text( "\n\n\n\n" )
|
||||||
|
|
||||||
def get_value( self ):
|
def get_value( self ):
|
||||||
return ''.join( self.blocks ).replace('\r\n','\n')
|
return "".join( self.blocks ).replace("\r\n","\n")
|
||||||
|
|
||||||
def write_to( self, output_path ):
|
def write_to( self, output_path ):
|
||||||
output_dir = os.path.dirname( output_path )
|
output_dir = os.path.dirname( output_path )
|
||||||
if output_dir and not os.path.isdir( output_dir ):
|
if output_dir and not os.path.isdir( output_dir ):
|
||||||
os.makedirs( output_dir )
|
os.makedirs( output_dir )
|
||||||
f = open( output_path, 'wb' )
|
f = open( output_path, "wb" )
|
||||||
f.write( self.get_value() )
|
f.write( bytes(self.get_value(), 'UTF-8') )
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
def amalgamate_source( source_top_dir=None,
|
def amalgamate_source( source_top_dir=None,
|
||||||
@ -56,69 +56,69 @@ def amalgamate_source( source_top_dir=None,
|
|||||||
target_source_path: output .cpp path
|
target_source_path: output .cpp path
|
||||||
header_include_path: generated header path relative to target_source_path.
|
header_include_path: generated header path relative to target_source_path.
|
||||||
"""
|
"""
|
||||||
print 'Amalgating header...'
|
print ("Amalgating header...")
|
||||||
header = AmalgamationFile( source_top_dir )
|
header = AmalgamationFile( source_top_dir )
|
||||||
header.add_text( '/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).' )
|
header.add_text( "/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/)." )
|
||||||
header.add_text( '/// It is intented to be used with #include <%s>' % header_include_path )
|
header.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )
|
||||||
header.add_file( 'LICENSE', wrap_in_comment=True )
|
header.add_file( "LICENSE", wrap_in_comment=True )
|
||||||
header.add_text( '#ifndef JSON_AMALGATED_H_INCLUDED' )
|
header.add_text( "#ifndef JSON_AMALGATED_H_INCLUDED" )
|
||||||
header.add_text( '# define JSON_AMALGATED_H_INCLUDED' )
|
header.add_text( "# define JSON_AMALGATED_H_INCLUDED" )
|
||||||
header.add_text( '/// If defined, indicates that the source file is amalgated' )
|
header.add_text( "/// If defined, indicates that the source file is amalgated" )
|
||||||
header.add_text( '/// to prevent private header inclusion.' )
|
header.add_text( "/// to prevent private header inclusion." )
|
||||||
header.add_text( '#define JSON_IS_AMALGAMATION' )
|
header.add_text( "#define JSON_IS_AMALGAMATION" )
|
||||||
#header.add_file( 'include/json/version.h' )
|
header.add_file( "include/json/version.h" )
|
||||||
header.add_file( 'include/json/config.h' )
|
header.add_file( "include/json/config.h" )
|
||||||
header.add_file( 'include/json/forwards.h' )
|
header.add_file( "include/json/forwards.h" )
|
||||||
header.add_file( 'include/json/features.h' )
|
header.add_file( "include/json/features.h" )
|
||||||
header.add_file( 'include/json/value.h' )
|
header.add_file( "include/json/value.h" )
|
||||||
header.add_file( 'include/json/reader.h' )
|
header.add_file( "include/json/reader.h" )
|
||||||
header.add_file( 'include/json/writer.h' )
|
header.add_file( "include/json/writer.h" )
|
||||||
header.add_file( 'include/json/assertions.h' )
|
header.add_file( "include/json/assertions.h" )
|
||||||
header.add_text( '#endif //ifndef JSON_AMALGATED_H_INCLUDED' )
|
header.add_text( "#endif //ifndef JSON_AMALGATED_H_INCLUDED" )
|
||||||
|
|
||||||
target_header_path = os.path.join( os.path.dirname(target_source_path), header_include_path )
|
target_header_path = os.path.join( os.path.dirname(target_source_path), header_include_path )
|
||||||
print 'Writing amalgated header to %r' % target_header_path
|
print ("Writing amalgated header to %r" % target_header_path)
|
||||||
header.write_to( target_header_path )
|
header.write_to( target_header_path )
|
||||||
|
|
||||||
base, ext = os.path.splitext( header_include_path )
|
base, ext = os.path.splitext( header_include_path )
|
||||||
forward_header_include_path = base + '-forwards' + ext
|
forward_header_include_path = base + "-forwards" + ext
|
||||||
print 'Amalgating forward header...'
|
print ("Amalgating forward header...")
|
||||||
header = AmalgamationFile( source_top_dir )
|
header = AmalgamationFile( source_top_dir )
|
||||||
header.add_text( '/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/).' )
|
header.add_text( "/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/)." )
|
||||||
header.add_text( '/// It is intented to be used with #include <%s>' % forward_header_include_path )
|
header.add_text( "/// It is intented to be used with #include <%s>" % forward_header_include_path )
|
||||||
header.add_text( '/// This header provides forward declaration for all JsonCpp types.' )
|
header.add_text( "/// This header provides forward declaration for all JsonCpp types." )
|
||||||
header.add_file( 'LICENSE', wrap_in_comment=True )
|
header.add_file( "LICENSE", wrap_in_comment=True )
|
||||||
header.add_text( '#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED' )
|
header.add_text( "#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED" )
|
||||||
header.add_text( '# define JSON_FORWARD_AMALGATED_H_INCLUDED' )
|
header.add_text( "# define JSON_FORWARD_AMALGATED_H_INCLUDED" )
|
||||||
header.add_text( '/// If defined, indicates that the source file is amalgated' )
|
header.add_text( "/// If defined, indicates that the source file is amalgated" )
|
||||||
header.add_text( '/// to prevent private header inclusion.' )
|
header.add_text( "/// to prevent private header inclusion." )
|
||||||
header.add_text( '#define JSON_IS_AMALGAMATION' )
|
header.add_text( "#define JSON_IS_AMALGAMATION" )
|
||||||
header.add_file( 'include/json/config.h' )
|
header.add_file( "include/json/config.h" )
|
||||||
header.add_file( 'include/json/forwards.h' )
|
header.add_file( "include/json/forwards.h" )
|
||||||
header.add_text( '#endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED' )
|
header.add_text( "#endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED" )
|
||||||
|
|
||||||
target_forward_header_path = os.path.join( os.path.dirname(target_source_path),
|
target_forward_header_path = os.path.join( os.path.dirname(target_source_path),
|
||||||
forward_header_include_path )
|
forward_header_include_path )
|
||||||
print 'Writing amalgated forward header to %r' % target_forward_header_path
|
print ("Writing amalgated forward header to %r" % target_forward_header_path)
|
||||||
header.write_to( target_forward_header_path )
|
header.write_to( target_forward_header_path )
|
||||||
|
|
||||||
print 'Amalgating source...'
|
print ("Amalgating source...")
|
||||||
source = AmalgamationFile( source_top_dir )
|
source = AmalgamationFile( source_top_dir )
|
||||||
source.add_text( '/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/).' )
|
source.add_text( "/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/)." )
|
||||||
source.add_text( '/// It is intented to be used with #include "%s"' % target_source_path )
|
source.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )
|
||||||
source.add_file( 'LICENSE', wrap_in_comment=True )
|
source.add_file( "LICENSE", wrap_in_comment=True )
|
||||||
source.add_text( '' )
|
source.add_text( "" )
|
||||||
source.add_text( '#include "%s"' % header_include_path )
|
source.add_text( "#include <%s>" % header_include_path )
|
||||||
source.add_text( '' )
|
source.add_text( "" )
|
||||||
lib_json = 'src/lib_json'
|
lib_json = "src/lib_json"
|
||||||
source.add_file( os.path.join(lib_json, 'json_tool.h') )
|
source.add_file( os.path.join(lib_json, "json_tool.h") )
|
||||||
source.add_file( os.path.join(lib_json, 'json_reader.cpp') )
|
source.add_file( os.path.join(lib_json, "json_reader.cpp") )
|
||||||
source.add_file( os.path.join(lib_json, 'json_batchallocator.h') )
|
source.add_file( os.path.join(lib_json, "json_batchallocator.h") )
|
||||||
source.add_file( os.path.join(lib_json, 'json_valueiterator.inl') )
|
source.add_file( os.path.join(lib_json, "json_valueiterator.inl") )
|
||||||
source.add_file( os.path.join(lib_json, 'json_value.cpp') )
|
source.add_file( os.path.join(lib_json, "json_value.cpp") )
|
||||||
source.add_file( os.path.join(lib_json, 'json_writer.cpp') )
|
source.add_file( os.path.join(lib_json, "json_writer.cpp") )
|
||||||
|
|
||||||
print 'Writing amalgated source to %r' % target_source_path
|
print ("Writing amalgated source to %r" % target_source_path)
|
||||||
source.write_to( target_source_path )
|
source.write_to( target_source_path )
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -128,11 +128,11 @@ Generate a single amalgated source and header file from the sources.
|
|||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
parser = OptionParser(usage=usage)
|
parser = OptionParser(usage=usage)
|
||||||
parser.allow_interspersed_args = False
|
parser.allow_interspersed_args = False
|
||||||
parser.add_option('-s', '--source', dest="target_source_path", action='store', default='dist/jsoncpp.cpp',
|
parser.add_option("-s", "--source", dest="target_source_path", action="store", default="dist/jsoncpp.cpp",
|
||||||
help="""Output .cpp source path. [Default: %default]""")
|
help="""Output .cpp source path. [Default: %default]""")
|
||||||
parser.add_option('-i', '--include', dest="header_include_path", action='store', default='json/json.h',
|
parser.add_option("-i", "--include", dest="header_include_path", action="store", default="json/json.h",
|
||||||
help="""Header include path. Used to include the header from the amalgated source file. [Default: %default]""")
|
help="""Header include path. Used to include the header from the amalgated source file. [Default: %default]""")
|
||||||
parser.add_option('-t', '--top-dir', dest="top_dir", action='store', default=os.getcwd(),
|
parser.add_option("-t", "--top-dir", dest="top_dir", action="store", default=os.getcwd(),
|
||||||
help="""Source top-directory. [Default: %default]""")
|
help="""Source top-directory. [Default: %default]""")
|
||||||
parser.enable_interspersed_args()
|
parser.enable_interspersed_args()
|
||||||
options, args = parser.parse_args()
|
options, args = parser.parse_args()
|
||||||
@ -141,10 +141,10 @@ Generate a single amalgated source and header file from the sources.
|
|||||||
target_source_path=options.target_source_path,
|
target_source_path=options.target_source_path,
|
||||||
header_include_path=options.header_include_path )
|
header_include_path=options.header_include_path )
|
||||||
if msg:
|
if msg:
|
||||||
sys.stderr.write( msg + '\n' )
|
sys.stderr.write( msg + "\n" )
|
||||||
sys.exit( 1 )
|
sys.exit( 1 )
|
||||||
else:
|
else:
|
||||||
print 'Source succesfully amalagated'
|
print ("Source succesfully amalagated")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
Loading…
Reference in New Issue
Block a user