2
2
import glob
3
3
import re
4
4
import argparse
5
+ import filecmp
6
+ import shutil
5
7
from os import path
6
8
from jinja2 import Environment , FileSystemLoader
7
9
@@ -22,12 +24,12 @@ def main():
22
24
help = 'input dir(s) that contains mros2 app code (required)' )
23
25
24
26
args = parser .parse_args ()
25
- outdir = args .outdir
26
27
indir = args .indir
28
+ outdir = args .outdir
27
29
file = []
28
-
29
30
for id in indir :
30
31
file = file + glob .glob (os .path .join (id , "*.cpp" ))
32
+
31
33
for f in file :
32
34
print (' Analyzing \' {}\' to generate...' .format (f ))
33
35
with open (f , 'r' ) as m_f :
@@ -56,8 +58,18 @@ def main():
56
58
env = Environment (loader = FileSystemLoader (path .dirname (__file__ )))
57
59
template = env .get_template ('templates.tpl' )
58
60
datatext = template .render ({ "includeFiles" :includeFiles , "pubMsgTypes" :pubMsgTypes , "subMsgTypes" :subMsgTypes })
59
- with open (os .path .join (outdir + "/templates.hpp" ), "wb" ) as f :
61
+
62
+ outfile_path = os .path .join (outdir , "templates.hpp" )
63
+ outtemp_path = os .path .join (outdir , "templates.hpp.tmp" )
64
+ if (not os .path .isfile (outfile_path )):
65
+ with open (outfile_path , "wb" ) as f :
66
+ f .write (datatext .encode ('utf-8' ))
67
+ with open (outtemp_path , "wb" ) as f :
60
68
f .write (datatext .encode ('utf-8' ))
69
+ if filecmp .cmp (outtemp_path , outfile_path , shallow = True ):
70
+ os .remove (outtemp_path )
71
+ else :
72
+ shutil .move (outtemp_path , outfile_path )
61
73
62
74
print ('Generate {}/template.hpp done.' .format (outdir ))
63
75
0 commit comments