From c5fd6e3d13129d789ea203fab89fd0785935c954 Mon Sep 17 00:00:00 2001 From: Lucas Walter Date: Sat, 7 Nov 2020 07:58:58 -0800 Subject: [PATCH] Optionally don't put comments in generated files. --- src/catkin_pkg/cli/create_pkg.py | 6 ++++- src/catkin_pkg/package_templates.py | 35 ++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/catkin_pkg/cli/create_pkg.py b/src/catkin_pkg/cli/create_pkg.py index 6626b533..55db7e72 100644 --- a/src/catkin_pkg/cli/create_pkg.py +++ b/src/catkin_pkg/cli/create_pkg.py @@ -42,6 +42,9 @@ def main(argv=sys.argv[1:], parent_path=os.getcwd()): parser.add_argument('-m', '--maintainer', action='append', help='A single maintainer, may be used multiple times') + parser.add_argument('-n', '--no_comments', + action='store_true', + help="Don't put comments in package.xml or CMakeLists.txt") rosdistro_name = os.environ['ROS_DISTRO'] if 'ROS_DISTRO' in os.environ else None parser.add_argument('--rosdistro', required=rosdistro_name is None, default=rosdistro_name, help='The ROS distro (default: environment variable ROS_DISTRO if defined)') @@ -64,7 +67,8 @@ def main(argv=sys.argv[1:], parent_path=os.getcwd()): package_template=package_template, rosdistro=args.rosdistro, newfiles={}, - meta=args.meta) + meta=args.meta, + no_comments=args.no_comments) print('Successfully created files in %s. Please adjust the values in package.xml.' % target_path) except ValueError as vae: parser.error(str(vae)) diff --git a/src/catkin_pkg/package_templates.py b/src/catkin_pkg/package_templates.py index d539d2f8..beb22764 100644 --- a/src/catkin_pkg/package_templates.py +++ b/src/catkin_pkg/package_templates.py @@ -34,6 +34,7 @@ import getpass import os +import re import string import sys @@ -144,7 +145,7 @@ def _create_package_template(package_name, description=None, licenses=None, return package_temp -def read_template_file(filename, rosdistro): +def read_template_file(filename, rosdistro, no_comments=False): template_dir = os.path.join(os.path.dirname(__file__), 'templates') templates = [] templates.append(os.path.join(template_dir, rosdistro, '%s.in' % filename)) @@ -153,6 +154,16 @@ def read_template_file(filename, rosdistro): if os.path.isfile(template): with open(template, 'r') as fhand: template_contents = fhand.read() + + if no_comments: + lines = template_contents.split('\n') + lines2 = [] + for line in lines: + if line.startswith('##') or '