15#include <zypp/base/Gettext.h>
16#include <zypp/base/LogTools.h>
18#include <zypp/base/String.h>
28#undef ZYPP_BASE_LOGGER_LOGGROUP
29#define ZYPP_BASE_LOGGER_LOGGROUP "PoolQuery"
68 struct EditionRangePredicate
70 EditionRangePredicate(
const Rel & op,
const Edition & edition )
74 EditionRangePredicate(
const Rel & op,
const Edition & edition,
const Arch & arch )
85 if ( !
cap.isSimple() )
92 std::string serialize()
const
94 std::string
ret(
"EditionRange" );
106 struct SolvableRangePredicate
108 SolvableRangePredicate(
const Rel & op,
const Edition & edition )
113 SolvableRangePredicate(
const Rel & op,
const Edition & edition,
const Arch & arch )
120 if ( !
_arch.empty() &&
iter_r.inSolvable().arch() != _arch )
125 std::string serialize()
const
127 std::string
ret(
"SolvableRange" );
142 struct CapabilityMatchPredicate
153 std::string serialize()
const
155 std::string
ret(
"CapabilityMatch" );
223 template<
class TPredicate>
235 std::string serialize()
const
237 std::string
ret(
"AttrMatchData" );
250 std::vector<std::string>
words;
252 if (
words.empty() ||
words[0] !=
"AttrMatchData" )
254 if (
words.size() != 5 )
261 ret.strMatcher.setFlags( mode );
267 if ( !
words.empty() )
269 if (
words[0] ==
"EditionRange" )
271 switch(
words.size() )
284 else if (
words[0] ==
"SolvableRange" )
286 switch(
words.size() )
299 else if (
words[0] ==
"CapabilityMatch" )
301 if (
words.size() != 2 )
326#define OUTS(M,S) case Match::M: return #S; break
331 OUTS( STRINGSTART,
S );
332 OUTS( STRINGEND,
E );
333 OUTS( SUBSTRING, B );
349#define OUTS(M,C) case *#C: return Match::M; break
354 OUTS( STRINGSTART,
S );
355 OUTS( STRINGEND,
E );
356 OUTS( SUBSTRING, B );
369 inline std::ostream &
operator<<( std::ostream &
str,
const AttrMatchData &
obj )
371 str <<
obj.attr <<
": " <<
obj.strMatcher;
372 if (
obj.kindPredicate )
373 str <<
" +(" <<
obj.kindPredicate <<
")";
375 str <<
" +(" <<
obj.predicateStr <<
")";
380 inline bool operator==(
const AttrMatchData & lhs,
const AttrMatchData & rhs )
382 return ( lhs.attr == rhs.attr
383 && lhs.strMatcher == rhs.strMatcher
384 && lhs.predicateStr == rhs.predicateStr );
388 inline bool operator!=(
const AttrMatchData & lhs,
const AttrMatchData & rhs )
389 {
return !( lhs == rhs ); }
392 inline bool operator<(
const AttrMatchData & lhs,
const AttrMatchData & rhs )
394 if ( lhs.attr != rhs.attr )
395 return ( lhs.attr < rhs.attr );
396 if ( lhs.strMatcher != rhs.strMatcher )
397 return ( lhs.strMatcher < rhs.strMatcher );
398 if ( lhs.predicateStr != rhs.predicateStr )
399 return ( lhs.predicateStr < rhs.predicateStr );
403 typedef std::list<AttrMatchData> AttrMatchList;
466#define OUTS(A) if ( A != rhs.A ) return A < rhs.A;
532 {
return new Impl( *
this ); }
584 else if (
_attrs.size() == 1)
600 if (
ai->second.empty() )
602 for_(
it,
ai->second.begin(),
ai->second.end() )
616 AttrRawStrMap::const_iterator
ai =
_attrs.begin();
624 ai->second.begin(),
ai->second.end(),
686 const std::string &
mstr(
it->strMatcher.searchstring() );
687 if ( !
mstr.empty() )
712 it->strMatcher.compile();
754 else if ( _match_word )
769 else if ( _match_word )
777 std::ostringstream
o;
780 if ( _kinds.empty() )
784 for(Kinds::const_iterator
it = _kinds.begin();
785 it != _kinds.end(); ++
it)
791 if ( _repos.empty() )
795 for(StrContainer::const_iterator
it = _repos.begin();
796 it != _repos.end(); ++
it)
801 o <<
"version: "<< _op <<
" " << _edition.asString() << endl;
802 o <<
"status: " << ( _status_flags ? ( _status_flags ==
INSTALLED_ONLY ?
"INSTALLED_ONLY" :
"UNINSTALLED_ONLY" )
805 o <<
"string match flags: " <<
Match(_flags) << endl;
809 for(StrContainer::const_iterator
it = _strings.begin();
810 it != _strings.end(); ++
it)
814 o <<
"attributes: " << endl;
815 for(AttrRawStrMap::const_iterator
ai = _attrs.begin();
ai != _attrs.end(); ++
ai)
817 o <<
"* " <<
ai->first <<
": ";
818 for(StrContainer::const_iterator
vi =
ai->second.begin();
819 vi !=
ai->second.end(); ++
vi)
824 o <<
"predicated: " << endl;
825 for_(
it, _uncompiledPredicated.begin(), _uncompiledPredicated.end() )
827 o <<
"* " << *
it << endl;
831 o <<
"last attribute matcher compiled: " << endl;
832 if ( _attrMatchList.empty() )
834 o <<
"not yet compiled" << endl;
838 for_(
it, _attrMatchList.begin(), _attrMatchList.end() )
840 o <<
"* " << *
it << endl;
865 WAR <<
"ignoring an empty repository alias" << endl;
872 {
_pimpl->_kinds.insert(kind); }
882 {
_pimpl->_strings.insert(value); }
942 if ( !
cap.isSimple() )
969 {
return _pimpl->_flags; }
984 {
return _pimpl->_strings; }
988 {
return _pimpl->_attrs; }
994 AttrRawStrMap::const_iterator
it =
_pimpl->_attrs.find(
attr);
999 {
return _pimpl->_edition; }
1006 {
return _pimpl->_kinds; }
1010 {
return _pimpl->_repos; }
1014 {
return _pimpl->_comment; }
1033 {
return _pimpl->_status_flags; }
1161 if ((!
s.empty()) &&
s[0]==
'#')
1166 std::string::size_type
pos =
s.find(
':');
1167 if (
s.empty() ||
pos ==
s.npos)
1234 WAR <<
"forget recover some attribute defined as String type attribute: " <<
attrValue << endl;
1273 WAR <<
"Unknown value for install status " <<
attrValue << endl;
1278 std::string::size_type
pos;
1280 if (
attrValue.find_first_of(
"=<>!") == 0)
1293 _pimpl->_uncompiledPredicated.insert( AttrMatchData::deserialize(
attrValue ) );
1303 WAR <<
"empty attribute name" << endl;
1314 if (
d.isVersioned() )
1343 const AttrMatchData &
attrmatch { *
_pimpl->_uncompiledPredicated.begin() };
1349 std::vector<std::string>
words;
1373 std::vector<std::string>
words;
1375 if ( !
words.empty() )
1377 if (
words[0] ==
"EditionRange" ||
words[0] ==
"SolvableRange" )
1384 _pimpl->_uncompiledPredicated.clear();
1422 <<
": substring" <<
delim;
1437 str <<
"case_sensitive: ";
1453 str <<
"install_status: all" <<
delim;
1456 str <<
"install_status: installed" <<
delim;
1459 str <<
"install_status: not-installed" <<
delim;
1471 std::string
s =
it->first.asString();
1479 for_(
it,
_pimpl->_uncompiledPredicated.begin(),
_pimpl->_uncompiledPredicated.end() )
1481 str <<
"complex: "<<
it->serialize() <<
delim;
1484 if (
const std::string &
c {
comment() };
not c.empty() )
1492 {
return _pimpl->asString(); }
1495 {
return str <<
obj.asString(); }
1548 base_r.nextSkipSolvable();
1582 for ( ++base; base.
inSolvable() == inSolvable; ++base )
1660 if (
_repos.size() == 1 )
1714 base_r.nextSkipSolvable();
1736 base_r.nextSkipSolvable();
1782 base_r.nextSkipSolvable();
1802 void PoolQueryIterator::increment()
1835 if ( !
obj.matchesEmpty() )
1839 str << endl <<
" " <<
it->inSolvAttr() <<
"\t" <<
it->asString();
Edition::MatchRange _range
bool empty() const
Test for an empty Arch (this is Arch_epmty, not Arch_noarch ).
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
void reset()
Reset to default Ctor values.
Helper providing more detailed information about a Capability.
static const CapMatch yes
Edition represents [epoch:]version[-release]
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Base class for Exception.
std::string asUserHistory() const
A single (multiline) string composed of asUserString and historyAsString.
Base class for creating IdString based types.
Access to the sat-pools string space.
String matching option flags as used e.g.
int get() const
Return the integer representation.
Mode
Mode flags (mutual exclusive).
@ REGEX
Regular Expression.
@ SUBSTRING
Match substring.
bool isModeString() const
Whether this has mode STRING.
static const Match FILES
LookupAttr: match full path when matching in filelists, otherwise just the basenames.
static const Match NOCASE
If set, match case insensitive.
bool isModeGlob() const
Whether this has mode GLOB.
Mode mode() const
Return the mode part.
Edition _edition
Edition condition operand.
Kinds _kinds
Kinds to search.
StrContainer _repos
Repos to search.
StatusFilter _status_flags
Sat solver status flags.
Rel _op
Operator for edition condition.
Match _flags
Sat solver search flags.
std::string _comment
Optional comment string for serialization.
void compile() const
Compile the regex.
bool operator<(const PoolQuery::Impl &rhs) const
bool operator!=(const PoolQuery::Impl &rhs) const
StrContainer _strings
Raw search strings.
std::set< AttrMatchData > _uncompiledPredicated
Uncompiled attributes with predicate.
StrMatcher joinedStrMatcher(const StrContainer &container_r, const Match &flags_r) const
Join patterns in container_r according to flags_r into a single StrMatcher.
AttrRawStrMap _attrs
Raw attributes.
AttrMatchList _attrMatchList
StrMatcher per attribtue.
bool operator==(const PoolQuery::Impl &rhs) const
Impl * clone() const
clone for RWCOW_pointer
std::string asString() const
String representation.
Match flags() const
Free function to get libsolv repo search flags.
void addString(const std::string &value)
Add a global query string.
const Rel editionRel() const
std::set< std::string > StrContainer
bool matchSubstring() const
const StrContainer & repos() const
void setMatchExact()
Set to match exact string instead of substring.
void setMatchWord()
Set substring to match words.
void setMatchRegex()
Set to use the query strings as regexes.
const Edition edition() const
void setFlags(const Match &flags)
Free function to set libsolv repo search flags.
RW_pointer< Impl > _pimpl
Pointer to implementation.
void setCaseSensitive(bool value=true)
Turn case sentitivity on or off (unsets or sets SEARCH_NOCASE flag).
void setComment(const std::string &comment) const
Set an optional comment string describing the purpose of the query.
void execute(ProcessResolvable fnc)
Executes the query with the current settings.
std::string asString() const
Return a human-readable description of the query.
void setStatusFilterFlags(StatusFilter flags)
Set status filter directly.
bool empty() const
Whether the result is empty.
void addKind(const ResKind &kind)
Filter by selectable kind.
bool operator==(const PoolQuery &b) const
void setRequireAll(bool require_all=true) ZYPP_DEPRECATED
void addAttribute(const sat::SolvAttr &attr, const std::string &value="")
Filter by the value of the specified attr attribute.
bool requireAll() const ZYPP_DEPRECATED
const std::string & comment() const
bool filesMatchFullPath() const
Whether searching in filelists looks at the full path or just at the basenames.
void addRepo(const std::string &repoalias)
Filter by repo.
const Kinds & kinds() const
Match::Mode matchMode() const
Returns string matching mode as enum.
void setInstalledOnly()
Return only @System repo packages.
const_iterator end() const
An iterator pointing to the end of the query result.
StatusFilter statusFilterFlags() const
const StrContainer & strings() const
Search strings added via addString()
std::set< ResKind > Kinds
size_type size() const
Number of solvables in the query result.
const_iterator begin() const
Query result accessers.
bool recover(std::istream &str, char delim='\n')
Reads from stream query.
void serialize(std::ostream &str, char delim='\n') const
Writes a machine-readable string representation of the query to stream.
std::map< sat::SolvAttr, StrContainer > AttrRawStrMap
const AttrRawStrMap & attributes() const
Map (map<SolvAttr, StrContainer>) of attribute values added via addAttribute(), addDep in string form...
void addDependency(const sat::SolvAttr &attr, const std::string &name, const Rel &op, const Edition &edition)
Query "name|global op edition".
StatusFilter
Installed status filter setters.
void setEdition(const Edition &edition, const Rel &op=Rel::EQ)
Set version condition.
const StrContainer & attribute(const sat::SolvAttr &attr) const
void setMatchSubstring()
Set to substring (the default).
void setFilesMatchFullPath(bool value=true)
If set (default), look at the full path when searching in filelists.
void setUninstalledOnly()
Return only packages from repos other than @System.
void setMatchGlob()
Set to match globs.
bool operator<(const PoolQuery &b) const
bool caseSensitive() const
returns true if search is case sensitive
bool isSystemRepo() const
Return whether this is the system repository.
static ResKind explicitBuiltin(const char *str_r)
Return the builtin kind if str_r explicitly prefixed.
static const ResKind nokind
Value representing nokind ("")
String matching (STRING|SUBSTRING|GLOB|REGEX).
static const StringTypeAttr substringAttr
static const StringTypeAttr wordAttr
StringTypeAttr(const char *cstr_r)
StringTypeAttr(const std::string &str_r)
static const StringTypeAttr noAttr
static const StringTypeAttr globAttr
static const StringTypeAttr exactAttr
static const StringTypeAttr regexAttr
PoolQuery iterator as returned by PoolQuery::begin.
shared_ptr< Matches > _matches
shared_ptr< PoolQueryMatcher > _matcher
std::vector< sat::LookupAttr::iterator > Matches
Store PoolQuery settings and assist PoolQueryIterator.
sat::LookupAttr::iterator base_iterator
std::set< Repository > _repos
Repositories include in the search.
bool isAMatch(base_iterator &base_r) const
Check whether we are on a match.
bool advance(base_iterator &base_r) const
PoolQueryMatcher(const shared_ptr< const PoolQuery::Impl > &query_r)
Ctor stores the PoolQuery settings.
std::set< ResKind > _kinds
Resolvable kinds to include.
AttrMatchList _attrMatchList
StrMatcher per attribtue.
const base_iterator & end() const
DefaultIntegral< bool, false > _neverMatchRepo
void matchDetail(const base_iterator &base_r, std::vector< base_iterator > &return_r) const
Provide all matching attributes within this solvable.
base_iterator startNewQyery() const
Initialize a new base query.
int _status_flags
Installed status filter flags.
void stayInThisSolvable()
Stop after all matches in the current Solvable are processed.
Solvable inSolvable() const
The current Solvable.
Lightweight attribute value lookup.
Repository reposFind(const std::string &alias_r) const
Find a Repository named alias_r.
static Pool instance()
Singleton ctor.
static const SolvAttr supplements
static const SolvAttr obsoletes
static const SolvAttr name
static const SolvAttr suggests
static const SolvAttr conflicts
static const SolvAttr recommends
static const SolvAttr allAttr
Value to request searching all Attributes (0).
static const SolvAttr enhances
static const SolvAttr provides
A Solvable object within the sat Pool.
ResKind kind() const
The Solvables ResKind.
Edition edition() const
The edition (version-release).
bool isKind(const ResKind &kind_r) const
Test whether a Solvable is of a certain ResKind.
bool compareByRel(Rel op, const Tp &lhs, const Tp &rhs, TCompare compare)
Comparison of two elements using relational operator op.
String related utilities and Regular expression matching.
std::string & replaceAll(std::string &str_r, const std::string &from_r, const std::string &to_r)
Replace all occurrences of from_r with to_r in str_r (inplace).
bool strToFalse(const C_Str &str)
Return false if str is 0, false, no, off, never.
void appendEscaped(std::string &str_r, const C_Str &next_r, const char sep_r=' ')
Escape next_r and append it to str_r using separator sep_r.
std::string rxEscapeStr(std::string str_r)
Escape plain STRING str_r for use in a regex (not anchored by "^" or "$").
std::string rxEscapeGlob(std::string str_r)
Escape GLOB str_r for use in a regex (not anchored by "^" or "$").
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.
std::string trim(const std::string &s, const Trim trim_r)
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & dumpOn(std::ostream &str, const Capability &obj)
bool overlaps(const Range< Tp, TCompare > &lhs, const Range< Tp, TCompare > &rhs)
const Arch Arch_empty(IdString::Empty)
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool deserialize(const std::string &str_r, DownloadMode &result_r)
int invokeOnEach(TIterator begin_r, TIterator end_r, TFilter filter_r, TFunction fnc_r)
Iterate through [begin_r,end_r) and invoke fnc_r on each item that passes filter_r.
bool operator()(const std::string &str)
PoolQuery::StrContainer & _cont
bool operator()(const std::string &str)
MyInserter(PoolQuery::StrContainer &cont)
represents all atributes in PoolQuery except SolvAtributes, which are used as is (not needed extend a...
PoolQueryAttr(const std::string &str_r)
static const PoolQueryAttr stringAttr
static const PoolQueryAttr kindAttr
static const PoolQueryAttr editionAttr
static const PoolQueryAttr installStatusAttr
static const PoolQueryAttr commentAttr
static const PoolQueryAttr repoAttr
static const PoolQueryAttr requireAllAttr
PoolQueryAttr(const char *cstr_r)
static const PoolQueryAttr caseSensitiveAttr
static const PoolQueryAttr noAttr
static const PoolQueryAttr complexAttr
static const PoolQueryAttr stringTypeAttr
for_use_in_switch inSwitch() const
Enumarator provided for use in switch statement.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
#define arrayBegin(A)
Simple C-array iterator.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.