def install(robustus, requirement_specifier, rob_file, ignore_index): assert requirement_specifier.name == 'ros_overlay' packages = requirement_specifier.version.split(',') cwd = os.getcwd() try: env_source = os.path.join(robustus.env, 'bin/activate') _ros_dep_init(env_source, robustus) # NOTE: If ROS is not installed, the following returns an empty string. def get_ros_install_dir(env_source): ret_code, output = run_shell('. "%s" && python -c "import ros ; print ros.__file__"' % env_source, shell=True, return_output=True) if ret_code != 0: logging.info('get_ros_install_dir() failed: ret_code is %d: %s' % (ret_code, output)) return '' if len(output.splitlines()) != 1: logging.info('get_ros_install_dir() failed: Too many lines in output: %s' % output) return '' output_dirname = os.path.dirname(output) ros_install_dir = os.path.abspath(os.path.join(output_dirname, os.pardir, os.pardir, os.pardir, os.pardir)) if not os.path.isdir(ros_install_dir): logging.info('get_ros_install_dir() failed: ros_install_dir not a directory: %s' % ros_install_dir) return '' return ros_install_dir ros_install_dir = get_ros_install_dir(env_source) req_name = "ros-installed-overlay" ver_hash = requirement_specifier.version_hash() logging.info('Hashing ROS overlay on (robustus.env, ver_hash, ros_install_dir) = ("%s", "%s", "%s")' % (robustus.env, ver_hash, ros_install_dir)) req_hash = ros_utils.hash_path(robustus.env, ver_hash, ros_install_dir) overlay_install_folder = os.path.join(robustus.cache, '%s-%s' % (req_name, req_hash)) if not os.path.isdir(overlay_install_folder): overlay_archive = robustus.download_compiled_archive(req_name, req_hash) if overlay_archive: overlay_archive_name = unpack(overlay_archive) logging.info('Initializing compiled ROS overlay') # install into wheelhouse safe_move(overlay_archive_name, overlay_install_folder) safe_remove(overlay_archive) else: overlay_src_folder = _make_overlay_folder(robustus, req_hash) os.chdir(overlay_src_folder) logging.info('Building ros overlay in %s with versions %s' ' install folder %s' % (overlay_src_folder, str(packages), overlay_install_folder)) os.mkdir(os.path.join(overlay_src_folder, 'src')) _get_sources(packages) _ros_dep(env_source, robustus) opencv_cmake_dir = _opencv_cmake_path(robustus) ret_code = run_shell('. "%s" && export OpenCV_DIR="%s" && catkin_make_isolated' ' --install-space %s --install' % (env_source, opencv_cmake_dir, overlay_install_folder) + ' --force-cmake --cmake-args -DCATKIN_ENABLE_TESTING=1 ', shell=True, verbose=robustus.settings['verbosity'] >= 1) if ret_code != 0: raise RequirementException('Error during catkin_make') else: logging.info('ROS overlay cached %s' % overlay_install_folder) add_source_ref(robustus, os.path.join(overlay_install_folder, 'setup.sh')) except RequirementException: if robustus.settings['debug']: logging.info('Not removing folder %s due to debug flag.' % overlay_src_folder) else: shutil.rmtree(overlay_src_folder, ignore_errors=True) shutil.rmtree(overlay_install_folder, ignore_errors=True) raise finally: os.chdir(cwd)
def install(robustus, requirement_specifier, rob_file, ignore_index): ver, dist = requirement_specifier.version.split('.') if platform.machine() == 'armv7l': # specific code to link ros on bstem ros_install_dir = os.path.join('/opt/bstem/bstem.ros', 'ros-install-%s' % requirement_specifier.version) if os.path.isdir(ros_install_dir): # check distro if (ver == 'hydro' and dist == 'ros_comm'): # Add ROS settings to activate file logging.info('Using ROS system install %s' % ros_install_dir) add_source_ref(robustus, os.path.join(ros_install_dir, 'setup.sh')) return else: logging.warn('armv7l only uses hydro.ros_comm as a ROS system install.\n') else: logging.warn('No suitable ROS system install found.\n') # check distro if ver != 'hydro': logging.warn('Robustus is only tested to install ROS hydro.\n' 'Still, it will try to install required distribution "%s"' % requirement_specifier.version) # install dependencies, may throw robustus.execute(['install', 'catkin_pkg==0.2.2', 'rosinstall==0.6.30', 'rosinstall_generator==0.1.4', 'wstool==0.0.4', 'empy==3.3.2', 'rosdep==0.10.27', 'sip']) ros_src_dir = os.path.join(robustus.env, 'ros-src-%s' % requirement_specifier.version) req_name = 'ros-install-%s' % requirement_specifier.version req_hash = ros_utils.hash_path(robustus.env) ros_install_dir = os.path.join(robustus.cache, '%s-%s' % (req_name, req_hash)) def in_cache(): return os.path.isdir(ros_install_dir) rosdep = _install_ros_deps(robustus) try: cwd = os.getcwd() logging.info('ROS install dir %s' % ros_install_dir) # download and install compiled non-system ROS or, if necessary, build ROS if not in_cache() and not ignore_index: ros_archive = robustus.download_compiled_archive(req_name, req_hash) if ros_archive: ros_archive_name = unpack(ros_archive) logging.info('Initializing compiled ROS in Robustus wheelhouse') # install into wheelhouse safe_move(ros_archive_name, ros_install_dir) safe_remove(ros_archive) else: logging.info('Building ROS in Robustus wheelhouse') if not os.path.isdir(ros_src_dir): os.makedirs(ros_src_dir) os.chdir(ros_src_dir) rosinstall_generator = os.path.join(robustus.env, 'bin/rosinstall_generator') retcode = run_shell(rosinstall_generator + ' %s --rosdistro %s' % (dist, ver) + ' --deps --wet-only > %s-%s-wet.rosinstall' % (dist, ver), shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: raise RequirementException('Failed to generate rosinstall file') wstool = os.path.join(robustus.env, 'bin/wstool') retcode = run_shell(wstool + ' init -j2 src %s-%s-wet.rosinstall' % (dist, ver), shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: raise RequirementException('Failed to build ROS') # resolve dependencies if sys.platform.startswith('darwin'): ros_os_param = '' else: ros_os_param = '--os=ubuntu:%s' % _get_distribution() retcode = run_shell(rosdep + ' install -r --from-paths src --ignore-src --rosdistro %s -y %s' % (ver, ros_os_param), shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: if platform.machine() == 'armv7l': # Due to the lack of LISP machine for ARM we expect some failures logging.info("No LISP on ARM. Expected not all dependencies to be installed.") else: raise RequirementException('Failed to resolve ROS dependencies') # create catkin workspace py_activate_file = os.path.join(robustus.env, 'bin', 'activate') catkin_make_isolated = os.path.join(ros_src_dir, 'src/catkin/bin/catkin_make_isolated') retcode = run_shell('. ' + py_activate_file + ' && ' + catkin_make_isolated + ' --install-space %s --install' % ros_install_dir, shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: raise RequirementException('Failed to create catkin workspace for ROS') logging.info('Removing ROS source/build directory %s' % ros_src_dir) os.chdir(ros_install_dir) # NOTE: If this directory is not accessible, something is wrong. shutil.rmtree(ros_src_dir, ignore_errors=False) else: logging.info('Using ROS from cache %s' % ros_install_dir) os.chdir(cwd) # Add ROS settings to activate file add_source_ref(robustus, os.path.join(ros_install_dir, 'setup.sh')) except RequirementException: os.chdir(cwd) if robustus.settings['debug']: logging.info('Not removing folder %s due to debug flag.' % ros_src_dir) logging.info('Not removing folder %s due to debug flag.' % ros_install_dir) else: shutil.rmtree(ros_src_dir, ignore_errors=True) shutil.rmtree(ros_install_dir, ignore_errors=True) raise
def install(robustus, requirement_specifier, rob_file, ignore_index): assert requirement_specifier.name == 'ros_overlay' packages = requirement_specifier.version.split(',') cwd = os.getcwd() try: env_source = os.path.join(robustus.env, 'bin/activate') _ros_dep_init(env_source, robustus) # NOTE: If ROS is not installed, the following returns an empty string. def get_ros_install_dir(env_source): ret_code, output = run_shell( '. "%s" && python -c "import ros ; print ros.__file__"' % env_source, shell=True, return_output=True) if ret_code != 0: logging.info( 'get_ros_install_dir() failed: ret_code is %d: %s' % (ret_code, output)) return '' if len(output.splitlines()) != 1: logging.info( 'get_ros_install_dir() failed: Too many lines in output: %s' % output) return '' output_dirname = os.path.dirname(output) ros_install_dir = os.path.abspath( os.path.join(output_dirname, os.pardir, os.pardir, os.pardir, os.pardir)) if not os.path.isdir(ros_install_dir): logging.info( 'get_ros_install_dir() failed: ros_install_dir not a directory: %s' % ros_install_dir) return '' return ros_install_dir ros_install_dir = get_ros_install_dir(env_source) req_name = "ros-installed-overlay" ver_hash = requirement_specifier.version_hash() logging.info( 'Hashing ROS overlay on (robustus.env, ver_hash, ros_install_dir) = ("%s", "%s", "%s")' % (robustus.env, ver_hash, ros_install_dir)) req_hash = ros_utils.hash_path(robustus.env, ver_hash, ros_install_dir) overlay_install_folder = os.path.join(robustus.cache, '%s-%s' % (req_name, req_hash)) if not os.path.isdir(overlay_install_folder): overlay_archive = robustus.download_compiled_archive( req_name, req_hash) if overlay_archive: overlay_archive_name = unpack(overlay_archive) logging.info('Initializing compiled ROS overlay') # install into wheelhouse safe_move(overlay_archive_name, overlay_install_folder) safe_remove(overlay_archive) else: overlay_src_folder = _make_overlay_folder(robustus, req_hash) os.chdir(overlay_src_folder) logging.info('Building ros overlay in %s with versions %s' ' install folder %s' % (overlay_src_folder, str(packages), overlay_install_folder)) os.mkdir(os.path.join(overlay_src_folder, 'src')) _get_sources(packages) _ros_dep(env_source, robustus) opencv_cmake_dir = _opencv_cmake_path(robustus) ret_code = run_shell( '. "%s" && export OpenCV_DIR="%s" && catkin_make_isolated' ' --install-space %s --install' % (env_source, opencv_cmake_dir, overlay_install_folder) + ' --force-cmake --cmake-args -DCATKIN_ENABLE_TESTING=1 ', shell=True, verbose=robustus.settings['verbosity'] >= 1) if ret_code != 0: raise RequirementException('Error during catkin_make') else: logging.info('ROS overlay cached %s' % overlay_install_folder) add_source_ref(robustus, os.path.join(overlay_install_folder, 'setup.sh')) except RequirementException: if robustus.settings['debug']: logging.info('Not removing folder %s due to debug flag.' % overlay_src_folder) else: shutil.rmtree(overlay_src_folder, ignore_errors=True) shutil.rmtree(overlay_install_folder, ignore_errors=True) raise finally: os.chdir(cwd)
def install(robustus, requirement_specifier, rob_file, ignore_index): ver, dist = requirement_specifier.version.split('.') if platform.machine() == 'armv7l': # specific code to link ros on bstem ros_install_dir = os.path.join( '/opt/bstem/bstem.ros', 'ros-install-%s' % requirement_specifier.version) if os.path.isdir(ros_install_dir): # check distro if (ver == 'hydro' and dist == 'ros_comm'): # Add ROS settings to activate file logging.info('Using ROS system install %s' % ros_install_dir) add_source_ref(robustus, os.path.join(ros_install_dir, 'setup.sh')) return else: logging.warn( 'armv7l only uses hydro.ros_comm as a ROS system install.\n' ) else: logging.warn('No suitable ROS system install found.\n') # check distro if ver != 'hydro': logging.warn( 'Robustus is only tested to install ROS hydro.\n' 'Still, it will try to install required distribution "%s"' % requirement_specifier.version) # install dependencies, may throw robustus.execute([ 'install', 'catkin_pkg==0.2.2', 'rosinstall==0.6.30', 'rosinstall_generator==0.1.4', 'wstool==0.0.4', 'empy==3.3.2', 'rosdep==0.10.27', 'sip' ]) ros_src_dir = os.path.join(robustus.env, 'ros-src-%s' % requirement_specifier.version) req_name = 'ros-install-%s' % requirement_specifier.version req_hash = ros_utils.hash_path(robustus.env) ros_install_dir = os.path.join(robustus.cache, '%s-%s' % (req_name, req_hash)) def in_cache(): return os.path.isdir(ros_install_dir) rosdep = _install_ros_deps(robustus) try: cwd = os.getcwd() logging.info('ROS install dir %s' % ros_install_dir) # download and install compiled non-system ROS or, if necessary, build ROS if not in_cache() and not ignore_index: ros_archive = robustus.download_compiled_archive( req_name, req_hash) if ros_archive: ros_archive_name = unpack(ros_archive) logging.info( 'Initializing compiled ROS in Robustus wheelhouse') # install into wheelhouse safe_move(ros_archive_name, ros_install_dir) safe_remove(ros_archive) else: logging.info('Building ROS in Robustus wheelhouse') if not os.path.isdir(ros_src_dir): os.makedirs(ros_src_dir) os.chdir(ros_src_dir) rosinstall_generator = os.path.join( robustus.env, 'bin/rosinstall_generator') retcode = run_shell( rosinstall_generator + ' %s --rosdistro %s' % (dist, ver) + ' --deps --wet-only > %s-%s-wet.rosinstall' % (dist, ver), shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: raise RequirementException( 'Failed to generate rosinstall file') wstool = os.path.join(robustus.env, 'bin/wstool') retcode = run_shell( wstool + ' init -j2 src %s-%s-wet.rosinstall' % (dist, ver), shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: raise RequirementException('Failed to build ROS') # resolve dependencies if sys.platform.startswith('darwin'): ros_os_param = '' else: ros_os_param = '--os=ubuntu:%s' % _get_distribution() retcode = run_shell( rosdep + ' install -r --from-paths src --ignore-src --rosdistro %s -y %s' % (ver, ros_os_param), shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: if platform.machine() == 'armv7l': # Due to the lack of LISP machine for ARM we expect some failures logging.info( "No LISP on ARM. Expected not all dependencies to be installed." ) else: raise RequirementException( 'Failed to resolve ROS dependencies') # create catkin workspace py_activate_file = os.path.join(robustus.env, 'bin', 'activate') catkin_make_isolated = os.path.join( ros_src_dir, 'src/catkin/bin/catkin_make_isolated') retcode = run_shell( '. ' + py_activate_file + ' && ' + catkin_make_isolated + ' --install-space %s --install' % ros_install_dir, shell=True, verbose=robustus.settings['verbosity'] >= 1) if retcode != 0: raise RequirementException( 'Failed to create catkin workspace for ROS') logging.info('Removing ROS source/build directory %s' % ros_src_dir) os.chdir( ros_install_dir ) # NOTE: If this directory is not accessible, something is wrong. shutil.rmtree(ros_src_dir, ignore_errors=False) else: logging.info('Using ROS from cache %s' % ros_install_dir) os.chdir(cwd) # Add ROS settings to activate file add_source_ref(robustus, os.path.join(ros_install_dir, 'setup.sh')) except RequirementException: os.chdir(cwd) if robustus.settings['debug']: logging.info('Not removing folder %s due to debug flag.' % ros_src_dir) logging.info('Not removing folder %s due to debug flag.' % ros_install_dir) else: shutil.rmtree(ros_src_dir, ignore_errors=True) shutil.rmtree(ros_install_dir, ignore_errors=True) raise