Commits

Nathan Koenig committed dc7a139 Merge

Merged in model_db_renaming (pull request #242)

Renaming model database manifest files

Comments (0)

Files changed (5)

gazebo/common/ModelDatabase.cc

 }
 
 /////////////////////////////////////////////////
-std::string ModelDatabase::GetManifest(const std::string &_uri)
+std::string ModelDatabase::GetDBConfig(const std::string &_uri)
 {
   std::string xmlString;
   std::string uri = _uri;
 
   if (!uri.empty())
   {
-    std::string manifestURI = uri + "/manifest.xml";
+    std::string manifestURI = uri + "/" + GZ_MODEL_DB_MANIFEST_FILENAME;
+    xmlString = this->GetManifestImpl(manifestURI);
+  }
 
+  return xmlString;
+}
+
+/////////////////////////////////////////////////
+std::string ModelDatabase::GetModelConfig(const std::string &_uri)
+{
+  std::string xmlString;
+  std::string uri = _uri;
+  boost::replace_first(uri, "model://", ModelDatabase::GetURI());
+
+  if (!uri.empty())
+  {
+    std::string manifestURI = uri + "/" + GZ_MODEL_MANIFEST_FILENAME;
+    xmlString = this->GetManifestImpl(manifestURI);
+  }
+
+  return xmlString;
+}
+
+/////////////////////////////////////////////////
+std::string ModelDatabase::GetManifest(const std::string &_uri)
+{
+  return this->GetModelConfig(_uri);
+}
+
+/////////////////////////////////////////////////
+std::string ModelDatabase::GetManifestImpl(const std::string &_uri)
+{
+  std::string xmlString;
+  if (!_uri.empty())
+  {
     CURL *curl = curl_easy_init();
-    curl_easy_setopt(curl, CURLOPT_URL, manifestURI.c_str());
+    curl_easy_setopt(curl, CURLOPT_URL, _uri.c_str());
 
     curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_models_cb);
     curl_easy_setopt(curl, CURLOPT_WRITEDATA, &xmlString);
   return xmlString;
 }
 
-
 /////////////////////////////////////////////////
 bool ModelDatabase::UpdateModelCacheImpl()
 {
-  std::string xmlString = ModelDatabase::GetManifest(ModelDatabase::GetURI());
+  std::string xmlString = ModelDatabase::GetDBConfig(ModelDatabase::GetURI());
 
   if (!xmlString.empty())
   {
     TiXmlElement *databaseElem = xmlDoc.FirstChildElement("database");
     if (!databaseElem)
     {
-      gzerr << "No <database> tag in the model database manifest.xml found"
-        << " here[" << ModelDatabase::GetURI() << "]\n";
+      gzerr << "No <database> tag in the model database "
+            << GZ_MODEL_DB_MANIFEST_FILENAME << " found"
+            << " here[" << ModelDatabase::GetURI() << "]\n";
       return false;
     }
 
     TiXmlElement *modelsElem = databaseElem->FirstChildElement("models");
     if (!modelsElem)
     {
-      gzerr << "No <models> tag in the model database manifest.xml found"
+      gzerr << "No <models> tag in the model database "
+        << GZ_MODEL_DB_MANIFEST_FILENAME << " found"
         << " here[" << ModelDatabase::GetURI() << "]\n";
       return false;
     }
 std::string ModelDatabase::GetModelName(const std::string &_uri)
 {
   std::string result;
-  std::string xmlStr = ModelDatabase::GetManifest(_uri);
+  std::string xmlStr = ModelDatabase::GetModelConfig(_uri);
 
   if (!xmlStr.empty())
   {
         if (nameElem)
           result = nameElem->GetText();
         else
-          gzerr << "No <name> element in manifest.xml for model["
-                << _uri << "]\n";
+          gzerr << "No <name> element in " << GZ_MODEL_MANIFEST_FILENAME
+                << " for model[" << _uri << "]\n";
       }
       else
-        gzerr << "No <model> element in manifest.xml for model["
-              << _uri << "]\n";
+        gzerr << "No <model> element in " << GZ_MODEL_MANIFEST_FILENAME
+              << " for model[" << _uri << "]\n";
     }
     else
-      gzerr << "Unable to parse manifest.xml for model[" << _uri << "]\n";
+      gzerr << "Unable to parse " << GZ_MODEL_MANIFEST_FILENAME
+            << " for model[" << _uri << "]\n";
   }
   else
     gzerr << "Unable to get model name[" << _uri << "]\n";
 /////////////////////////////////////////////////
 void ModelDatabase::DownloadDependencies(const std::string &_path)
 {
-  std::string manifest = _path + "/manifest.xml";
+  boost::filesystem::path manifestPath = _path;
+
+  // First try to get the GZ_MODEL_MANIFEST_FILENAME. If that file doesn't
+  // exist, try to get the deprecated version.
+  if (boost::filesystem::exists(manifestPath / GZ_MODEL_MANIFEST_FILENAME))
+    manifestPath /= GZ_MODEL_MANIFEST_FILENAME;
+  else
+  {
+    gzwarn << "The manifest.xml for a Gazebo model is deprecated. "
+      << "Please rename manifest.xml to " << GZ_MODEL_MANIFEST_FILENAME
+      << " for model " << _path << "\n";
+
+    manifestPath /= "manifest.xml";
+  }
 
   TiXmlDocument xmlDoc;
-  if (xmlDoc.LoadFile(manifest))
+  if (xmlDoc.LoadFile(manifestPath.string()))
   {
     TiXmlElement *modelXML = xmlDoc.FirstChildElement("model");
     if (!modelXML)
       else
       {
         gzerr << "Model depend is missing <uri> in manifest["
-              << manifest << "]\n";
+              << manifestPath << "]\n";
       }
     }
   }
   else
-    gzerr << "Unable to load manifest file[" << manifest << "]\n";
+    gzerr << "Unable to load manifest file[" << manifestPath << "]\n";
 }
 
 /////////////////////////////////////////////////
   // This will download the model if necessary
   std::string path = ModelDatabase::GetModelPath(_uri);
 
-  std::string manifest = path + "/manifest.xml";
+  boost::filesystem::path manifestPath = path;
+
+  // First try to get the GZ_MODEL_MANIFEST_FILENAME. If that file doesn't
+  // exist, try to get the deprecated version.
+  if (boost::filesystem::exists(manifestPath / GZ_MODEL_MANIFEST_FILENAME))
+    manifestPath /= GZ_MODEL_MANIFEST_FILENAME;
+  else
+  {
+    gzwarn << "The manifest.xml for a Gazebo model is deprecated. "
+      << "Please rename manifest.xml to " << GZ_MODEL_MANIFEST_FILENAME
+      << " for model " << manifestPath << "\n";
+
+    manifestPath /= "manifest.xml";
+  }
 
   TiXmlDocument xmlDoc;
-  if (xmlDoc.LoadFile(manifest))
+  if (xmlDoc.LoadFile(manifestPath.string()))
   {
     TiXmlElement *modelXML = xmlDoc.FirstChildElement("model");
     if (modelXML)
       }
       else
       {
-        gzerr << "Manifest[" << manifest << "] doesn't have "
+        gzerr << "Manifest[" << manifestPath << "] doesn't have "
               << "<model><sdf>...</sdf></model> element.\n";
       }
     }
     else
     {
-      gzerr << "Manifest[" << manifest << "] doesn't have a <model> element\n";
+      gzerr << "Manifest[" << manifestPath
+            << "] doesn't have a <model> element\n";
     }
   }
   else
   {
-    gzerr << "Invalid model manifest file[" << manifest << "]\n";
+    gzerr << "Invalid model manifest file[" << manifestPath << "]\n";
   }
 
   return result;

gazebo/common/ModelDatabase.hh

 #include <boost/thread/mutex.hpp>
 #include "gazebo/common/SingletonT.hh"
 
+/// \brief The file name of model XML configuration.
+#define GZ_MODEL_MANIFEST_FILENAME "model.config"
+
+/// \brief The file name of model database XML configuration.
+#define GZ_MODEL_DB_MANIFEST_FILENAME "database.config"
+
 namespace gazebo
 {
   namespace common
       /// \return the model's name.
       public: std::string GetModelName(const std::string &_uri);
 
-      /// \brief Return the manifest.xml file as a string.
-      /// \return the manifest file from the model database.
-      public: std::string GetManifest(const std::string &_uri);
+      /// \brief Return the model.config file as a string.
+      /// \return The model config file from the model database.
+      public: std::string GetModelConfig(const std::string &_uri);
+
+      /// \brief Return the database.config file as a string.
+      /// \return The database config file from the model database.
+      public: std::string GetDBConfig(const std::string &_uri);
+
+      /// \brief Deprecated.
+      /// \sa ModelDatabase::GetModelConfig
+      /// \sa ModelDatabase::GetDBConfig
+      public: std::string GetManifest(const std::string &_uri)
+              GAZEBO_DEPRECATED;
 
       /// \brief Get the local path to a model.
       ///
 
       /// \brief Download all dependencies for a give model path
       ///
-      /// Look's in the model's manifest file (_path/manifest.xml) for all
-      /// models listed in the <depend> block, and downloads the models if
-      /// necessary.
+      /// Look's in the model's manifest file (_path/model.config)
+      /// for all models listed in the <depend> block, and downloads the
+      /// models if necessary.
       /// \param[in] _path Path to a model.
       public: void DownloadDependencies(const std::string &_path);
 
       /// \return True if the model was found.
       public: bool HasModel(const std::string &_modelName);
 
+      /// \brief A helper function that uses CURL to get a manifest file.
+      /// \param[in] _uri URI of a manifest XML file.
+      /// \return The contents of the manifest file.
+      private: std::string GetManifestImpl(const std::string &_uri);
+
       /// \brief Used by a thread to update the model cache.
       private: void UpdateModelCache();
 

gazebo/gui/InsertModelWidget.cc

     {
       std::string modelName;
       boost::filesystem::path fullPath = _path / dIter->filename();
-      boost::filesystem::path manifest = fullPath / "manifest.xml";
+      boost::filesystem::path manifest = fullPath;
+
+      if (!boost::filesystem::is_directory(fullPath))
+      {
+        if (dIter->filename() == "manifest.xml")
+        {
+          boost::filesystem::path tmpPath = boost::filesystem::path(_path) /
+            "database.config";
+          gzwarn << "manifest.xml for a model database is deprecated. "
+                 << "Please rename " << fullPath <<  " to "
+                 << tmpPath << "\n";
+        }
+        else if (dIter->filename() != "database.config")
+        {
+          gzwarn << "Invalid filename or directory[" << fullPath
+            << "] in GAZEBO_MODEL_PATH. It's not a good idea to put extra "
+            << "files in a GAZEBO_MODEL_PATH because the file structure may"
+            << " be modified by Gazebo.\n";
+        }
+        continue;
+      }
+
+      // First try to get the GZ_MODEL_MANIFEST_FILENAME. If that file doesn't
+      // exist, try to get the deprecated version.
+      if (boost::filesystem::exists(manifest / GZ_MODEL_MANIFEST_FILENAME))
+        manifest /= GZ_MODEL_MANIFEST_FILENAME;
+      else if (boost::filesystem::exists(manifest / "manifest.xml"))
+      {
+        gzwarn << "The manifest.xml for a Gazebo model is deprecated. "
+          << "Please rename manifest.xml to "
+          << GZ_MODEL_MANIFEST_FILENAME << " for model "
+          << (*dIter) << "\n";
+
+        manifest /= "manifest.xml";
+      }
+
+      if (!boost::filesystem::exists(manifest) || manifest == fullPath)
+      {
+        gzerr << "model.config file is missing in directory["
+              << fullPath << "]\n";
+        continue;
+      }
 
       TiXmlDocument xmlDoc;
       if (xmlDoc.LoadFile(manifest.string()))

gazebo/rendering/RTShaderSystem.cc

File contents unchanged.

gazebo/sdf/interface/parser.cc

             }
           }
 
-          std::string manifest = modelPath + "/manifest.xml";
+          boost::filesystem::path manifestPath = modelPath;
+
+          // First try to get the GZ_MODEL_MANIFEST_FILENAME.
+          // If that file doesn't exist, try to get the deprecated version.
+          if (boost::filesystem::exists(
+                manifestPath / GZ_MODEL_MANIFEST_FILENAME))
+          {
+            manifestPath /= GZ_MODEL_MANIFEST_FILENAME;
+          }
+          else
+          {
+            gzwarn << "The manifest.xml for a Gazebo model is deprecated. "
+                   << "Please rename manifest.xml to "
+                   << GZ_MODEL_MANIFEST_FILENAME << ".\n";
+
+            manifestPath /= "manifest.xml";
+          }
 
           TiXmlDocument manifestDoc;
-          if (manifestDoc.LoadFile(manifest))
+          if (manifestDoc.LoadFile(manifestPath.string()))
           {
             TiXmlElement *modelXML = manifestDoc.FirstChildElement("model");
             if (!modelXML)
-              gzerr << "No <model> element in manifest[" << manifest << "]\n";
+              gzerr << "No <model> element in manifest["
+                    << manifestPath << "]\n";
             else
             {
               TiXmlElement *sdfXML = modelXML->FirstChildElement("sdf");