add PackagesLangParser for packages.en (for now)
authorKlaus Kaempf <kkaempf@suse.de>
Wed, 8 Feb 2006 21:50:57 +0000 (21:50 +0000)
committerKlaus Kaempf <kkaempf@suse.de>
Wed, 8 Feb 2006 21:50:57 +0000 (21:50 +0000)
zypp/source/susetags/Makefile.am
zypp/source/susetags/PackagesLangParser.cc [new file with mode: 0644]
zypp/source/susetags/PackagesLangParser.h [new file with mode: 0644]
zypp/source/susetags/PackagesParser.cc
zypp/source/susetags/PackagesParser.h
zypp/source/susetags/SuseTagsImpl.cc
zypp/source/susetags/SuseTagsPackageImpl.cc
zypp/source/susetags/SuseTagsPackageImpl.h

index 6fe5fe4..a114760 100644 (file)
@@ -9,6 +9,7 @@ sourceincludedir = $(pkgincludedir)/source
 
 sourceinclude_HEADERS =        \
        PackagesParser.h\
+       PackagesLangParser.h\
        SuseTagsImpl.h \
        SuseTagsSelectionImpl.h \
        SuseTagsPatternImpl.h \
@@ -25,6 +26,7 @@ noinst_LTLIBRARIES =  lib@PACKAGE@_source_susetags.la
 
 lib@PACKAGE@_source_susetags_la_SOURCES = \
        PackagesParser.cc       \
+       PackagesLangParser.cc   \
        SuseTagsImpl.cc \
        SuseTagsSelectionImpl.cc \
        SuseTagsPatternImpl.cc \
diff --git a/zypp/source/susetags/PackagesLangParser.cc b/zypp/source/susetags/PackagesLangParser.cc
new file mode 100644 (file)
index 0000000..55f912c
--- /dev/null
@@ -0,0 +1,104 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/source/susetags/PackagesLangParser.cc
+ *
+*/
+#include <iostream>
+#include "zypp/base/Logger.h"
+
+#include "zypp/source/susetags/PackagesLangParser.h"
+#include "zypp/parser/tagfile/TagFileParser.h"
+#include "zypp/Package.h"
+#include "zypp/source/susetags/SuseTagsPackageImpl.h"
+
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace source
+  { /////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////
+    namespace susetags
+    { /////////////////////////////////////////////////////////////////
+
+      using namespace parser::tagfile;
+
+      struct PackagesLangParser : public parser::tagfile::TagFileParser
+      {
+        const PkgContent & _content;
+       const Locale & _lang;
+       PkgImplPtr _current;
+
+       PackagesLangParser (const PkgContent & content_r, const Locale & lang_r)
+           : _content( content_r )
+           , _lang( lang_r)
+        { }
+
+        /* Consume SingleTag data. */
+        virtual void consume( const SingleTag & stag_r )
+        {
+          if ( stag_r.name == "Pkg" )
+          {
+            std::vector<std::string> words;
+            str::split( stag_r.value, std::back_inserter(words) );
+
+            if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
+              ZYPP_THROW( ParseException( "Pkg" ) );
+
+            NVRAD nvrad ( words[0], Edition(words[1],words[2]), Arch(words[3]) );
+           PkgContent::const_iterator it = _content.find(nvrad);
+           if (it == _content.end()) {
+               WAR << words[0] << " " << words[1] << " " << words[2] << "  " << Arch(words[3]) << " not found" << endl;
+               _current.reset();
+           }
+           else {
+               _current = it->second;
+           }
+
+          }
+         else if ( stag_r.name == "Sum" )
+          {
+           if (_current != NULL) {
+             _current->_summary = TranslatedText( stag_r.value, _lang);
+           }
+          }
+        }
+
+        /* Consume MulitTag data. */
+        virtual void consume( const MultiTag & mtag_r )
+        {
+          if ( mtag_r.name == "Des" )
+            {
+              if ( _current != NULL )
+                 _current->_description = TranslatedText (mtag_r.values, _lang);
+            }
+        }
+      };
+
+      ////////////////////////////////////////////////////////////////////////////
+
+      void parsePackagesLang( const Pathname & file_r, const Locale & lang_r, const PkgContent & content_r )
+      {
+        PackagesLangParser p (content_r, lang_r);
+        p.parse( file_r );
+        return;
+      }
+
+      /////////////////////////////////////////////////////////////////
+    } // namespace susetags
+    ///////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////
+  } // namespace source
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/source/susetags/PackagesLangParser.h b/zypp/source/susetags/PackagesLangParser.h
new file mode 100644 (file)
index 0000000..1ba0d8d
--- /dev/null
@@ -0,0 +1,47 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/source/susetags/PackagesLangParser.h
+ *
+*/
+#ifndef ZYPP_SOURCE_SUSETAGS_PACKAGESLANGPARSER_H
+#define ZYPP_SOURCE_SUSETAGS_PACKAGESLANGPARSER_H
+
+#include <iosfwd>
+#include <list>
+
+#include "zypp/Pathname.h"
+#include "zypp/Package.h"
+#include "zypp/source/susetags/PackagesParser.h"
+#include "zypp/source/susetags/SuseTagsImpl.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace source
+  { /////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////
+    namespace susetags
+    { /////////////////////////////////////////////////////////////////
+
+      /** \deprecated Just temporary.
+       * \throws ParseException and others.
+      */
+      void parsePackagesLang( const Pathname & file_r, const Locale & lang_r, const PkgContent & content_r );
+
+      /////////////////////////////////////////////////////////////////
+    } // namespace susetags
+    ///////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////
+  } // namespace source
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SOURCE_SUSETAGS_PACKAGESLANGPARSER_H
index 0891653..09da042 100644 (file)
@@ -15,7 +15,6 @@
 #include "zypp/source/susetags/PackagesParser.h"
 #include "zypp/parser/tagfile/TagFileParser.h"
 #include "zypp/Package.h"
-#include "zypp/source/susetags/SuseTagsPackageImpl.h"
 #include "zypp/CapFactory.h"
 #include "zypp/CapSet.h"
 
@@ -36,12 +35,12 @@ namespace zypp
 
       struct PackagesParser : public parser::tagfile::TagFileParser
       {
-        std::list<Package::Ptr> result;
+        PkgContent result;
 
        Source_Ref _source;
        SuseTagsImpl::Ptr _sourceImpl;
 
-        shared_ptr<source::susetags::SuseTagsPackageImpl> pkgImpl;
+        PkgImplPtr pkgImpl;
         NVRAD nvrad;
 
         bool pkgPending() const
@@ -52,7 +51,7 @@ namespace zypp
         {
           if ( pkgPending() )
             {
-              result.push_back( detail::makeResolvableFromImpl( nvrad, pkgImpl ) );
+              result[nvrad] = pkgImpl;
             }
           pkgImpl = nextPkg_r;
         }
@@ -167,7 +166,7 @@ namespace zypp
 
       ////////////////////////////////////////////////////////////////////////////
 
-      std::list<Package::Ptr> parsePackages( Source_Ref source_r, SuseTagsImpl::Ptr sourceImpl_r, const Pathname & file_r )
+      PkgContent parsePackages( Source_Ref source_r, SuseTagsImpl::Ptr sourceImpl_r, const Pathname & file_r )
       {
         PackagesParser p;
        p._source = source_r;
index 7bb002e..c384319 100644 (file)
 #include <iosfwd>
 #include <list>
 
+#include "zypp/base/PtrTypes.h"
 #include "zypp/Pathname.h"
 #include "zypp/Package.h"
+#include "zypp/NVRAD.h"
 #include "zypp/source/susetags/SuseTagsImpl.h"
+#include "zypp/source/susetags/SuseTagsPackageImpl.h"
+
+typedef zypp::shared_ptr<zypp::source::susetags::SuseTagsPackageImpl> PkgImplPtr;
+typedef std::map<zypp::NVRAD, PkgImplPtr> PkgContent;
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -32,7 +38,7 @@ namespace zypp
       /** \deprecated Just temporary.
        * \throws ParseException and others.
       */
-      std::list<Package::Ptr> parsePackages( Source_Ref source_r, SuseTagsImpl::Ptr, const Pathname & file_r );
+      PkgContent parsePackages( Source_Ref source_r, SuseTagsImpl::Ptr, const Pathname & file_r );
 
       /////////////////////////////////////////////////////////////////
     } // namespace susetags
index 7d2e915..297481b 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "zypp/source/susetags/SuseTagsImpl.h"
 #include "zypp/source/susetags/PackagesParser.h"
+#include "zypp/source/susetags/PackagesLangParser.h"
 #include "zypp/source/susetags/SelectionTagFileParser.h"
 #include "zypp/source/susetags/PatternTagFileParser.h"
 
@@ -105,8 +106,17 @@ namespace zypp
 #warning We use suse instead of <DATADIR> for now
         Pathname p = provideFile(_path + "suse/setup/descr/packages");
         DBG << "Going to parse " << p << endl;
-        std::list<Package::Ptr> content( parsePackages( source_r, this, p ) );
-        _store.insert( content.begin(), content.end() );
+        PkgContent content( parsePackages( source_r, this, p ) );
+#warning Should use correct locale
+       Locale lang;
+        p = provideFile(_path + "suse/setup/descr/packages.en");
+        DBG << "Going to parse " << p << endl;
+       parsePackagesLang( p, lang, content );
+
+       for (PkgContent::const_iterator it = content.begin(); it != content.end(); ++it) {
+           Package::Ptr pkg = detail::makeResolvableFromImpl( it->first, it->second );
+           _store.insert( pkg );
+       }
         DBG << "SuseTagsImpl (fake) from " << p << ": "
             << content.size() << " packages" << endl;
 
index 98a3ef7..6058ce4 100644 (file)
@@ -39,6 +39,13 @@ namespace zypp
       SuseTagsPackageImpl::~SuseTagsPackageImpl()
       {}
 
+
+      TranslatedText SuseTagsPackageImpl::summary() const
+      { return _summary; }
+
+      TranslatedText SuseTagsPackageImpl::description() const
+      { return _description; }
+
       Date SuseTagsPackageImpl::buildtime() const
       { return Date(); }
 
index a2679b9..900a563 100644 (file)
@@ -37,6 +37,9 @@ namespace zypp
 
         /** \name Rpm Package Attributes. */
         //@{
+       virtual TranslatedText summary() const;
+       virtual TranslatedText description() const;
+
         /** */
         virtual Date buildtime() const;
         /** */
@@ -87,6 +90,8 @@ namespace zypp
 
         virtual License licenseToConfirm() const;
 
+       TranslatedText _summary;
+       TranslatedText _description;
         PackageGroup _group;
         std::list<std::string> _authors;
         std::list<std::string> _keywords;