13 #include <unordered_map>
30 #undef ZYPP_BASE_LOGGER_LOGGROUP
31 #define ZYPP_BASE_LOGGER_LOGGROUP "parser"
49 void setVar(
const std::string & key_r,
const std::string & val_r )
51 MIL <<
"*** Inject " << key_r <<
" = " << val_r;
52 _vars[key_r] = replace( val_r );
53 MIL <<
" (" <<
_vars[key_r] <<
")" << endl;
56 std::string replace(
const std::string & val_r )
const
59 if ( vbeg == std::string::npos )
64 for( ; vbeg != std::string::npos; vbeg = val_r.find(
"%{", vbeg ) )
68 if ( nend == std::string::npos )
70 WAR <<
"Incomplete variable in '" << val_r <<
"'" << endl;
73 const auto & iter =
_vars.find( val_r.substr( nbeg, nend-nbeg ) );
74 if ( iter !=
_vars.end() )
77 ret << val_r.substr( cbeg, vbeg-cbeg );
82 WAR <<
"Undefined variable %{" << val_r.substr( nbeg, nend-nbeg ) <<
"} in '" << val_r <<
"'" << endl;
85 if ( cbeg < val_r.size() )
86 ret << val_r.substr( cbeg );
91 std::unordered_map<std::string,std::string>
_vars;
116 bool getAttrValue(
const std::string & key_r, Reader & reader_r, std::string & value_r )
118 const XmlString & s( reader_r->getAttribute( key_r ) );
121 value_r =
_replacer.replace( s.asString() );
122 return !value_r.empty();
140 MIL <<
"Reading " << is.
path() << endl;
159 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
162 if ( reader_r->name() ==
"repoindex" )
164 while ( reader_r.nextNodeAttribute() )
165 _replacer.setVar( reader_r->localName().asString(), reader_r->value().asString() );
170 if ( reader_r->name() ==
"repo" )
177 std::string attrValue;
181 if ( getAttrValue(
"alias", reader_r, attrValue ) )
184 _replacer.setVar(
"alias", attrValue );
194 getAttrValue(
"url", reader_r, urlstr );
195 getAttrValue(
"path", reader_r, pathstr );
196 if ( urlstr.empty() )
198 if ( pathstr.empty() )
201 info.
setPath( Pathname(
"/repo") / pathstr );
205 if ( pathstr.empty() )
217 if ( getAttrValue(
"name", reader_r, attrValue ) )
221 if ( getAttrValue(
"distro_target", reader_r, attrValue ) )
225 if ( getAttrValue(
"priority", reader_r, attrValue ) )
226 info.
setPriority( str::strtonum<unsigned>( attrValue ) );
230 if ( getAttrValue(
"enabled", reader_r, attrValue ) )
234 if ( getAttrValue(
"autorefresh", reader_r, attrValue ) )
263 : _pimpl(new
Impl(is, callback))
function< bool(const RepoInfo &)> ProcessResource
Callback definition.
ProcessResource _callback
Function for processing collected data.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
void setPriority(unsigned newval_r)
Set repository priority for solver.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
void setEnabled(bool enabled)
enable or disable the repository
void setAlias(const std::string &alias)
set the repository alias
What is known about a repository.
void setBaseUrl(const Url &url)
Clears current base URL list and adds url.
bool enabled() const
If enabled is false, then this repository must be ignored as if does not exists, except when checking...
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
std::unordered_map< std::string, std::string > _vars
const ProcessCredentials & _callback
Interface of repoindex.xml file reader.
RepoindexFileReader(const zypp::Pathname &repoindexFile, const ProcessResource &callback)
CTOR.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
~RepoindexFileReader()
DTOR.
void setPath(const Pathname &path)
set the product path.
void setTargetDistribution(const std::string &targetDistribution)
Sets the distribution for which is this repository meant.
bool autorefresh() const
If true, the repostory must be refreshed before creating resolvables from it.
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
Impl(const InputStream &is, const ProcessResource &callback)
CTOR.
void setName(const std::string &name)
set the repository name
bool getAttrValue(const std::string &key_r, Reader &reader_r, std::string &value_r)
bool consumeNode(Reader &reader_r)
Callback provided to the XML parser.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl