13#include <zypp/base/Logger.h>
14#include <zypp/base/String.h>
15#include <zypp/base/Regex.h>
16#include <zypp-core/base/InputStream>
17#include <zypp-core/base/UserRequestException>
19#include <zypp-core/parser/IniDict>
55 MIL << (*its) << endl;
58 std::map<std::string,std::pair<std::string,ServiceInfo::RepoState>> repoStates;
65 if ( it->first ==
"name" )
67 else if ( it->first ==
"url" && ! it->second.empty() )
69 else if ( it->first ==
"enabled" )
71 else if ( it->first ==
"autorefresh" )
73 else if ( it->first ==
"type" )
75 else if ( it->first ==
"ttl_sec" )
76 service.
setTtl( str::strtonum<Date::Duration>(it->second) );
77 else if ( it->first ==
"lrf_dat" )
79 else if ( it->first ==
"repostoenable" )
81 std::vector<std::string> aliases;
83 for_( ait, aliases.begin(), aliases.end() )
88 else if ( it->first ==
"repostodisable" )
90 std::vector<std::string> aliases;
92 for_( ait, aliases.begin(), aliases.end() )
99 static str::regex rxexpr(
"([0-9]+)(_(.*))?" );
103 std::string tag( what[1] );
104 if ( what.
size() > 3 )
107 if ( what[3] ==
"enabled" )
108 repoStates[tag].second.enabled =
str::strToBool( it->second, repoStates[tag].second.enabled );
109 else if ( what[3] ==
"autorefresh" )
110 repoStates[tag].second.autorefresh =
str::strToBool( it->second, repoStates[tag].second.autorefresh );
111 else if ( what[3] ==
"priority" )
112 str::strtonum( it->second, repoStates[tag].second.priority );
114 ERR <<
"Unknown attribute " << it->first <<
" ignored" << endl;
119 repoStates[tag].first = it->second;
123 ERR <<
"Unknown attribute " << it->first <<
" ignored" << endl;
126 ERR <<
"Unknown attribute " << it->first <<
" ignored" << endl;
129 if ( ! repoStates.empty() )
132 for (
const auto & el : repoStates )
134 if ( el.second.first.empty() )
135 ERR <<
"Missing alias for repo_" << el.first <<
"; ignore entry" << endl;
137 data[el.second.first] = el.second.second;
139 if ( ! data.empty() )
143 MIL <<
"Linking ServiceInfo with file " << file << endl;
147 if ( !callback(service) )
Store and operate on date (time_t).
Base class for Exception.
void setLrf(Date lrf_r)
Set date of last refresh.
void setType(const repo::ServiceType &type)
Set service type.
void addRepoToDisable(const std::string &alias_r)
Add alias_r to the set of ReposToDisable.
void setTtl(Date::Duration ttl_r)
Set sugested TTL.
std::map< std::string, RepoState > RepoStates
void addRepoToEnable(const std::string &alias_r)
Add alias_r to the set of ReposToEnable.
void setUrl(const Url &url)
Set the service url (raw value)
void setRepoStates(RepoStates newStates_r)
Remember a new set of repository states.
Parses a INI file and offers its structure as a dictionary.
section_const_iterator sectionsEnd() const
EntrySet::const_iterator entry_const_iterator
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
entry_const_iterator entriesBegin(const std::string §ion) const
section_const_iterator sectionsBegin() const
entry_const_iterator entriesEnd(const std::string §ion) const
static void parseServices(const Pathname &file, const ServiceFileReader::ProcessService &callback)
Read service data from a .service file.
friend std::ostream & operator<<(std::ostream &str, const ServiceFileReader &obj)
function< bool(const ServiceInfo &)> ProcessService
Callback definition.
ServiceFileReader(const Pathname &serviceFile, const ProcessService &callback)
Constructor.
~ServiceFileReader()
Dtor.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
void setFilepath(const Pathname &filename)
set the path to the .repo file
void setName(const std::string &name)
set the repository name
void setEnabled(bool enabled)
enable or disable the repository
Regular expression match result.
String related utilities and Regular expression matching.
bool startsWith(const C_Str &str_r, const C_Str &prefix_r)
alias for hasPrefix
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
bool strToTrue(const C_Str &str)
Parsing boolean from string.
unsigned splitEscaped(const C_Str &line_r, TOutputIterator result_r, const C_Str &sepchars_r=" \t", bool withEmpty=false)
Split line_r into words with respect to escape delimeters.
Easy-to use interface to the ZYPP dependency resolver.
Service type enumeration.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.