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] );
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());
135 Target_Ptr trg( getZYpp()->target() );
137 vendorPath = trg->root() / vendorPath;
145 addVendorDirectory (vendorPath);
151 VendorMap::const_iterator suseit( _vendorMap.find(
"suse") );
152 VendorMap::const_iterator opensuseit( _vendorMap.find(
"opensuse") );
153 if ( suseit == _vendorMap.end() )
155 if ( opensuseit == _vendorMap.end() )
158 _vendorMap[
"suse"] = _vendorMap[
"opensuse"] = ++vendorGroupCounter;
163 _vendorMap[
"suse"] = opensuseit->second;
166 else if ( opensuseit == _vendorMap.end() )
169 _vendorMap[
"opensuse"] = suseit->second;
172 MIL << *
this << endl;
175 void VendorAttr::_addVendorList(
VendorList & vendorList_r )
const
177 unsigned int nextId = vendorGroupCounter + 1;
181 for_( it, vendorList_r.begin(), vendorList_r.end() )
184 if (_vendorMap.find(*it) != _vendorMap.end())
186 if (nextId != vendorGroupCounter + 1 &&
187 nextId != _vendorMap[*it])
190 unsigned int moveID = _vendorMap[*it];
191 for_( itMap, _vendorMap.begin(), _vendorMap.end() )
193 if (itMap->second == moveID)
194 itMap->second = nextId;
199 nextId = _vendorMap[*it];
200 WAR <<
"Vendor " << *it <<
" is already used in another vendor group. --> mixing these groups" << endl;
205 for_( it, vendorList_r.begin(), vendorList_r.end() )
207 _vendorMap[*it] = nextId;
210 if (nextId == vendorGroupCounter + 1)
211 ++vendorGroupCounter;
214 vendorMatchIdReset();
217 bool VendorAttr::addVendorFile(
const Pathname & filename )
const
221 if ( PathInfo(filename).isExist())
228 MIL << filename <<
" not found." << endl;
236 string section(*sit);
242 string entry(it->first);
243 string value(it->second);
244 if ( section ==
"main" )
246 if ( entry ==
"vendors" )
249 str::split( value, back_inserter(vendorlist),
"," );
250 _addVendorList (vendorlist);
260 bool VendorAttr::addVendorDirectory(
const Pathname & dirname )
const
264 if ( PathInfo(dirname).isExist())
271 MIL << dirname <<
" not found." << endl;
275 list<Pathname> filenames;
279 for (list<Pathname>::iterator it = filenames.begin();
280 it != filenames.end(); ++it) {
281 MIL <<
"Adding file " << *it << endl;
282 addVendorFile( *it );
293 if ( lVendor == rVendor )
295 return vendorMatchId( lVendor ) == vendorMatchId( rVendor );
298 bool VendorAttr::equivalent(
const Vendor & lVendor,
const Vendor & rVendor )
const
303 {
return equivalent( lVendor.
vendor(), rVendor.
vendor() ); }
312 str <<
"Equivalent vendors:";
313 for_( it, _vendorMap.begin(), _vendorMap.end() )
315 str << endl <<
" [" << it->second <<
"] " << it->first;