Skip to content

Instantly share code, notes, and snippets.

@peci1
Created February 10, 2025 08:40
Show Gist options
  • Save peci1/591c6d9cecbd3666c92d16c75a968e21 to your computer and use it in GitHub Desktop.
Save peci1/591c6d9cecbd3666c92d16c75a968e21 to your computer and use it in GitHub Desktop.
Recursive wstool implementation that honors all dependencies.rosinstall files in fetched repos
#! /usr/bin/python
# Software License Agreement (BSD License)
#
# Copyright (c) 2010, Willow Garage, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# * Neither the name of Willow Garage, Inc. nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# Revision $Id: rosws 14389 2011-07-20 18:38:40Z tfoote $
# $Author: tfoote $
"""%(prog)s is a command to manipulate ROS workspaces.
Official usage:
%(prog)s CMD [ARGS] [OPTIONS]
%(prog)s will try to infer install path from context
"%(prog)s init" replaces the rosinstall command
Type '%(prog)s --help' for usage.
"""
from __future__ import print_function
import sys
import os
import time
try:
import wstool.wstool_cli
from wstool.common import MultiProjectException
except ImportError as exc:
sys.exit("ERROR: Cannot find required rosinstall library version, \
check your installation (also of vcstools) is up-to-date. One frequent cause \
is that rosinstall 0.5 is still installed in /usr/local/lib.\n%s" % exc)
OLD_REPO_SECONDS = 120
if __name__ == "__main__":
from wstool.config_elements import VCSConfigElement
from wstool.common import MultiProjectException
orig_install = VCSConfigElement.install
force_shallow=False
if "--shallow" in sys.argv:
force_shallow=True
sys.argv.remove("--shallow")
def my_install(self,
checkout=True,
backup=True,
backup_path=None,
inplace=False,
timeout=None,
verbose=False,
shallow=False):
p = self.get_path()
cache_path = '/tmp/wstool-cache' + p
if os.path.exists(cache_path):
mtime = os.path.getmtime(cache_path)
if time.time() - mtime < OLD_REPO_SECONDS:
print("Repository %s was recently updated, not updating again" % self.get_local_name())
return
else:
#print("Repository %s is old, updating" % self.get_local_name())
os.utime(cache_path, (time.time(), time.time()))
else:
try:
os.makedirs(cache_path)
except OSError as exc:
pass
try:
orig_install(self, checkout, backup, backup_path, inplace, timeout, verbose, True if force_shallow else shallow)
except MultiProjectException:
os.rmdir(cache_path)
raise
VCSConfigElement.install = my_install
try:
sys.exit(wstool.wstool_cli.wstool_main(sys.argv))
except MultiProjectException as mpe:
sys.exit("ERROR in config: %s" % str(mpe))
#!/bin/bash
# Merge and fetch dependencies from rosinstall files (recursively).
set -e
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $script_dir/utils.bash ''
$script_dir/fast_wstool_up up "$@"
deps=(`find . -mindepth 2 -type f -name 'dependencies.rosinstall' ! -executable`)
processed=()
while [ "${#deps[@]}" -ne "${#processed[@]}" ]; do
for f in "${deps[@]}"; do
if [[ " ${processed[@]} " =~ " ${f} " ]]; then
continue
fi
ans=`answer "Fetch packages from $f [y/n]? " "y" "$rosinstall"`
if [ "$ans" = "y" ]; then
# Keep first entry with given key (-k).
# Do not allow deps to overwrite already specified keys.
wstool merge -k "$f"
fi
processed+=("$f")
done
$script_dir/fast_wstool_up up "$@" || ask_for_exit
deps=(`find . -mindepth 2 -type f -name 'dependencies.rosinstall' ! -executable`)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment