[resource-retriever] 01/01: Imported Upstream version 1.11.6

Jochen Sprickerhof jspricke-guest at moszumanska.debian.org
Tue Aug 4 21:55:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

jspricke-guest pushed a commit to annotated tag upstream/1.11.6
in repository resource-retriever.

commit 60c44397066d8be31c99d694b815d1976d3d6f1f
Author: Jochen Sprickerhof <git at jochen.sprickerhof.de>
Date:   Tue Aug 4 23:43:22 2015 +0200

    Imported Upstream version 1.11.6
---
 CHANGELOG.rst                          |  38 +++++++++
 CMakeLists.txt                         |  37 +++++++++
 include/resource_retriever/retriever.h |  86 +++++++++++++++++++
 mainpage.dox                           |  14 ++++
 package.xml                            |  32 +++++++
 setup.py                               |   9 ++
 src/resource_retriever/__init__.py     |  69 ++++++++++++++++
 src/retriever.cpp                      | 147 +++++++++++++++++++++++++++++++++
 test/CMakeLists.txt                    |   4 +
 test/test.cpp                          | 140 +++++++++++++++++++++++++++++++
 test/test.txt                          |   1 +
 11 files changed, 577 insertions(+)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
new file mode 100644
index 0000000..5c95286
--- /dev/null
+++ b/CHANGELOG.rst
@@ -0,0 +1,38 @@
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+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/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..f34b0da
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,37 @@
+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/include/resource_retriever/retriever.h b/include/resource_retriever/retriever.h
new file mode 100644
index 0000000..c1fcf15
--- /dev/null
+++ b/include/resource_retriever/retriever.h
@@ -0,0 +1,86 @@
+/*
+ * 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
diff --git a/mainpage.dox b/mainpage.dox
new file mode 100644
index 0000000..a06a758
--- /dev/null
+++ b/mainpage.dox
@@ -0,0 +1,14 @@
+/**
+\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/package.xml b/package.xml
new file mode 100644
index 0000000..4a2a532
--- /dev/null
+++ b/package.xml
@@ -0,0 +1,32 @@
+<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 at willowgarage.com">Josh Faust</author>
+  <maintainer email="isucan at 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>
+
+</package>
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..f712a40
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,9 @@
+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/src/resource_retriever/__init__.py b/src/resource_retriever/__init__.py
new file mode 100644
index 0000000..d92baca
--- /dev/null
+++ b/src/resource_retriever/__init__.py
@@ -0,0 +1,69 @@
+# 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/src/retriever.cpp b/src/retriever.cpp
new file mode 100644
index 0000000..b09a981
--- /dev/null
+++ b/src/retriever.cpp
@@ -0,0 +1,147 @@
+/*
+ * 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;
+}
+
+}
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..f133bf6
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,4 @@
+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/test/test.cpp b/test/test.cpp
new file mode 100644
index 0000000..b29f40e
--- /dev/null
+++ b/test/test.cpp
@@ -0,0 +1,140 @@
+/*********************************************************************
+* 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();
+}
+
diff --git a/test/test.txt b/test/test.txt
new file mode 100644
index 0000000..8c7e5a6
--- /dev/null
+++ b/test/test.txt
@@ -0,0 +1 @@
+A
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ros/resource-retriever.git



More information about the debian-science-commits mailing list