- New class ProductInfo to provide product related metadata that
authorMichael Andres <ma@suse.de>
Thu, 31 Jul 2008 20:57:10 +0000 (20:57 +0000)
committerMichael Andres <ma@suse.de>
Thu, 31 Jul 2008 20:57:10 +0000 (20:57 +0000)
  might be associated with a package. This will replace the Product
  resolvable.

package/libzypp.changes
zypp/CMakeLists.txt
zypp/ProductInfo.cc [new file with mode: 0644]
zypp/ProductInfo.h [new file with mode: 0644]
zypp/ResObject.cc
zypp/ResObject.h

index 4d63527..4bd8a95 100644 (file)
@@ -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
index 206c9bf..32ca3d9 100644 (file)
@@ -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 (file)
index 0000000..7a1a73c
--- /dev/null
@@ -0,0 +1,192 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/ProductInfo.cc
+ *
+*/
+#include <iostream>
+#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<Url> & 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<std::string> & 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<ResObject>::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<Package>::constPtrType ProductInfo::package() const
+  {
+    return make<Package>( *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<Url> ret;
+    fillList( ret, satSolvable(), sat::SolvAttr::productRelnotesurl );
+    if ( ! ret.empty() )
+      return  ret.front();
+    return Url();
+  }
+
+  std::list<Url> ProductInfo::updateUrls() const
+  {
+    std::list<Url> ret;
+    fillList( ret, satSolvable(), sat::SolvAttr::productUpdateurls );
+    return ret;
+  }
+
+  std::list<Url> ProductInfo::extraUrls() const
+  {
+    std::list<Url> ret;
+    fillList( ret, satSolvable(), sat::SolvAttr::productExtraurls );
+    return ret;
+  }
+
+  std::list<Url> ProductInfo::optionalUrls() const
+  {
+    std::list<Url> ret;
+    fillList( ret, satSolvable(), sat::SolvAttr::productOptionalurls );
+    return ret;
+  }
+
+  std::list<std::string> ProductInfo::flags() const
+  {
+    std::list<std::string> 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 (file)
index 0000000..6b65758
--- /dev/null
@@ -0,0 +1,172 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/ProductInfo.h
+ *
+*/
+#ifndef ZYPP_PRODUCTINFO_H
+#define ZYPP_PRODUCTINFO_H
+
+#include <iosfwd>
+
+#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<ResObject>::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<Package>::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<Url> updateUrls() const;
+
+      /**
+       * Additional software for the product
+       * They are complementary, not alternatives.
+       */
+      std::list<Url> extraUrls() const;
+
+      /**
+       * Optional software for the product
+       * (for example. Non OSS repositories)
+       * They are complementary, not alternatives.
+       */
+      std::list<Url> optionalUrls() const;
+
+      /** The product flags */
+      std::list<std::string> flags() const;
+
+      /** Untranslated short name like <tt>SLES 10</tt>*/
+      std::string shortName() const;
+
+      /** Translated long name like <tt>SUSE Linux Enterprise Server 10</tt>*/
+      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
index 2e10972..0735439 100644 (file)
@@ -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
index b91df17..07bb1ae 100644 (file)
@@ -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.