@@ -15,36 +15,36 @@ def __init__( self, top_dir ):
15
15
self .blocks = []
16
16
17
17
def add_text ( self , text ):
18
- if not text .endswith ( ' \n ' ):
19
- text += ' \n '
18
+ if not text .endswith ( " \n " ):
19
+ text += " \n "
20
20
self .blocks .append ( text )
21
21
22
22
def add_file ( self , relative_input_path , wrap_in_comment = False ):
23
23
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" )
31
31
content = f .read ()
32
32
if wrap_in_comment :
33
- content = ' /*\n ' + content + ' \n */'
33
+ content = " /*\n " + content + " \n */"
34
34
self .add_text ( content )
35
35
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 " )
38
38
39
39
def get_value ( self ):
40
- return '' .join ( self .blocks ).replace (' \r \n ' , ' \n ' )
40
+ return "" .join ( self .blocks ).replace (" \r \n " , " \n " )
41
41
42
42
def write_to ( self , output_path ):
43
43
output_dir = os .path .dirname ( output_path )
44
44
if output_dir and not os .path .isdir ( output_dir ):
45
45
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' ) )
48
48
f .close ()
49
49
50
50
def amalgamate_source ( source_top_dir = None ,
@@ -56,69 +56,69 @@ def amalgamate_source( source_top_dir=None,
56
56
target_source_path: output .cpp path
57
57
header_include_path: generated header path relative to target_source_path.
58
58
"""
59
- print ' Amalgating header...'
59
+ print ( " Amalgating header..." )
60
60
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" )
78
78
79
79
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 )
81
81
header .write_to ( target_header_path )
82
82
83
83
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..." )
86
86
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" )
99
99
100
100
target_forward_header_path = os .path .join ( os .path .dirname (target_source_path ),
101
101
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 )
103
103
header .write_to ( target_forward_header_path )
104
104
105
- print ' Amalgating source...'
105
+ print ( " Amalgating source..." )
106
106
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 )
122
122
source .write_to ( target_source_path )
123
123
124
124
def main ():
@@ -128,11 +128,11 @@ def main():
128
128
from optparse import OptionParser
129
129
parser = OptionParser (usage = usage )
130
130
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" ,
132
132
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" ,
134
134
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 (),
136
136
help = """Source top-directory. [Default: %default]""" )
137
137
parser .enable_interspersed_args ()
138
138
options , args = parser .parse_args ()
@@ -141,10 +141,10 @@ def main():
141
141
target_source_path = options .target_source_path ,
142
142
header_include_path = options .header_include_path )
143
143
if msg :
144
- sys .stderr .write ( msg + ' \n ' )
144
+ sys .stderr .write ( msg + " \n " )
145
145
sys .exit ( 1 )
146
146
else :
147
- print ' Source succesfully amalagated'
148
-
149
- if __name__ == ' __main__' :
147
+ print ( " Source succesfully amalagated" )
148
+
149
+ if __name__ == " __main__" :
150
150
main ()
0 commit comments