Skip to content

Commit

Permalink
Merge pull request #124 from ignitionrobotics/jshep1/add_model_config…
Browse files Browse the repository at this point in the history
…_dep_download

Add support for model config dependencies
  • Loading branch information
John Shepherd authored Oct 12, 2020
2 parents 86cfba8 + 90e1069 commit f7fd8eb
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/FuelClient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,8 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id,
{
std::string metadataPath =
ignition::common::joinPaths(path, "metadata.pbtxt");
std::string modelConfigPath =
ignition::common::joinPaths(path, "model.config");
if (ignition::common::exists(metadataPath))
{
// Read the pbtxt file.
Expand All @@ -704,6 +706,28 @@ Result FuelClient::DownloadModel(const ModelIdentifier &_id,
// Parse the file into the fuel metadata message
google::protobuf::TextFormat::ParseFromString(inputStr, &meta);

for (int i = 0; i < meta.dependencies_size(); i++)
{
std::string dependencyPath;
ignition::common::URI dependencyURI(meta.dependencies(i).uri());

// If the model is not already cached, download it; this prevents
// any sort of cyclic dependencies fromo running infinitely
if (!this->CachedModel(dependencyURI, dependencyPath))
this->DownloadModel(dependencyURI, dependencyPath);
}
}
else if (ignition::common::exists(modelConfigPath))
{
std::ifstream inputFile(modelConfigPath);
std::string inputStr((std::istreambuf_iterator<char>(inputFile)),
std::istreambuf_iterator<char>());

if (!ignition::msgs::ConvertFuelMetadata(inputStr, meta))
{
return Result(ResultType::UPLOAD_ERROR);
}

for (int i = 0; i < meta.dependencies_size(); i++)
{
std::string dependencyPath;
Expand Down

0 comments on commit f7fd8eb

Please sign in to comment.