From 2977726b32f57205ac0985ce9eb8f44e5dbbe8bf Mon Sep 17 00:00:00 2001 From: Mikael Arguedas Date: Fri, 24 Jan 2020 23:00:00 +0100 Subject: [PATCH] [update] Allow to process single ROS distro, fix 723 (#738) * [update] skip other distro if --rosdistro passed Signed-off-by: Mikael Arguedas * ignore argument if specified distro doesnt exist * address review comments * update help message for rosdistro Signed-off-by: Mikael Arguedas --- src/rosdep2/main.py | 12 +++++++++--- src/rosdep2/sources_list.py | 19 ++++++++++++++----- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index 6010033ab..268fcbdc1 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -269,7 +269,7 @@ def setup_environment_variables(ros_distro): """ Set environment variables needed to find ROS packages and evaluate conditional dependencies. - :param rosdistro: The requested ROS distro passed on the CLI, or None + :param ros_distro: The requested ROS distro passed on the CLI, or None """ if ros_distro is not None: if 'ROS_DISTRO' in os.environ and os.environ['ROS_DISTRO'] != ros_distro: @@ -355,7 +355,9 @@ def _rosdep_main(args): parser.add_option('--rosdistro', dest='ros_distro', default=None, help='Explicitly sets the ROS distro to use, overriding ' 'the normal method of detecting the ROS distro ' - 'using the ROS_DISTRO environment variable.') + 'using the ROS_DISTRO environment variable. ' + "When used with the 'update' verb, " + 'only the specified distro will be updated.') parser.add_option('--as-root', default=[], action='append', metavar='INSTALLER_KEY:', help='Override ' 'whether sudo is used for a specific installer, ' @@ -643,7 +645,8 @@ def update_error_handler(data_source, exc): pass update_sources_list(success_handler=update_success_handler, error_handler=update_error_handler, - skip_eol_distros=not options.include_eol_distros) + skip_eol_distros=not options.include_eol_distros, + ros_distro=options.ros_distro) print('updated cache in %s' % (sources_cache_dir)) except InvalidData as e: print('ERROR: invalid sources list file:\n\t%s' % (e), file=sys.stderr) @@ -651,6 +654,9 @@ def update_error_handler(data_source, exc): except IOError as e: print('ERROR: error loading sources list:\n\t%s' % (e), file=sys.stderr) return 1 + except ValueError as e: + print('ERROR: invalid argument value provided:\n\t%s' % (e), file=sys.stderr) + return 1 if error_occured: print('ERROR: Not all sources were able to be updated.\n[[[') for e in error_occured: diff --git a/src/rosdep2/sources_list.py b/src/rosdep2/sources_list.py index 1315c83ed..70f7cb8ca 100644 --- a/src/rosdep2/sources_list.py +++ b/src/rosdep2/sources_list.py @@ -439,7 +439,7 @@ def _generate_key_from_urls(urls): def update_sources_list(sources_list_dir=None, sources_cache_dir=None, success_handler=None, error_handler=None, - skip_eol_distros=False): + skip_eol_distros=False, ros_distro=None): """ Re-downloaded data from remote sources and store in cache. Also update the cache index based on current sources. @@ -487,12 +487,21 @@ def update_sources_list(sources_list_dir=None, sources_cache_dir=None, python_versions = {} print('Query rosdistro index %s' % get_index_url()) - for dist_name in sorted(get_index().distributions.keys()): + distribution_names = get_index().distributions.keys() + if ros_distro is not None and ros_distro not in distribution_names: + raise ValueError( + 'Requested distribution "%s" is not in the index.' % ros_distro) + + for dist_name in sorted(distribution_names): distribution = get_index().distributions[dist_name] - if skip_eol_distros: - if distribution.get('distribution_status') == 'end-of-life': - print('Skip end-of-life distro "%s"' % dist_name) + if dist_name != ros_distro: + if ros_distro is not None: + print('Skip distro "%s" different from requested "%s"' % (dist_name, ros_distro)) continue + if skip_eol_distros: + if distribution.get('distribution_status') == 'end-of-life': + print('Skip end-of-life distro "%s"' % dist_name) + continue print('Add distro "%s"' % dist_name) rds = RosDistroSource(dist_name) rosdep_data = get_gbprepo_as_rosdep_data(dist_name)