Skip to content

Commit 494950a

Browse files
committed
rm extra whitespace in python, per PEP8
1 parent f4bc0bf commit 494950a

17 files changed

+494
-500
lines changed

Diff for: amalgamate.py

+86-86
Original file line numberDiff line numberDiff line change
@@ -10,116 +10,116 @@
1010
import sys
1111

1212
class AmalgamationFile:
13-
def __init__( self, top_dir ):
13+
def __init__(self, top_dir):
1414
self.top_dir = top_dir
1515
self.blocks = []
1616

17-
def add_text( self, text ):
18-
if not text.endswith( "\n" ):
17+
def add_text(self, text):
18+
if not text.endswith("\n"):
1919
text += "\n"
20-
self.blocks.append( text )
21-
22-
def add_file( self, relative_input_path, wrap_in_comment=False ):
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" )
20+
self.blocks.append(text)
21+
22+
def add_file(self, relative_input_path, wrap_in_comment=False):
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")
3131
content = f.read()
3232
if wrap_in_comment:
3333
content = "/*\n" + content + "\n*/"
34-
self.add_text( content )
34+
self.add_text(content)
3535
f.close()
36-
add_marker( "End" )
37-
self.add_text( "\n\n\n\n" )
38-
39-
def get_value( self ):
40-
return "".join( self.blocks ).replace("\r\n","\n")
41-
42-
def write_to( self, output_path ):
43-
output_dir = os.path.dirname( output_path )
44-
if output_dir and not os.path.isdir( output_dir ):
45-
os.makedirs( output_dir )
46-
f = open( output_path, "wb" )
47-
f.write( str.encode(self.get_value(), 'UTF-8') )
36+
add_marker("End")
37+
self.add_text("\n\n\n\n")
38+
39+
def get_value(self):
40+
return "".join(self.blocks).replace("\r\n","\n")
41+
42+
def write_to(self, output_path):
43+
output_dir = os.path.dirname(output_path)
44+
if output_dir and not os.path.isdir(output_dir):
45+
os.makedirs(output_dir)
46+
f = open(output_path, "wb")
47+
f.write(str.encode(self.get_value(), 'UTF-8'))
4848
f.close()
4949

50-
def amalgamate_source( source_top_dir=None,
50+
def amalgamate_source(source_top_dir=None,
5151
target_source_path=None,
52-
header_include_path=None ):
52+
header_include_path=None):
5353
"""Produces amalgated source.
5454
Parameters:
5555
source_top_dir: top-directory
5656
target_source_path: output .cpp path
5757
header_include_path: generated header path relative to target_source_path.
5858
"""
5959
print("Amalgating header...")
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" )
78-
79-
target_header_path = os.path.join( os.path.dirname(target_source_path), header_include_path )
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")
78+
79+
target_header_path = os.path.join(os.path.dirname(target_source_path), header_include_path)
8080
print("Writing amalgated header to %r" % target_header_path)
81-
header.write_to( target_header_path )
81+
header.write_to(target_header_path)
8282

83-
base, ext = os.path.splitext( header_include_path )
83+
base, ext = os.path.splitext(header_include_path)
8484
forward_header_include_path = base + "-forwards" + ext
8585
print("Amalgating forward header...")
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" )
99-
100-
target_forward_header_path = os.path.join( os.path.dirname(target_source_path),
101-
forward_header_include_path )
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")
99+
100+
target_forward_header_path = os.path.join(os.path.dirname(target_source_path),
101+
forward_header_include_path)
102102
print("Writing amalgated forward header to %r" % target_forward_header_path)
103-
header.write_to( target_forward_header_path )
103+
header.write_to(target_forward_header_path)
104104

105105
print("Amalgating source...")
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>" % 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( "" )
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>" % 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("")
113113
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") )
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"))
120120

121121
print("Writing amalgated source to %r" % target_source_path)
122-
source.write_to( target_source_path )
122+
source.write_to(target_source_path)
123123

124124
def main():
125125
usage = """%prog [options]
@@ -137,12 +137,12 @@ def main():
137137
parser.enable_interspersed_args()
138138
options, args = parser.parse_args()
139139

140-
msg = amalgamate_source( source_top_dir=options.top_dir,
140+
msg = amalgamate_source(source_top_dir=options.top_dir,
141141
target_source_path=options.target_source_path,
142-
header_include_path=options.header_include_path )
142+
header_include_path=options.header_include_path)
143143
if msg:
144-
sys.stderr.write( msg + "\n" )
145-
sys.exit( 1 )
144+
sys.stderr.write(msg + "\n")
145+
sys.exit(1)
146146
else:
147147
print("Source succesfully amalagated")
148148

0 commit comments

Comments
 (0)