Skip to content

Commit 83b43ca

Browse files
jvanbrueggecdunn2001
authored andcommitted
allow python3
1 parent 0dc03d0 commit 83b43ca

File tree

1 file changed

+72
-72
lines changed

1 file changed

+72
-72
lines changed

amalgamate.py

Lines changed: 72 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,36 @@ def __init__( self, top_dir ):
1515
self.blocks = []
1616

1717
def add_text( self, text ):
18-
if not text.endswith( '\n' ):
19-
text += '\n'
18+
if not text.endswith( "\n" ):
19+
text += "\n"
2020
self.blocks.append( text )
2121

2222
def add_file( self, relative_input_path, wrap_in_comment=False ):
2323
def add_marker( prefix ):
24-
self.add_text( '' )
25-
self.add_text( '// ' + '/'*70 )
26-
self.add_text( '// %s of content of file: %s' % (prefix, relative_input_path.replace('\\','/')) )
27-
self.add_text( '// ' + '/'*70 )
28-
self.add_text( '' )
29-
add_marker( 'Beginning' )
30-
f = open( os.path.join( self.top_dir, relative_input_path ), 'rt' )
24+
self.add_text( "" )
25+
self.add_text( "// " + "/"*70 )
26+
self.add_text( "// %s of content of file: %s" % (prefix, relative_input_path.replace("\\","/")) )
27+
self.add_text( "// " + "/"*70 )
28+
self.add_text( "" )
29+
add_marker( "Beginning" )
30+
f = open( os.path.join( self.top_dir, relative_input_path ), "rt" )
3131
content = f.read()
3232
if wrap_in_comment:
33-
content = '/*\n' + content + '\n*/'
33+
content = "/*\n" + content + "\n*/"
3434
self.add_text( content )
3535
f.close()
36-
add_marker( 'End' )
37-
self.add_text( '\n\n\n\n' )
36+
add_marker( "End" )
37+
self.add_text( "\n\n\n\n" )
3838

3939
def get_value( self ):
40-
return ''.join( self.blocks ).replace('\r\n','\n')
40+
return "".join( self.blocks ).replace("\r\n","\n")
4141

4242
def write_to( self, output_path ):
4343
output_dir = os.path.dirname( output_path )
4444
if output_dir and not os.path.isdir( output_dir ):
4545
os.makedirs( output_dir )
46-
f = open( output_path, 'wb' )
47-
f.write( self.get_value() )
46+
f = open( output_path, "wb" )
47+
f.write( bytes(self.get_value(), 'UTF-8') )
4848
f.close()
4949

5050
def amalgamate_source( source_top_dir=None,
@@ -56,69 +56,69 @@ def amalgamate_source( source_top_dir=None,
5656
target_source_path: output .cpp path
5757
header_include_path: generated header path relative to target_source_path.
5858
"""
59-
print 'Amalgating header...'
59+
print ("Amalgating header...")
6060
header = AmalgamationFile( source_top_dir )
61-
header.add_text( '/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/).' )
62-
header.add_text( '/// It is intented to be used with #include <%s>' % header_include_path )
63-
header.add_file( 'LICENSE', wrap_in_comment=True )
64-
header.add_text( '#ifndef JSON_AMALGATED_H_INCLUDED' )
65-
header.add_text( '# define JSON_AMALGATED_H_INCLUDED' )
66-
header.add_text( '/// If defined, indicates that the source file is amalgated' )
67-
header.add_text( '/// to prevent private header inclusion.' )
68-
header.add_text( '#define JSON_IS_AMALGAMATION' )
69-
#header.add_file( 'include/json/version.h' )
70-
header.add_file( 'include/json/config.h' )
71-
header.add_file( 'include/json/forwards.h' )
72-
header.add_file( 'include/json/features.h' )
73-
header.add_file( 'include/json/value.h' )
74-
header.add_file( 'include/json/reader.h' )
75-
header.add_file( 'include/json/writer.h' )
76-
header.add_file( 'include/json/assertions.h' )
77-
header.add_text( '#endif //ifndef JSON_AMALGATED_H_INCLUDED' )
61+
header.add_text( "/// Json-cpp amalgated header (http://jsoncpp.sourceforge.net/)." )
62+
header.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )
63+
header.add_file( "LICENSE", wrap_in_comment=True )
64+
header.add_text( "#ifndef JSON_AMALGATED_H_INCLUDED" )
65+
header.add_text( "# define JSON_AMALGATED_H_INCLUDED" )
66+
header.add_text( "/// If defined, indicates that the source file is amalgated" )
67+
header.add_text( "/// to prevent private header inclusion." )
68+
header.add_text( "#define JSON_IS_AMALGAMATION" )
69+
header.add_file( "include/json/version.h" )
70+
header.add_file( "include/json/config.h" )
71+
header.add_file( "include/json/forwards.h" )
72+
header.add_file( "include/json/features.h" )
73+
header.add_file( "include/json/value.h" )
74+
header.add_file( "include/json/reader.h" )
75+
header.add_file( "include/json/writer.h" )
76+
header.add_file( "include/json/assertions.h" )
77+
header.add_text( "#endif //ifndef JSON_AMALGATED_H_INCLUDED" )
7878

7979
target_header_path = os.path.join( os.path.dirname(target_source_path), header_include_path )
80-
print 'Writing amalgated header to %r' % target_header_path
80+
print ("Writing amalgated header to %r" % target_header_path)
8181
header.write_to( target_header_path )
8282

8383
base, ext = os.path.splitext( header_include_path )
84-
forward_header_include_path = base + '-forwards' + ext
85-
print 'Amalgating forward header...'
84+
forward_header_include_path = base + "-forwards" + ext
85+
print ("Amalgating forward header...")
8686
header = AmalgamationFile( source_top_dir )
87-
header.add_text( '/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/).' )
88-
header.add_text( '/// It is intented to be used with #include <%s>' % forward_header_include_path )
89-
header.add_text( '/// This header provides forward declaration for all JsonCpp types.' )
90-
header.add_file( 'LICENSE', wrap_in_comment=True )
91-
header.add_text( '#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED' )
92-
header.add_text( '# define JSON_FORWARD_AMALGATED_H_INCLUDED' )
93-
header.add_text( '/// If defined, indicates that the source file is amalgated' )
94-
header.add_text( '/// to prevent private header inclusion.' )
95-
header.add_text( '#define JSON_IS_AMALGAMATION' )
96-
header.add_file( 'include/json/config.h' )
97-
header.add_file( 'include/json/forwards.h' )
98-
header.add_text( '#endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED' )
87+
header.add_text( "/// Json-cpp amalgated forward header (http://jsoncpp.sourceforge.net/)." )
88+
header.add_text( "/// It is intented to be used with #include <%s>" % forward_header_include_path )
89+
header.add_text( "/// This header provides forward declaration for all JsonCpp types." )
90+
header.add_file( "LICENSE", wrap_in_comment=True )
91+
header.add_text( "#ifndef JSON_FORWARD_AMALGATED_H_INCLUDED" )
92+
header.add_text( "# define JSON_FORWARD_AMALGATED_H_INCLUDED" )
93+
header.add_text( "/// If defined, indicates that the source file is amalgated" )
94+
header.add_text( "/// to prevent private header inclusion." )
95+
header.add_text( "#define JSON_IS_AMALGAMATION" )
96+
header.add_file( "include/json/config.h" )
97+
header.add_file( "include/json/forwards.h" )
98+
header.add_text( "#endif //ifndef JSON_FORWARD_AMALGATED_H_INCLUDED" )
9999

100100
target_forward_header_path = os.path.join( os.path.dirname(target_source_path),
101101
forward_header_include_path )
102-
print 'Writing amalgated forward header to %r' % target_forward_header_path
102+
print ("Writing amalgated forward header to %r" % target_forward_header_path)
103103
header.write_to( target_forward_header_path )
104104

105-
print 'Amalgating source...'
105+
print ("Amalgating source...")
106106
source = AmalgamationFile( source_top_dir )
107-
source.add_text( '/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/).' )
108-
source.add_text( '/// It is intented to be used with #include "%s"' % target_source_path )
109-
source.add_file( 'LICENSE', wrap_in_comment=True )
110-
source.add_text( '' )
111-
source.add_text( '#include "%s"' % header_include_path )
112-
source.add_text( '' )
113-
lib_json = 'src/lib_json'
114-
source.add_file( os.path.join(lib_json, 'json_tool.h') )
115-
source.add_file( os.path.join(lib_json, 'json_reader.cpp') )
116-
source.add_file( os.path.join(lib_json, 'json_batchallocator.h') )
117-
source.add_file( os.path.join(lib_json, 'json_valueiterator.inl') )
118-
source.add_file( os.path.join(lib_json, 'json_value.cpp') )
119-
source.add_file( os.path.join(lib_json, 'json_writer.cpp') )
120-
121-
print 'Writing amalgated source to %r' % target_source_path
107+
source.add_text( "/// Json-cpp amalgated source (http://jsoncpp.sourceforge.net/)." )
108+
source.add_text( "/// It is intented to be used with #include <%s>" % header_include_path )
109+
source.add_file( "LICENSE", wrap_in_comment=True )
110+
source.add_text( "" )
111+
source.add_text( "#include <%s>" % header_include_path )
112+
source.add_text( "" )
113+
lib_json = "src/lib_json"
114+
source.add_file( os.path.join(lib_json, "json_tool.h") )
115+
source.add_file( os.path.join(lib_json, "json_reader.cpp") )
116+
source.add_file( os.path.join(lib_json, "json_batchallocator.h") )
117+
source.add_file( os.path.join(lib_json, "json_valueiterator.inl") )
118+
source.add_file( os.path.join(lib_json, "json_value.cpp") )
119+
source.add_file( os.path.join(lib_json, "json_writer.cpp") )
120+
121+
print ("Writing amalgated source to %r" % target_source_path)
122122
source.write_to( target_source_path )
123123

124124
def main():
@@ -128,11 +128,11 @@ def main():
128128
from optparse import OptionParser
129129
parser = OptionParser(usage=usage)
130130
parser.allow_interspersed_args = False
131-
parser.add_option('-s', '--source', dest="target_source_path", action='store', default='dist/jsoncpp.cpp',
131+
parser.add_option("-s", "--source", dest="target_source_path", action="store", default="dist/jsoncpp.cpp",
132132
help="""Output .cpp source path. [Default: %default]""")
133-
parser.add_option('-i', '--include', dest="header_include_path", action='store', default='json/json.h',
133+
parser.add_option("-i", "--include", dest="header_include_path", action="store", default="json/json.h",
134134
help="""Header include path. Used to include the header from the amalgated source file. [Default: %default]""")
135-
parser.add_option('-t', '--top-dir', dest="top_dir", action='store', default=os.getcwd(),
135+
parser.add_option("-t", "--top-dir", dest="top_dir", action="store", default=os.getcwd(),
136136
help="""Source top-directory. [Default: %default]""")
137137
parser.enable_interspersed_args()
138138
options, args = parser.parse_args()
@@ -141,10 +141,10 @@ def main():
141141
target_source_path=options.target_source_path,
142142
header_include_path=options.header_include_path )
143143
if msg:
144-
sys.stderr.write( msg + '\n' )
144+
sys.stderr.write( msg + "\n" )
145145
sys.exit( 1 )
146146
else:
147-
print 'Source succesfully amalagated'
148-
149-
if __name__ == '__main__':
147+
print ("Source succesfully amalagated")
148+
149+
if __name__ == "__main__":
150150
main()

0 commit comments

Comments
 (0)