1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Product.cc
13 #include "zypp/base/LogTools.h"
15 #include "zypp/Product.h"
18 #include "zypp/sat/LookupAttr.h"
19 #include "zypp/sat/WhatProvides.h"
20 #include "zypp/sat/WhatObsoletes.h"
21 #include "zypp/PoolItem.h"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
29 IMPL_PTR_TYPE(Product);
33 void fillList( std::list<Url> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
35 sat::LookupAttr query( attr_r, solv_r );
36 for_( it, query.begin(), query.end() )
38 try // ignore malformed urls
40 ret_r.push_back( Url( it.asString() ) );
42 catch( const url::UrlException & )
47 void fillList( std::list<std::string> & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r )
49 sat::LookupAttr query( attr_r, solv_r );
50 for_( it, query.begin(), query.end() )
52 ret_r.push_back( it.asString() );
57 ///////////////////////////////////////////////////////////////////
59 // METHOD NAME : Product::Product
62 Product::Product( const sat::Solvable & solvable_r )
63 : ResObject( solvable_r )
66 ///////////////////////////////////////////////////////////////////
68 // METHOD NAME : Product::~Product
74 ///////////////////////////////////////////////////////////////////
76 sat::Solvable Product::referencePackage() const
78 // Look for a provider of 'product(name) = version' of same
79 // architecture and within the same repo.
80 Capability identCap( str::form( "product(%s) = %s", name().c_str(), edition().c_str() ) );
82 sat::WhatProvides providers( identCap );
83 for_( it, providers.begin(), providers.end() )
85 if ( it->repository() == repository()
86 && it->arch() == arch() )
90 WAR << *this << ": no reference package found: " << identCap << endl;
91 return sat::Solvable::noSolvable;
94 Product::ReplacedProducts Product::replacedProducts() const
96 std::vector<constPtr> ret;
97 // By now we simply collect what is obsoleted by the Product,
98 // or by the products buddy (release-package).
100 // Check our own dependencies. We should not have any,
101 // but just to be shure.
102 sat::WhatObsoletes obsoleting( satSolvable() );
103 for_( it, obsoleting.begin(), obsoleting.end() )
105 if ( it->isKind( ResKind::product ) )
106 ret.push_back( make<Product>( *it ) );
109 // If we have a buddy, we check what product buddies the
111 obsoleting = sat::WhatObsoletes( poolItem().buddy() );
112 for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
114 if ( (*it).buddy().isKind( ResKind::product ) )
115 ret.push_back( make<Product>( (*it).buddy() ) );
121 ///////////////////////////////////////////////////////////////////
123 std::string Product::shortName() const
124 { return lookupStrAttribute( sat::SolvAttr::productShortlabel ); }
126 std::string Product::flavor() const
127 { return lookupStrAttribute( sat::SolvAttr::productFlavor ); }
129 std::string Product::type() const
130 { return lookupStrAttribute( sat::SolvAttr::productType ); }
132 std::list<std::string> Product::flags() const
134 std::list<std::string> ret;
135 fillList( ret, satSolvable(), sat::SolvAttr::productFlags );
139 bool Product::isTargetDistribution() const
140 { return isSystem() && type() == "base"; }
142 std::string Product::registerTarget() const
143 { return lookupStrAttribute( sat::SolvAttr::productRegisterTarget ); }
145 std::string Product::registerRelease() const
146 { return lookupStrAttribute( sat::SolvAttr::productRegisterRelease ); }
148 /////////////////////////////////////////////////////////////////
150 Product::UrlList Product::urls( const std::string & key_r ) const
154 sat::LookupAttr url( sat::SolvAttr::productUrl, *this );
155 sat::LookupAttr url_type( sat::SolvAttr::productUrlType, *this );
157 sat::LookupAttr::iterator url_it(url.begin());
158 sat::LookupAttr::iterator url_type_it(url_type.begin());
160 for (;url_it != url.end(); ++url_it, ++url_type_it)
162 /* safety checks, shouldn't happen (tm) */
163 if (url_type_it == url_type.end())
165 /* FIXME: Raise exception ?! */
166 ERR << *this << " : The thing that should not happen, happened." << endl;
170 if ( url_type_it.asString() == key_r )
172 ret._list.push_back(url_it.asString());
174 } /* while (attribute array) */
179 Product::UrlList Product::releaseNotesUrls() const { return urls( "releasenotes" ); }
180 Product::UrlList Product::registerUrls() const { return urls( "register" ); }
181 Product::UrlList Product::smoltUrls() const { return urls( "smolt" ); }
182 Product::UrlList Product::updateUrls() const { return urls( "update" ); }
183 Product::UrlList Product::extraUrls() const { return urls( "extra" ); }
184 Product::UrlList Product::optionalUrls() const { return urls( "optional" ); }
186 std::ostream & operator<<( std::ostream & str, const Product::UrlList & obj )
187 { return dumpRange( str << obj.key() << ' ', obj.begin(), obj.end() ); }
189 /////////////////////////////////////////////////////////////////
191 ///////////////////////////////////////////////////////////////////