move resource_retriever to its own repository

This commit is contained in:
William Woodall 2015-04-21 18:16:28 -07:00
parent 137268dc21
commit 210654ace6
11 changed files with 0 additions and 578 deletions

View File

@ -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

View File

@ -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})

View File

@ -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 <stdint.h>
#include <string>
#include <boost/shared_array.hpp>
#include <stdexcept>
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<uint8_t> 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

View File

@ -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.
*/

View File

@ -1,33 +0,0 @@
<package>
<name>resource_retriever</name>
<version>1.11.6</version>
<description>
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.
</description>
<author email="jfaust@willowgarage.com">Josh Faust</author>
<maintainer email="isucan@gmail.com">Ioan Sucan</maintainer>
<license>BSD</license>
<url type="website">http://ros.org/wiki/resource_retriever</url>
<url type="repository">https://github.com/ros/robot_model</url>
<url type="bugtracker">https://github.com/ros/robot_model/issues</url>
<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>
<build_depend>curl</build_depend>
<build_depend>rosconsole</build_depend>
<build_depend>roslib</build_depend>
<run_depend>curl</run_depend>
<run_depend>rosconsole</run_depend>
<run_depend>roslib</run_depend>
<run_depend>python-urlgrabber</run_depend>
</package>

View File

@ -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)

View File

@ -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))

View File

@ -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 <string.h>
#include <ros/package.h>
#include <ros/console.h>
#include <curl/curl.h>
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<uint8_t> 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;
}
}

View File

@ -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})

View File

@ -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 <gtest/gtest.h>
#include <resource_retriever/retriever.h>
#include <ros/package.h>
#include <ros/console.h>
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();
}

View File

@ -1 +0,0 @@
A