Follow good practice and add main() to split.py
This commit is contained in:
parent
3f4e9056e9
commit
50816d4c08
116
split.py
116
split.py
@ -10,62 +10,68 @@ border = (
|
|||||||
"// ----------------------------------------------------------------------------"
|
"// ----------------------------------------------------------------------------"
|
||||||
)
|
)
|
||||||
|
|
||||||
args_parser = argparse.ArgumentParser(description=__doc__)
|
|
||||||
args_parser.add_argument(
|
|
||||||
"-e",
|
|
||||||
"--extension",
|
|
||||||
help="extension of the implementation file (default: cc)",
|
|
||||||
default="cc",
|
|
||||||
)
|
|
||||||
args_parser.add_argument(
|
|
||||||
"-o", "--out", help="where to write the files (default: out)", default="out"
|
|
||||||
)
|
|
||||||
args = args_parser.parse_args()
|
|
||||||
|
|
||||||
cur_dir = os.path.dirname(sys.argv[0])
|
def main():
|
||||||
lib_name = "httplib"
|
args_parser = argparse.ArgumentParser(description=__doc__)
|
||||||
header_name = "/" + lib_name + ".h"
|
args_parser.add_argument(
|
||||||
source_name = "/" + lib_name + "." + args.extension
|
"-e",
|
||||||
# get the input file
|
"--extension",
|
||||||
in_file = cur_dir + header_name
|
help="extension of the implementation file (default: cc)",
|
||||||
# get the output file
|
default="cc",
|
||||||
h_out = args.out + header_name
|
)
|
||||||
cc_out = args.out + source_name
|
args_parser.add_argument(
|
||||||
|
"-o", "--out", help="where to write the files (default: out)", default="out"
|
||||||
|
)
|
||||||
|
args = args_parser.parse_args()
|
||||||
|
|
||||||
# if the modification time of the out file is after the in file,
|
cur_dir = os.path.dirname(sys.argv[0])
|
||||||
# don't split (as it is already finished)
|
lib_name = "httplib"
|
||||||
do_split = True
|
header_name = "/" + lib_name + ".h"
|
||||||
|
source_name = "/" + lib_name + "." + args.extension
|
||||||
if os.path.exists(h_out):
|
# get the input file
|
||||||
in_time = os.path.getmtime(in_file)
|
in_file = cur_dir + header_name
|
||||||
out_time = os.path.getmtime(h_out)
|
# get the output file
|
||||||
do_split = in_time > out_time
|
h_out = args.out + header_name
|
||||||
|
|
||||||
if do_split:
|
|
||||||
with open(in_file) as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
|
|
||||||
python_version = sys.version_info[0]
|
|
||||||
if python_version < 3:
|
|
||||||
os.makedirs(args.out)
|
|
||||||
else:
|
|
||||||
os.makedirs(args.out, exist_ok=True)
|
|
||||||
|
|
||||||
in_implementation = False
|
|
||||||
cc_out = args.out + source_name
|
cc_out = args.out + source_name
|
||||||
with open(h_out, "w") as fh, open(cc_out, "w") as fc:
|
|
||||||
fc.write('#include "httplib.h"\n')
|
|
||||||
fc.write("namespace httplib {\n")
|
|
||||||
for line in lines:
|
|
||||||
is_border_line = border in line
|
|
||||||
if is_border_line:
|
|
||||||
in_implementation = not in_implementation
|
|
||||||
elif in_implementation:
|
|
||||||
fc.write(line.replace("inline ", ""))
|
|
||||||
else:
|
|
||||||
fh.write(line)
|
|
||||||
fc.write("} // namespace httplib\n")
|
|
||||||
|
|
||||||
print("Wrote {} and {}".format(h_out, cc_out))
|
# if the modification time of the out file is after the in file,
|
||||||
else:
|
# don't split (as it is already finished)
|
||||||
print("{} and {} are up to date".format(h_out, cc_out))
|
do_split = True
|
||||||
|
|
||||||
|
if os.path.exists(h_out):
|
||||||
|
in_time = os.path.getmtime(in_file)
|
||||||
|
out_time = os.path.getmtime(h_out)
|
||||||
|
do_split = in_time > out_time
|
||||||
|
|
||||||
|
if do_split:
|
||||||
|
with open(in_file) as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
|
||||||
|
python_version = sys.version_info[0]
|
||||||
|
if python_version < 3:
|
||||||
|
os.makedirs(args.out)
|
||||||
|
else:
|
||||||
|
os.makedirs(args.out, exist_ok=True)
|
||||||
|
|
||||||
|
in_implementation = False
|
||||||
|
cc_out = args.out + source_name
|
||||||
|
with open(h_out, "w") as fh, open(cc_out, "w") as fc:
|
||||||
|
fc.write('#include "httplib.h"\n')
|
||||||
|
fc.write("namespace httplib {\n")
|
||||||
|
for line in lines:
|
||||||
|
is_border_line = border in line
|
||||||
|
if is_border_line:
|
||||||
|
in_implementation = not in_implementation
|
||||||
|
elif in_implementation:
|
||||||
|
fc.write(line.replace("inline ", ""))
|
||||||
|
else:
|
||||||
|
fh.write(line)
|
||||||
|
fc.write("} // namespace httplib\n")
|
||||||
|
|
||||||
|
print("Wrote {} and {}".format(h_out, cc_out))
|
||||||
|
else:
|
||||||
|
print("{} and {} are up to date".format(h_out, cc_out))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user