39 #undef ZYPP_BASE_LOGGER_LOGGROUP
40 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::VendorAttr"
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] );
93 for ( VendorMap::reverse_iterator it = _vendorMap.rbegin(); it != _vendorMap.rend(); ++it )
124 VendorAttr::VendorAttr ()
126 vendorGroupCounter = 1;
127 Pathname vendorPath (ZConfig::instance().vendorPath());
130 Target_Ptr trg( getZYpp()->target() );
132 vendorPath = trg->root() / vendorPath;
140 addVendorDirectory (vendorPath);
146 VendorMap::const_iterator suseit( _vendorMap.find(
"suse") );
147 VendorMap::const_iterator opensuseit( _vendorMap.find(
"opensuse") );
148 if ( suseit == _vendorMap.end() )
150 if ( opensuseit == _vendorMap.end() )
153 _vendorMap[
"suse"] = _vendorMap[
"opensuse"] = ++vendorGroupCounter;
158 _vendorMap[
"suse"] = opensuseit->second;
161 else if ( opensuseit == _vendorMap.end() )
164 _vendorMap[
"opensuse"] = suseit->second;
168 VendorMap::const_iterator obsit( _vendorMap.find(
"opensuse build service") );
169 if ( obsit == _vendorMap.end() )
171 _vendorMap[
"opensuse build service"] = ++vendorGroupCounter;
175 MIL << *
this << endl;
178 void VendorAttr::_addVendorList(
VendorList & vendorList_r )
const
180 unsigned int nextId = vendorGroupCounter + 1;
184 for_( it, vendorList_r.begin(), vendorList_r.end() )
187 if (_vendorMap.find(*it) != _vendorMap.end())
189 if (nextId != vendorGroupCounter + 1 &&
190 nextId != _vendorMap[*it])
193 unsigned int moveID = _vendorMap[*it];
194 for_( itMap, _vendorMap.begin(), _vendorMap.end() )
196 if (itMap->second == moveID)
197 itMap->second = nextId;
202 nextId = _vendorMap[*it];
203 WAR <<
"Vendor " << *it <<
" is already used in another vendor group. --> mixing these groups" << endl;
208 for_( it, vendorList_r.begin(), vendorList_r.end() )
210 _vendorMap[*it] = nextId;
213 if (nextId == vendorGroupCounter + 1)
214 ++vendorGroupCounter;
217 vendorMatchIdReset();
220 bool VendorAttr::addVendorFile(
const Pathname & filename )
const
224 if ( PathInfo(filename).isExist())
231 MIL << filename <<
" not found." << endl;
239 string section(*sit);
245 string entry(it->first);
246 string value(it->second);
247 if ( section ==
"main" )
249 if ( entry ==
"vendors" )
252 str::split( value, back_inserter(vendorlist),
"," );
253 _addVendorList (vendorlist);
263 bool VendorAttr::addVendorDirectory(
const Pathname & dirname )
const
267 if ( PathInfo(dirname).isExist())
274 MIL << dirname <<
" not found." << endl;
278 list<Pathname> filenames;
282 for (list<Pathname>::iterator it = filenames.begin();
283 it != filenames.end(); ++it) {
284 MIL <<
"Adding file " << *it << endl;
285 addVendorFile( *it );
296 if ( lVendor == rVendor )
298 return vendorMatchId( lVendor ) == vendorMatchId( rVendor );
301 bool VendorAttr::equivalent(
const Vendor & lVendor,
const Vendor & rVendor )
const
306 {
return equivalent( lVendor.
vendor(), rVendor.
vendor() ); }
315 str <<
"Equivalent vendors:";
316 for_( it, _vendorMap.begin(), _vendorMap.end() )
318 str << endl <<
" [" << it->second <<
"] " << it->first;