pax_global_header00006660000000000000000000000064131231603470014512gustar00rootroot0000000000000052 comment=17975e2a00795850911e8fd6f9c98ab0ebd545c0 ros-resource-retriever-1.12.3/000077500000000000000000000000001312316034700162335ustar00rootroot00000000000000ros-resource-retriever-1.12.3/CHANGELOG.rst000066400000000000000000000041731312316034700202610ustar00rootroot00000000000000^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Changelog for package resource_retriever ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1.12.3 (2017-03-27) ------------------- * Fix C++11 to use set_directory_properties * Make Shane and Chris the maintainers. * Python3 compatibility (`#10 `_) * Replace urlgrabber with urllib[2] As urlgrabber is not supported for Python 3 replace it with either the built-in urllib (Python 2) or urllib2 (Python 3) * Use rospkg instead of system call for rospack * Add test for python functionality * Fix rospkg dependency definition * Update URL in http test to something which exists (`#8 `_) * Update URL in http test to something which exists * Contributors: Chris Lalancette, Mike Purvis, Ruben Smits 1.12.2 (2016-06-10) ------------------- * fix failing build due to cmake error (`#6 `_) * Contributors: Jackie Kay 1.12.1 (2016-06-10) ------------------- * Fix warnings in test (`#5 `_) add spaces around ROS_PACKAGE_NAME * Merge pull request `#4 `_ from DLu/kinetic-devel Add c++11 flag * Contributors: David V. Lu!!, Jackie Kay, Steven Peters 1.12.0 (2016-03-23) ------------------- * resource_retriever: adding missing dep Using the python resource_retriever requires the `python-urlgrabber` system dependency: http://rosindex.github.io/d/python-urlgrabber/ * Contributors: Jonathan Bohren 1.11.6 (2014-11-30) ------------------- 1.11.5 (2014-07-24) ------------------- 1.11.4 (2014-07-07) ------------------- 1.11.3 (2014-06-24) ------------------- 1.11.2 (2014-03-22) ------------------- 1.11.1 (2014-03-20) ------------------- 1.11.0 (2014-02-21) ------------------- 1.10.18 (2013-12-04) -------------------- * add DEPENDS for kdl_parser * Contributors: Ioan Sucan 1.10.16 (2013-11-18) -------------------- * check for CATKIN_ENABLE_TESTING 1.10.15 (2013-08-17) -------------------- * resource_retriever: install python package using setup.py ros-resource-retriever-1.12.3/CMakeLists.txt000066400000000000000000000016511312316034700207760ustar00rootroot00000000000000cmake_minimum_required(VERSION 2.8.3) project(resource_retriever) set_directory_properties(PROPERTIES COMPILE_OPTIONS "-std=c++11") find_package(catkin REQUIRED COMPONENTS rosconsole roslib) catkin_python_setup() catkin_package( LIBRARIES ${PROJECT_NAME} INCLUDE_DIRS include) include_directories(include) include_directories(${catkin_INCLUDE_DIRS}) link_directories(${catkin_LIBRARY_DIRS}) include(FindCURL) if(NOT CURL_FOUND) message("CURL not found! Aborting...") fail() endif(NOT CURL_FOUND) include_directories(${CURL_INCLUDE_DIRS}) add_library(${PROJECT_NAME} src/retriever.cpp) target_link_libraries(${PROJECT_NAME} ${CURL_LIBRARIES} ${catkin_LIBRARIES}) if(CATKIN_ENABLE_TESTING) add_subdirectory(test EXCLUDE_FROM_ALL) endif() install(TARGETS ${PROJECT_NAME} DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}) install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}) ros-resource-retriever-1.12.3/include/000077500000000000000000000000001312316034700176565ustar00rootroot00000000000000ros-resource-retriever-1.12.3/include/resource_retriever/000077500000000000000000000000001312316034700235745ustar00rootroot00000000000000ros-resource-retriever-1.12.3/include/resource_retriever/retriever.h000066400000000000000000000055411312316034700257610ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * 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 names of Stanford University or 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. */ #ifndef RESOURCE_RETRIEVER_RETRIEVER_H #define RESOURCE_RETRIEVER_RETRIEVER_H #include #include #include #include typedef void CURL; namespace resource_retriever { class Exception : public std::runtime_error { public: Exception(const std::string& file, const std::string& error_msg) : std::runtime_error("Error retrieving file [" + file + "]: " + error_msg) {} }; /** * \brief A combination of a pointer to data in memory along with the data's size. */ struct MemoryResource { MemoryResource() : size(0) {} boost::shared_array data; uint32_t size; }; /** * \brief Retrieves files from from a url. Caches a CURL handle so multiple accesses to a single url * will keep connections open. */ class Retriever { public: Retriever(); ~Retriever(); /** * \brief Get a file and store it in memory * \param url The url to retrieve. package://package/file will be turned into the correct file:// invocation * \return The file, loaded into memory * \throws resource_retriever::Exception if anything goes wrong. */ MemoryResource get(const std::string& url); private: Retriever(const Retriever & ret) = delete; CURL* curl_handle_; }; } // namespace resource_retriever #endif // RESOURCE_RETRIEVER_RETRIEVER_H ros-resource-retriever-1.12.3/mainpage.dox000066400000000000000000000005301312316034700205260ustar00rootroot00000000000000/** \mainpage \htmlinclude manifest.html \b resource_retriever is a package used for downloading files from a url. It also provides special handling of the package:// prefix, allowing things to be referenced by path relative to a package. \section codeapi Code API - resource_retriever::Retriever -- Use this class to download files. */ros-resource-retriever-1.12.3/package.xml000066400000000000000000000025221312316034700203510ustar00rootroot00000000000000 resource_retriever 1.12.3 This package retrieves data from url-format files such as http://, ftp://, package:// file://, etc., and loads the data into memory. The package:// url for ros packages is translated into a local file:// url. The resourse retriever was initially designed to load mesh files into memory, but it can be used for any type of data. The resource retriever is based on the the libcurl library. Josh Faust Ioan Sucan Chris Lalancette Shane Loretz BSD http://ros.org/wiki/resource_retriever https://github.com/ros/robot_model https://github.com/ros/robot_model/issues catkin curl rosconsole roslib curl rosconsole roslib python-rospkg ros-resource-retriever-1.12.3/setup.py000066400000000000000000000003421312316034700177440ustar00rootroot00000000000000from distutils.core import setup from catkin_pkg.python_setup import generate_distutils_setup d = generate_distutils_setup() d['packages'] = ['resource_retriever'] d['scripts'] = [] d['package_dir'] = {'': 'src'} setup(**d) ros-resource-retriever-1.12.3/src/000077500000000000000000000000001312316034700170225ustar00rootroot00000000000000ros-resource-retriever-1.12.3/src/resource_retriever/000077500000000000000000000000001312316034700227405ustar00rootroot00000000000000ros-resource-retriever-1.12.3/src/resource_retriever/__init__.py000066400000000000000000000051501312316034700250520ustar00rootroot00000000000000# Software License Agreement (BSD License) # # Copyright (c) 2008, 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 the Willow Garage 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. # import roslib; roslib.load_manifest('resource_retriever') import subprocess import rospkg try: from urllib.request import urlopen from urllib.error import URLError except ImportError: from urllib2 import urlopen from urllib2 import URLError PACKAGE_PREFIX = 'package://' r = rospkg.RosPack() def get_filename(url, use_protocol=True ): mod_url = url if url.find(PACKAGE_PREFIX) == 0: mod_url = url[len(PACKAGE_PREFIX):] pos = mod_url.find('/') if pos == -1: raise Exception("Could not parse package:// format into file:// format for "+url) package = mod_url[0:pos] mod_url = mod_url[pos:] package_path = r.get_path(package) if use_protocol: protocol = "file://" else: protocol = "" mod_url = protocol + package_path + mod_url; return mod_url def get(url): filename = get_filename(url) try: return urlopen(filename).read() except URLError: raise Exception("Invalid URL: {}".format(filename)) ros-resource-retriever-1.12.3/src/retriever.cpp000066400000000000000000000076171312316034700215500ustar00rootroot00000000000000/* * Copyright (C) 2009, Willow Garage, Inc. * * 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 names of Stanford University or 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. */ #include "resource_retriever/retriever.h" #include #include #include #include namespace resource_retriever { class CURLStaticInit { public: CURLStaticInit() : initialized_(false) { CURLcode ret = curl_global_init(CURL_GLOBAL_ALL); if (ret != 0) { ROS_ERROR("Error initializing libcurl! retcode = %d", ret); } else { initialized_ = true; } } ~CURLStaticInit() { if (initialized_) { curl_global_cleanup(); } } bool initialized_; }; static CURLStaticInit g_curl_init; Retriever::Retriever() { curl_handle_ = curl_easy_init(); } Retriever::~Retriever() { if (curl_handle_) { curl_easy_cleanup(curl_handle_); } } struct MemoryBuffer { std::vector v; }; size_t curlWriteFunc(void* buffer, size_t size, size_t nmemb, void* userp) { MemoryBuffer* membuf = (MemoryBuffer*)userp; size_t prev_size = membuf->v.size(); membuf->v.resize(prev_size + size * nmemb); memcpy(&membuf->v[prev_size], buffer, size * nmemb); return size * nmemb; } MemoryResource Retriever::get(const std::string& url) { std::string mod_url = url; if (url.find("package://") == 0) { mod_url.erase(0, strlen("package://")); size_t pos = mod_url.find("/"); if (pos == std::string::npos) { throw Exception(url, "Could not parse package:// format into file:// format"); } std::string package = mod_url.substr(0, pos); mod_url.erase(0, pos); std::string package_path = ros::package::getPath(package); if (package_path.empty()) { throw Exception(url, "Package [" + package + "] does not exist"); } mod_url = "file://" + package_path + mod_url; } curl_easy_setopt(curl_handle_, CURLOPT_URL, mod_url.c_str()); curl_easy_setopt(curl_handle_, CURLOPT_WRITEFUNCTION, curlWriteFunc); char error_buffer[CURL_ERROR_SIZE]; curl_easy_setopt(curl_handle_, CURLOPT_ERRORBUFFER , error_buffer); MemoryResource res; MemoryBuffer buf; curl_easy_setopt(curl_handle_, CURLOPT_WRITEDATA, &buf); CURLcode ret = curl_easy_perform(curl_handle_); if (ret != 0) { throw Exception(mod_url, error_buffer); } else if (!buf.v.empty()) { res.size = buf.v.size(); res.data.reset(new uint8_t[res.size]); memcpy(res.data.get(), &buf.v[0], res.size); } return res; } } ros-resource-retriever-1.12.3/test/000077500000000000000000000000001312316034700172125ustar00rootroot00000000000000ros-resource-retriever-1.12.3/test/CMakeLists.txt000066400000000000000000000003001312316034700217430ustar00rootroot00000000000000set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) catkin_add_gtest(${PROJECT_NAME}_utest test.cpp) target_link_libraries(${PROJECT_NAME}_utest ${PROJECT_NAME}) catkin_add_nosetests(test.py) ros-resource-retriever-1.12.3/test/test.cpp000066400000000000000000000064641312316034700207070ustar00rootroot00000000000000/********************************************************************* * Software License Agreement (BSD License) * * Copyright (c) 2008, 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 the Willow Garage 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. *********************************************************************/ #include #include #include #include using namespace resource_retriever; TEST(Retriever, getByPackage) { try { Retriever r; MemoryResource res = r.get("package://" ROS_PACKAGE_NAME "/test/test.txt"); ASSERT_EQ(res.size, 1); ASSERT_EQ(res.data[0], 'A'); } catch (Exception& e) { FAIL(); } } TEST(Retriever, largeFile) { try { std::string path = ros::package::getPath(ROS_PACKAGE_NAME) + "/test/large_file.dat"; FILE* f = fopen(path.c_str(), "w"); ASSERT_TRUE(f); for (int i = 0; i < 1024*1024*50; ++i) { fprintf(f, "A"); } fclose(f); Retriever r; MemoryResource res = r.get("package://" ROS_PACKAGE_NAME "/test/large_file.dat"); ASSERT_EQ(res.size, 1024*1024*50); } catch (Exception& e) { FAIL(); } } TEST(Retriever, http) { try { Retriever r; MemoryResource res = r.get("http://packages.ros.org/ros.key"); ASSERT_GT(res.size, 0); } catch (Exception& e) { FAIL(); } } TEST(Retriever, invalidFiles) { Retriever r; try { r.get("file://fail"); FAIL(); } catch (Exception& e) { ROS_INFO("%s", e.what()); } try { r.get("package://roscpp"); FAIL(); } catch (Exception& e) { ROS_INFO("%s", e.what()); } try { r.get("package://invalid_package_blah/test.xml"); FAIL(); } catch (Exception& e) { ROS_INFO("%s", e.what()); } } int main(int argc, char **argv){ testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } ros-resource-retriever-1.12.3/test/test.py000066400000000000000000000016501312316034700205450ustar00rootroot00000000000000import resource_retriever as r import os import rospkg from nose.tools import raises rospack = rospkg.RosPack() def test_get_by_package(): res = r.get("package://resource_retriever/test/test.txt") assert len(res) == 1 assert res == 'A'.encode() def test_get_large_file(): res_path = os.path.join(rospack.get_path("resource_retriever"), "test/large_file.dat") with open(res_path, 'w') as f: for _ in range(1024*1024*50): f.write('A') res = r.get("package://resource_retriever/test/large_file.dat") assert len(res) == 1024*1024*50 def test_http(): res = r.get("http://packages.ros.org/ros.key") assert len(res) > 0 @raises(Exception) def test_invalid_file(): r.get("file://fail") @raises(Exception) def test_no_file(): r.get("package://roscpp") @raises(rospkg.common.ResourceNotFound) def test_invalid_package(): r.get("package://invalid_package_blah/test.xml") ros-resource-retriever-1.12.3/test/test.txt000066400000000000000000000000011312316034700207210ustar00rootroot00000000000000A