Added useful feature: include other paths in sami

This way you can include other repositories into
the Salt.Mine XML:

  <salt-mine>
    <salt-grain>
      ...
    </salt-grain>
    <include>http://from.other.source/repository.xml</include>
  </salt-mine>
This commit is contained in:
Matthias Koefferlein 2017-10-03 17:47:40 +02:00
parent 469eb47068
commit 6f51c0be2e
2 changed files with 26 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "laySaltGrains.h"
#include "tlString.h"
#include "tlFileUtils.h"
#include "tlLog.h"
#include <QDir>
#include <QFileInfo>
@ -235,6 +236,7 @@ SaltGrains::from_path (const std::string &path, const std::string &prefix)
static tl::XMLElementList s_group_struct =
tl::make_member (&SaltGrains::name, &SaltGrains::set_name, "name") +
tl::make_member (&SaltGrains::include, "include") +
tl::make_element (&SaltGrains::begin_collections, &SaltGrains::end_collections, &SaltGrains::add_collection, "group", &s_group_struct) +
tl::make_element (&SaltGrains::begin_grains, &SaltGrains::end_grains, &SaltGrains::add_grain, "salt-grain", SaltGrain::xml_elements ());
@ -254,6 +256,23 @@ SaltGrains::load (tl::InputStream &p)
s_xml_struct.parse (source, *this);
}
void
SaltGrains::include (const std::string &src)
{
if (! src.empty ()) {
if (tl::verbosity () >= 20) {
tl::log << "Including package index from " << src;
}
lay::SaltGrains g;
g.load (src);
m_collections.splice (m_collections.end (), g.m_collections);
m_grains.splice (m_grains.end (), g.m_grains);
}
}
void
SaltGrains::save (const std::string &p) const
{

View File

@ -108,6 +108,13 @@ public:
*/
void set_path (const std::string &p);
/**
* @brief Includes a list from an external source into this list
* This method reads the other list from the source (an URL) and
* merges it into this.
*/
void include (const std::string &src);
/**
* @brief Gets the collections which are members of this collection (begin iterator)
*/