Skip to content

Commit

Permalink
change location to execute template_gen and output dir of template.hpp
Browse files Browse the repository at this point in the history
also check:
mROS-base/mros2-mbed@b120d7c

```
$ pwd
/<snipned>/mros2-mbed/workspace/echoback_string

$ python3 ../../mros2/mros2_header_generator/templates_generator.py -h
Generate template.hpp from mros2 app code file.
usage: templates_generator.py [-h] [--outdir OUTDIR]
                              [--file [FILE [FILE ...]]]

Generate template.hpp from mros2 app code file.

optional arguments:
  -h, --help            show this help message and exit
  --outdir OUTDIR       directry name to output template.hpp (default: '.'
                        (current dir))
  --file [FILE [FILE ...]]
                        filename(s) of mros2 app code (default: 'app.cpp')
```
  • Loading branch information
takasehideki committed Sep 15, 2023
1 parent 76570ee commit c446669
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions mros2_header_generator/templates_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ def main():
print('Generate template.hpp from mros2 app code file.')

parser = argparse.ArgumentParser(description='Generate template.hpp from mros2 app code file.')
parser.add_argument('--app', default='echoreply_string',
help='application name (default: \'echoreply_string\')')
parser.add_argument('--outdir', default='.',
help='directry name to output template.hpp (default: \'.\' (current dir))')
parser.add_argument('--file', nargs='*', type=str, default=['app.cpp'],
help='filename(s) of mros2 app code (default: \'app.cpp\')')

args = parser.parse_args()
app = args.app
outdir = args.outdir
file = args.file

for f in file:
print(' Analyzing {}/{} file to generate...'.format(app, f))
with open(app + "/" + f, 'r') as m_f:
print(' Analyzing \'{}\' to generate...'.format(f))
with open(f, 'r') as m_f:
arr = m_f.readlines()
for m_line in arr:
if "create_publisher" in m_line:
Expand All @@ -53,10 +53,10 @@ 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(app+"/templates.hpp"), "wb") as f:
with open(os.path.join(outdir + "/templates.hpp"), "wb") as f:
f.write(datatext.encode('utf-8'))

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

if __name__ == "__main__":
main()

0 comments on commit c446669

Please # to comment.