Skip to content

Commit

Permalink
do not generate templates.hpp if it is same as the previous
Browse files Browse the repository at this point in the history
  • Loading branch information
takasehideki committed Sep 19, 2023
1 parent b2d6bde commit f4076b6
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions mros2_header_generator/templates_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import glob
import re
import argparse
import filecmp
import shutil
from os import path
from jinja2 import Environment, FileSystemLoader

Expand All @@ -22,12 +24,12 @@ def main():
help='input dir(s) that contains mros2 app code (required)')

args = parser.parse_args()
outdir = args.outdir
indir = args.indir
outdir = args.outdir
file = []

for id in indir:
file = file + glob.glob(os.path.join(id, "*.cpp"))

for f in file:
print(' Analyzing \'{}\' to generate...'.format(f))
with open(f, 'r') as m_f:
Expand Down Expand Up @@ -56,8 +58,18 @@ def main():
env = Environment(loader=FileSystemLoader(path.dirname(__file__)))
template = env.get_template('templates.tpl')
datatext = template.render({ "includeFiles":includeFiles, "pubMsgTypes":pubMsgTypes, "subMsgTypes":subMsgTypes })
with open(os.path.join(outdir + "/templates.hpp"), "wb") as f:

outfile_path = os.path.join(outdir, "templates.hpp")
outtemp_path = os.path.join(outdir, "templates.hpp.tmp")
if (not os.path.isfile(outfile_path)):
with open(outfile_path, "wb") as f:
f.write(datatext.encode('utf-8'))
with open(outtemp_path, "wb") as f:
f.write(datatext.encode('utf-8'))
if filecmp.cmp(outtemp_path, outfile_path, shallow=True):
os.remove(outtemp_path)
else:
shutil.move(outtemp_path, outfile_path)

print('Generate {}/template.hpp done.'.format(outdir))

Expand Down

0 comments on commit f4076b6

Please # to comment.