From: Michael Andres Date: Thu, 31 Jul 2008 20:57:10 +0000 (+0000) Subject: - New class ProductInfo to provide product related metadata that X-Git-Tag: BASE-SuSE-Code-11-Branch~543 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a480ddb11d0aa0465d37866a8e23420a112f5188;p=platform%2Fupstream%2Flibzypp.git - New class ProductInfo to provide product related metadata that might be associated with a package. This will replace the Product resolvable. --- diff --git a/package/libzypp.changes b/package/libzypp.changes index 4d63527..4bd8a95 100644 --- a/package/libzypp.changes +++ b/package/libzypp.changes @@ -1,4 +1,12 @@ ------------------------------------------------------------------- +Thu Jul 31 21:52:11 CEST 2008 ma@suse.de + +- New class ProductInfo to provide product related metadata that + might be associated with a package. This will replace the Product + resolvable. +- revision 10715 + +------------------------------------------------------------------- Thu Jul 31 19:01:54 CEST 2008 - dmacvicar@suse.de - generate a unique anonymous unique string per target diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index 206c9bf..32ca3d9 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -41,6 +41,7 @@ SET( zypp_SRCS PoolQueryResult.cc ProblemSolution.cc Product.cc + ProductInfo.cc ProgressData.cc ProvideFilePolicy.cc PublicKey.cc @@ -128,6 +129,7 @@ SET( zypp_HEADERS ProblemSolution.h ProblemTypes.h Product.h + ProductInfo.h ProgressData.h ProvideFilePolicy.h PublicKey.h diff --git a/zypp/ProductInfo.cc b/zypp/ProductInfo.cc new file mode 100644 index 0000000..7a1a73c --- /dev/null +++ b/zypp/ProductInfo.cc @@ -0,0 +1,192 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/ProductInfo.cc + * +*/ +#include +#include "zypp/base/LogTools.h" + +#include "zypp/ProductInfo.h" +#include "zypp/PoolItem.h" +#include "zypp/Package.h" + +using std::endl; + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + + namespace + { + /** Fast check whether a \ref sat::Solvable provides product metadata. + * Return the solvable or \ref sat::noSolvable. + */ + sat::Solvable ifProductInfoProvided( sat::Solvable solvable_r ) + { +#warning THIS SHOULD BE REPLACED BY A FAST TEST E.G. productName + // and use detail::IdType lookupIdAttribute for this test + + if ( solvable_r.lookupStrAttribute( sat::SolvAttr::productShortlabel ).empty() ) + return sat::Solvable::noSolvable; + return solvable_r; + } + + /** List attribute helper */ + void fillList( std::list & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r ) + { + sat::LookupAttr query( attr_r, solv_r ); + for_( it, query.begin(), query.end() ) + { + try // ignore malformed urls + { + ret_r.push_back( Url( it.asString() ) ); + } + catch( const url::UrlException & ) + {} + } + } + + /** List attribute helper */ + void fillList( std::list & ret_r, sat::Solvable solv_r, sat::SolvAttr attr_r ) + { + sat::LookupAttr query( attr_r, solv_r ); + for_( it, query.begin(), query.end() ) + { + ret_r.push_back( it.asString() ); + } + } + } + + /////////////////////////////////////////////////////////////////// + + const ProductInfo ProductInfo::noProductInfo; + + /////////////////////////////////////////////////////////////////// + // + // METHOD NAME : ProductInfo::ProductInfo + // METHOD TYPE : Ctor + // + ProductInfo::ProductInfo() + {} + + ProductInfo::ProductInfo( sat::Solvable solvable_r ) + : sat::Solvable( ifProductInfoProvided( solvable_r ) ) + {} + + ProductInfo::ProductInfo( const PoolItem & poolItem_r ) + : sat::Solvable( ifProductInfoProvided( poolItem_r.satSolvable() ) ) + {} + + ProductInfo::ProductInfo( const ResTraits::constPtrType & package_r ) + : sat::Solvable( package_r ? ifProductInfoProvided( package_r->satSolvable() ) + : sat::Solvable::noSolvable ) + {} + + /****************************************************************** + ** + ** FUNCTION NAME : operator<< + ** FUNCTION TYPE : std::ostream & + */ + std::ostream & operator<<( std::ostream & str, const ProductInfo & obj ) + { +#warning provide reasonable output + return str << obj.satSolvable(); + } + + /////////////////////////////////////////////////////////////////// + + PoolItem ProductInfo::poolItem() const + { + return PoolItem( *this ); + } + + ResTraits::constPtrType ProductInfo::package() const + { + return make( *this ); + } + + /////////////////////////////////////////////////////////////////// + +#warning DUMMIES RETURNING THE PACKAGE ATTRIBUTES + std::string ProductInfo::name() const + { return sat::Solvable::name(); } + + Edition ProductInfo::edition() const + { return sat::Solvable::edition(); } + + Arch ProductInfo::arch() const + { return sat::Solvable::arch(); } + + Vendor ProductInfo::vendor() const + { return sat::Solvable::vendor().asString(); } + + std::string ProductInfo::summary( const Locale & lang_r ) const + { return package() ? package()->summary( lang_r ) : std::string(); } + + std::string ProductInfo::description( const Locale & lang_r ) const + { return package() ? package()->description( lang_r ) : std::string(); } + + +#warning REVIEW THESE OLD PRODUCT ARTTRIBUTES + + std::string ProductInfo::type() const + { return lookupStrAttribute( sat::SolvAttr::productType ); } + + Url ProductInfo::releaseNotesUrl() const + { + std::list ret; + fillList( ret, satSolvable(), sat::SolvAttr::productRelnotesurl ); + if ( ! ret.empty() ) + return ret.front(); + return Url(); + } + + std::list ProductInfo::updateUrls() const + { + std::list ret; + fillList( ret, satSolvable(), sat::SolvAttr::productUpdateurls ); + return ret; + } + + std::list ProductInfo::extraUrls() const + { + std::list ret; + fillList( ret, satSolvable(), sat::SolvAttr::productExtraurls ); + return ret; + } + + std::list ProductInfo::optionalUrls() const + { + std::list ret; + fillList( ret, satSolvable(), sat::SolvAttr::productOptionalurls ); + return ret; + } + + std::list ProductInfo::flags() const + { + std::list ret; + fillList( ret, satSolvable(), sat::SolvAttr::productFlags ); + return ret; + } + + std::string ProductInfo::shortName() const + { return lookupStrAttribute( sat::SolvAttr::productShortlabel ); } + + std::string ProductInfo::longName( const Locale & /*lang_r*/ ) const + { return std::string(); } + + std::string ProductInfo::distributionName() const + { return lookupStrAttribute( sat::SolvAttr::productDistproduct ); } + + Edition ProductInfo::distributionEdition() const + { return Edition( lookupStrAttribute( sat::SolvAttr::productDistversion ) ); } + + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/ProductInfo.h b/zypp/ProductInfo.h new file mode 100644 index 0000000..6b65758 --- /dev/null +++ b/zypp/ProductInfo.h @@ -0,0 +1,172 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/ProductInfo.h + * +*/ +#ifndef ZYPP_PRODUCTINFO_H +#define ZYPP_PRODUCTINFO_H + +#include + +#include "zypp/sat/Solvable.h" +#include "zypp/Locale.h" +#include "zypp/Vendor.h" +#include "zypp/Repository.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp +{ ///////////////////////////////////////////////////////////////// + + class Url; + + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : ProductInfo + // + /** Product metadata. + * + * \ref ProductInfo allows to retrieve product related metadata, that + * might be associated with certain packages. This class basically + * provides the information stored in an \c /etc/products.d entry. + * + * \ref ProductInfo is provided by \ref Package. + * + * The underlying \c private \ref sat::Solvable either refers to + * an associated package providing product related metadata, or + * is \ref sat::noSolvable. + */ + class ProductInfo : private sat::Solvable + { + public: + /** Represents no \ref ProductInfo. */ + static const ProductInfo noProductInfo; + + public: + /** Default ctor creates \ref noProductInfo. */ + ProductInfo(); + + /** ProductInfo associated with a \ref sat::Solvable or \ref noProductInfo. */ + explicit ProductInfo( sat::Solvable solvable_r ); + + /** ProductInfo associated with a \ref PoolItem or \ref noProductInfo. */ + explicit ProductInfo( const PoolItem & poolItem_r ); + + /** ProductInfo associated with a \ref ResObject or \ref noProductInfo. */ + explicit ProductInfo( const ResTraits::constPtrType & package_r ); + + public: +#ifndef SWIG // Swig treats it as syntax error + /** Whether this represents a valid- or \ref noProductInfo. */ + using sat::Solvable::operator bool_type; +#endif + + public: + /** \name Access the associated \ref Package. + */ + //@{ + /** Access the associated \ref sat:::Solvable. */ + sat::Solvable satSolvable() const + { return *this; } + + /** Access the associated \ref PoolItem. */ + PoolItem poolItem() const; + + /** Access the associated \ref Package. */ + ResTraits::constPtrType package() const; + //@} + + public: + /** \name Product metadata. + */ + //@{ + /** Whether this represents an installed Product. */ + using sat::Solvable::isSystem; + + std::string name() const; + Edition edition() const; + Arch arch() const; + Vendor vendor() const; + + std::string summary( const Locale & lang_r = Locale() ) const; + std::string description( const Locale & lang_r = Locale() ) const; + + /** The \ref Repository this \ref Product belongs to. */ + using sat::Solvable::repository; + + /** \ref RepoInfo associated with the repository + * providing this product. + */ + RepoInfo repoInfo() const { return repository().info(); } + + + //---------------------------------------------- + // These are the old Product attibutes to be revieved: + + /** Get the product type (base, add-on) */ + std::string type() const; + + /** The URL to download the release notes for this product */ + Url releaseNotesUrl() const; + + /** + * Online updates for the product. + * They are complementary, not alternatives. #163192 + */ + std::list updateUrls() const; + + /** + * Additional software for the product + * They are complementary, not alternatives. + */ + std::list extraUrls() const; + + /** + * Optional software for the product + * (for example. Non OSS repositories) + * They are complementary, not alternatives. + */ + std::list optionalUrls() const; + + /** The product flags */ + std::list flags() const; + + /** Untranslated short name like SLES 10*/ + std::string shortName() const; + + /** Translated long name like SUSE Linux Enterprise Server 10*/ + std::string longName( const Locale & lang_r = Locale() ) const; + + /** Vendor specific distribution id. */ + std::string distributionName() const; + + /** Vendor specific distribution version. */ + Edition distributionEdition() const; + //@} + }; + /////////////////////////////////////////////////////////////////// + + /** \relates ProductInfo Stream output */ + std::ostream & operator<<( std::ostream & str, const ProductInfo & obj ); + + /** \relates ProductInfo */ + inline bool operator==( const ProductInfo & lhs, const ProductInfo & rhs ) + { return lhs.satSolvable() == rhs.satSolvable(); } + + /** \relates ProductInfo */ + inline bool operator!=( const ProductInfo & lhs, const ProductInfo & rhs ) + { return lhs.satSolvable() != rhs.satSolvable(); } + + /** \relates ProductInfo */ + inline bool operator<( const ProductInfo & lhs, const ProductInfo & rhs ) + { return lhs.satSolvable() < rhs.satSolvable(); } + + ///////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// +#endif // ZYPP_PRODUCTINFO_H diff --git a/zypp/ResObject.cc b/zypp/ResObject.cc index 2e10972..0735439 100644 --- a/zypp/ResObject.cc +++ b/zypp/ResObject.cc @@ -16,6 +16,7 @@ #include "zypp/sat/Solvable.h" #include "zypp/Repository.h" #include "zypp/RepoInfo.h" +#include "zypp/ProductInfo.h" #include "zypp/IdString.h" using namespace zypp; @@ -55,9 +56,13 @@ namespace zypp } /////////////////////////////////////////////////////////////////// - // - // ResObject interface forwarded to implementation - // + + bool ResObject::hasProductInfo() const + { return ProductInfo( *this ); } // this is basically one lookupIdAttribute call + + ProductInfo ResObject::productInfo() const + { return ProductInfo( *this ); } + /////////////////////////////////////////////////////////////////// std::string ResObject::summary( const Locale & lang_r ) const diff --git a/zypp/ResObject.h b/zypp/ResObject.h index b91df17..07bb1ae 100644 --- a/zypp/ResObject.h +++ b/zypp/ResObject.h @@ -30,6 +30,8 @@ namespace zypp { ///////////////////////////////////////////////////////////////// + class ProductInfo; + /////////////////////////////////////////////////////////////////// // // CLASS NAME : ResObject @@ -65,6 +67,18 @@ namespace zypp //@} public: + /** \name Associated product metadata. + * Some \ref Packages may provide additional product metadata. + * \see \ref ProductInfo. + */ + //@{ + /** Whether there is associated \ref ProductInfo available. */ + bool hasProductInfo() const; + /** Return associated \ref ProductInfo or \ref ProductInfo::noProductInfo. */ + ProductInfo productInfo() const; + //@} + + public: /** * \short Short text describing the resolvable.