Skip to content

Commit

Permalink
use argparse to specify file(s) to generate template.hpp
Browse files Browse the repository at this point in the history
```
$ python3 ../mros2/mros2_header_generator/templates_generator.py --app echoback_string --file app.cpp bbb.cpp -h
Generate template.hpp from mros2 app code file.
usage: templates_generator.py [-h] [--app APP] [--file [FILE [FILE ...]]]

Generate template.hpp from mros2 app code file.

optional arguments:
  -h, --help            show this help message and exit
  --app APP             application name (default: 'echoreply_string')
  --file [FILE [FILE ...]]
                        filename(s) of mros2 app code (default: 'app.cpp')
```
  • Loading branch information
takasehideki committed Sep 13, 2023
1 parent 4c4a97d commit 76570ee
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions mros2_header_generator/templates_generator.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import os
import sys
import re
import argparse
from os import path
from jinja2 import Environment, FileSystemLoader

arg = sys.argv
app = arg[1]

includeFiles = []
pubMsgTypes = []
subMsgTypes = []
Expand All @@ -15,7 +13,21 @@ def toSnakeCase(string):
return re.sub("(.[A-Z])",lambda x:x.group(1)[0] + "_" +x.group(1)[1],string).lower()

def main():
with open(app + "/app.cpp", 'r') as m_f:
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('--file', nargs='*', type=str, default=['app.cpp'],
help='filename(s) of mros2 app code (default: \'app.cpp\')')

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

for f in file:
print(' Analyzing {}/{} file to generate...'.format(app, f))
with open(app + "/" + f, 'r') as m_f:
arr = m_f.readlines()
for m_line in arr:
if "create_publisher" in m_line:
Expand Down Expand Up @@ -44,5 +56,7 @@ def main():
with open(os.path.join(app+"/templates.hpp"), "wb") as f:
f.write(datatext.encode('utf-8'))

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

if __name__ == "__main__":
main()

0 comments on commit 76570ee

Please # to comment.