39 #undef ZYPP_BASE_LOGGER_LOGGROUP
40 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::VendorAttr"
50 typedef map<Vendor,unsigned int> VendorMap;
52 unsigned int vendorGroupCounter;
61 typedef DefaultIntegral<int,0> VendorMatchEntry;
62 typedef std::tr1::unordered_map<IdString, VendorMatchEntry> VendorMatch;
64 VendorMatch _vendorMatch;
67 inline void vendorMatchIdReset()
81 inline unsigned vendorMatchId( IdString vendor )
83 VendorMatchEntry & ent( _vendorMatch[vendor] );
87 VendorMatchEntry & lcent( _vendorMatch[lcvendor] );
92 static const IdString openSUSE(
"opensuse" );
93 if ( lcvendor == openSUSE || !
str::hasPrefix( lcvendor.c_str(), openSUSE.c_str() ) )
97 for ( VendorMap::reverse_iterator it = _vendorMap.rbegin(); it != _vendorMap.rend(); ++it )
129 VendorAttr::VendorAttr ()
131 vendorGroupCounter = 1;
132 Pathname vendorPath (ZConfig::instance().vendorPath());
134 Target_Ptr trg( getZYpp()->getTarget() );
136 vendorPath = trg->root() / vendorPath;
139 addVendorDirectory (vendorPath);
145 VendorMap::const_iterator suseit( _vendorMap.find(
"suse") );
146 VendorMap::const_iterator opensuseit( _vendorMap.find(
"opensuse") );
147 if ( suseit == _vendorMap.end() )
149 if ( opensuseit == _vendorMap.end() )
152 _vendorMap[
"suse"] = _vendorMap[
"opensuse"] = ++vendorGroupCounter;
157 _vendorMap[
"suse"] = opensuseit->second;
160 else if ( opensuseit == _vendorMap.end() )
163 _vendorMap[
"opensuse"] = suseit->second;
166 MIL << *
this << endl;
169 void VendorAttr::_addVendorList(
VendorList & vendorList_r )
const
171 unsigned int nextId = vendorGroupCounter + 1;
175 for_( it, vendorList_r.begin(), vendorList_r.end() )
178 if (_vendorMap.find(*it) != _vendorMap.end())
180 if (nextId != vendorGroupCounter + 1 &&
181 nextId != _vendorMap[*it])
184 unsigned int moveID = _vendorMap[*it];
185 for_( itMap, _vendorMap.begin(), _vendorMap.end() )
187 if (itMap->second == moveID)
188 itMap->second = nextId;
193 nextId = _vendorMap[*it];
194 WAR <<
"Vendor " << *it <<
" is already used in another vendor group. --> mixing these groups" << endl;
199 for_( it, vendorList_r.begin(), vendorList_r.end() )
201 _vendorMap[*it] = nextId;
204 if (nextId == vendorGroupCounter + 1)
205 ++vendorGroupCounter;
208 vendorMatchIdReset();
211 bool VendorAttr::addVendorFile(
const Pathname & filename )
const
215 if ( PathInfo(filename).isExist())
222 MIL << filename <<
" not found." << endl;
230 string section(*sit);
236 string entry(it->first);
237 string value(it->second);
238 if ( section ==
"main" )
240 if ( entry ==
"vendors" )
243 str::split( value, back_inserter(vendorlist),
"," );
244 _addVendorList (vendorlist);
254 bool VendorAttr::addVendorDirectory(
const Pathname & dirname )
const
258 if ( PathInfo(dirname).isExist())
265 MIL << dirname <<
" not found." << endl;
269 list<Pathname> filenames;
273 for (list<Pathname>::iterator it = filenames.begin();
274 it != filenames.end(); ++it) {
275 MIL <<
"Adding file " << *it << endl;
276 addVendorFile( *it );
287 if ( lVendor == rVendor )
289 return vendorMatchId( lVendor ) == vendorMatchId( rVendor );
292 bool VendorAttr::equivalent(
const Vendor & lVendor,
const Vendor & rVendor )
const
297 {
return equivalent( lVendor.
vendor(), rVendor.
vendor() ); }
306 str <<
"Equivalent vendors:";
307 for_( it, _vendorMap.begin(), _vendorMap.end() )
309 str << endl <<
" [" << it->second <<
"] " << it->first;
A Solvable object within the sat Pool.
MapKVIteratorTraits< SectionSet >::Key_const_iterator section_const_iterator
unsigned split(const C_Str &line_r, _OutputIterator result_r, const C_Str &sepchars_r=" \t")
Split line_r into words.
std::vector< std::string > VendorList
Access to the sat-pools string space.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
void read(const InputStream &is, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Fill a dictionary from a InputStream containing a ini structured file.
std::ostream & operator<<(std::ostream &str, const ::_Dataiterator *obj)
Definition of vendor equivalence.
section_const_iterator sectionsBegin() const
entry_const_iterator entriesEnd(const std::string §ion) const
std::string toLower(const std::string &s)
Return lowercase version of s.
Parses a INI file and offers its structure as a dictionary.
int readdir(std::list< std::string > &retlist_r, const Pathname &path_r, bool dots_r)
Return content of directory via retlist.
entry_const_iterator entriesBegin(const std::string §ion) const
sat::Solvable satSolvable() const
Return the corresponding sat::Solvable.
Reference to a PoolItem connecting ResObject and ResStatus.
EntrySet::const_iterator entry_const_iterator
section_const_iterator sectionsEnd() const
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.