From 210654ace651646b87c2849e96ef8f391bd76ad1 Mon Sep 17 00:00:00 2001 From: William Woodall Date: Tue, 21 Apr 2015 18:16:28 -0700 Subject: [PATCH] move resource_retriever to its own repository --- resource_retriever/CHANGELOG.rst | 38 ----- resource_retriever/CMakeLists.txt | 37 ----- .../include/resource_retriever/retriever.h | 86 ---------- resource_retriever/mainpage.dox | 14 -- resource_retriever/package.xml | 33 ---- resource_retriever/setup.py | 9 -- .../src/resource_retriever/__init__.py | 69 -------- resource_retriever/src/retriever.cpp | 147 ------------------ resource_retriever/test/CMakeLists.txt | 4 - resource_retriever/test/test.cpp | 140 ----------------- resource_retriever/test/test.txt | 1 - 11 files changed, 578 deletions(-) delete mode 100644 resource_retriever/CHANGELOG.rst delete mode 100644 resource_retriever/CMakeLists.txt delete mode 100644 resource_retriever/include/resource_retriever/retriever.h delete mode 100644 resource_retriever/mainpage.dox delete mode 100644 resource_retriever/package.xml delete mode 100644 resource_retriever/setup.py delete mode 100644 resource_retriever/src/resource_retriever/__init__.py delete mode 100644 resource_retriever/src/retriever.cpp delete mode 100644 resource_retriever/test/CMakeLists.txt delete mode 100644 resource_retriever/test/test.cpp delete mode 100644 resource_retriever/test/test.txt diff --git a/resource_retriever/CHANGELOG.rst b/resource_retriever/CHANGELOG.rst deleted file mode 100644 index 5c95286..0000000 --- a/resource_retriever/CHANGELOG.rst +++ /dev/null @@ -1,38 +0,0 @@ -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Changelog for package resource_retriever -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -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 diff --git a/resource_retriever/CMakeLists.txt b/resource_retriever/CMakeLists.txt deleted file mode 100644 index f34b0da..0000000 --- a/resource_retriever/CMakeLists.txt +++ /dev/null @@ -1,37 +0,0 @@ -cmake_minimum_required(VERSION 2.8.3) -project(resource_retriever) - -find_package(catkin REQUIRED COMPONENTS rosconsole roslib) - -catkin_python_setup() - -catkin_package( - LIBRARIES ${PROJECT_NAME} - INCLUDE_DIRS include) - -include_directories(include) - -find_package(catkin REQUIRED COMPONENTS rosconsole roslib) -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}) diff --git a/resource_retriever/include/resource_retriever/retriever.h b/resource_retriever/include/resource_retriever/retriever.h deleted file mode 100644 index c1fcf15..0000000 --- a/resource_retriever/include/resource_retriever/retriever.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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: - CURL* curl_handle_; -}; - -} // namespace resource_retriever - -#endif // RESOURCE_RETRIEVER_RETRIEVER_H diff --git a/resource_retriever/mainpage.dox b/resource_retriever/mainpage.dox deleted file mode 100644 index a06a758..0000000 --- a/resource_retriever/mainpage.dox +++ /dev/null @@ -1,14 +0,0 @@ -/** -\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. - - -*/ \ No newline at end of file diff --git a/resource_retriever/package.xml b/resource_retriever/package.xml deleted file mode 100644 index cb41684..0000000 --- a/resource_retriever/package.xml +++ /dev/null @@ -1,33 +0,0 @@ - - resource_retriever - 1.11.6 - - 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 - - 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-urlgrabber - - diff --git a/resource_retriever/setup.py b/resource_retriever/setup.py deleted file mode 100644 index f712a40..0000000 --- a/resource_retriever/setup.py +++ /dev/null @@ -1,9 +0,0 @@ -from 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) diff --git a/resource_retriever/src/resource_retriever/__init__.py b/resource_retriever/src/resource_retriever/__init__.py deleted file mode 100644 index d92baca..0000000 --- a/resource_retriever/src/resource_retriever/__init__.py +++ /dev/null @@ -1,69 +0,0 @@ -# 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 urlgrabber, string - -PACKAGE_PREFIX = 'package://' - -def rospack_find(package): - process = subprocess.Popen(['rospack', 'find', package], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - (stdout, stderr) = process.communicate() - if len(stderr) > 0: - raise Exception(stderr) - else: - return string.strip(stdout) - -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 = rospack_find(package) - - if use_protocol: - protocol = "file://" - else: - protocol = "" - mod_url = protocol + package_path + mod_url; - return mod_url - -def get(url): - return urlgrabber.urlopen(get_filename(url)) - diff --git a/resource_retriever/src/retriever.cpp b/resource_retriever/src/retriever.cpp deleted file mode 100644 index b09a981..0000000 --- a/resource_retriever/src/retriever.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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; -} - -} diff --git a/resource_retriever/test/CMakeLists.txt b/resource_retriever/test/CMakeLists.txt deleted file mode 100644 index f133bf6..0000000 --- a/resource_retriever/test/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}) - -catkin_add_gtest(${PROJECT_NAME}_utest test.cpp) -target_link_libraries(${PROJECT_NAME}_utest ${PROJECT_NAME}) diff --git a/resource_retriever/test/test.cpp b/resource_retriever/test/test.cpp deleted file mode 100644 index b29f40e..0000000 --- a/resource_retriever/test/test.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/********************************************************************* -* 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://pr.willowgarage.com/downloads/svnmerge.py"); - - 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(); -} - diff --git a/resource_retriever/test/test.txt b/resource_retriever/test/test.txt deleted file mode 100644 index 8c7e5a6..0000000 --- a/resource_retriever/test/test.txt +++ /dev/null @@ -1 +0,0 @@ -A \ No newline at end of file