Follow good practice and add main() to split.py
This commit is contained in:
parent
3f4e9056e9
commit
50816d4c08
48
split.py
48
split.py
@ -10,38 +10,40 @@ border = (
|
||||
"// ----------------------------------------------------------------------------"
|
||||
)
|
||||
|
||||
args_parser = argparse.ArgumentParser(description=__doc__)
|
||||
args_parser.add_argument(
|
||||
|
||||
def main():
|
||||
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(
|
||||
)
|
||||
args_parser.add_argument(
|
||||
"-o", "--out", help="where to write the files (default: out)", default="out"
|
||||
)
|
||||
args = args_parser.parse_args()
|
||||
)
|
||||
args = args_parser.parse_args()
|
||||
|
||||
cur_dir = os.path.dirname(sys.argv[0])
|
||||
lib_name = "httplib"
|
||||
header_name = "/" + lib_name + ".h"
|
||||
source_name = "/" + lib_name + "." + args.extension
|
||||
# get the input file
|
||||
in_file = cur_dir + header_name
|
||||
# get the output file
|
||||
h_out = args.out + header_name
|
||||
cc_out = args.out + source_name
|
||||
cur_dir = os.path.dirname(sys.argv[0])
|
||||
lib_name = "httplib"
|
||||
header_name = "/" + lib_name + ".h"
|
||||
source_name = "/" + lib_name + "." + args.extension
|
||||
# get the input file
|
||||
in_file = cur_dir + header_name
|
||||
# get the output file
|
||||
h_out = args.out + header_name
|
||||
cc_out = args.out + source_name
|
||||
|
||||
# if the modification time of the out file is after the in file,
|
||||
# don't split (as it is already finished)
|
||||
do_split = True
|
||||
# if the modification time of the out file is after the in file,
|
||||
# don't split (as it is already finished)
|
||||
do_split = True
|
||||
|
||||
if os.path.exists(h_out):
|
||||
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:
|
||||
if do_split:
|
||||
with open(in_file) as f:
|
||||
lines = f.readlines()
|
||||
|
||||
@ -67,5 +69,9 @@ if do_split:
|
||||
fc.write("} // namespace httplib\n")
|
||||
|
||||
print("Wrote {} and {}".format(h_out, cc_out))
|
||||
else:
|
||||
else:
|
||||
print("{} and {} are up to date".format(h_out, cc_out))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user