all pieces in there. Can get string split to work... I miss Qt :-\(
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 24 Jan 2006 14:43:17 +0000 (14:43 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Tue, 24 Jan 2006 14:43:17 +0000 (14:43 +0000)
testsuite/parser/ProductMetadataParserTest.cc
testsuite/parser/tagfiles/products/content.1.txt [new file with mode: 0644]
zypp/parser/tagfile/ProductMetadataParser.cc
zypp/parser/tagfile/ProductMetadataParser.h

index 5aea765..52da579 100644 (file)
@@ -1,10 +1,17 @@
 
 #include <zypp/parser/tagfile/ProductMetadataParser.h> 
+#include <zypp/base/Logger.h>
+#include <zypp/Pathname.h>
+
+using namespace zypp;
+using namespace zypp::parser::tagfile;
 
 int main()
 {
-  zypp::parser::tagfile::ProductMetadataParser parser;
-  //parser.parse("tagfiles/products/content.1.txt");
+  ProductMetadataParser parser;
+  ProductMetadataParser::ProductEntry entry;
 
-  return 0;
+  parser.parse(Pathname("tagfiles/products/content.1.txt"), entry);
+  DBG << "arch: " << entry.arch["x86_64"].size() << std::endl;
+return 0;
 }
diff --git a/testsuite/parser/tagfiles/products/content.1.txt b/testsuite/parser/tagfiles/products/content.1.txt
new file mode 100644 (file)
index 0000000..85554d9
--- /dev/null
@@ -0,0 +1,22 @@
+PRODUCT SUSE SLES
+VERSION 9
+DISTPRODUCT SUSE-Linux-SLES-x86-64
+DISTVERSION 9-0
+BASEPRODUCT SUSE CORE
+BASEVERSION 9
+YOUTYPE business
+YOUPATH x86_64/update/SUSE-SLES/9
+YOUURL http://www.suse.de/cgi-bin/suseservers.cgi
+VENDOR SUSE LINUX AG
+RELNOTESURL http://www.suse.com/relnotes/x86_64/SUSE-SLES/9/release-notes.rpm
+ARCH.x86_64 x86_64 i686 i586 i486 i386 noarch
+DEFAULTBASE x86_64
+REQUIRES sles-release-9
+LINGUAS de en
+LABEL SUSE SLES Version 9
+LABEL.de SUSE SLES in der Version 9
+DESCRDIR suse/setup/descr
+DATADIR suse
+FLAGS update
+LANGUAGE en_US
+TIMEZONE America/Los_Angeles
index 89b2237..54e2af5 100644 (file)
@@ -6,7 +6,7 @@
 |                         /_____||_| |_| |_|                           |
 |                                                                      |
 \---------------------------------------------------------------------*/
-/** \file      zypp/parser/tagfile/Parser.cc
+/** \file      zypp/parser/tagfile/ProductMetadataParser.cc
  *
 */
 #include <iostream>
 #include <sstream>
 
 #include <boost/tokenizer.hpp>
+#include <boost/algorithm/string.hpp>
 
 #include "zypp/base/Logger.h"
 #include "zypp/base/PtrTypes.h"
 
 #include "zypp/parser/tagfile/ProductMetadataParser.h"
+#include <boost/regex.hpp>
 #include "zypp/parser/tagfile/Grammar.h"
 
-using std::endl;
+using namespace std;
 using namespace boost;
 
+typedef find_iterator<string::iterator> string_find_iterator;
+
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -42,13 +46,75 @@ namespace zypp
       void ProductMetadataParser::parse( const Pathname & file_r, ProductEntry &entry_r )
       {
         std::ifstream file(file_r.asString().c_str());
-        std::stringstream st;
-        st << file;
-        tokenizer<> tok(st.str());
-        //for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
-        //  std::cout << *beg << std:endl;
-        //}
+        std::string buffer;
+        while(!file.eof())
+        {
+          getline(file, buffer);
+          boost::regex e("^(([A-Z]+)(\\.([_A-Z0-9a-z]+)){0,1}) (.+)$");
+          boost::smatch what;
+          if(boost::regex_match(buffer, what, e, boost::match_extra))
+          {
+            if ( what.size() < 5 )
+              std::cout << "ups!!!!" << std::endl;
+            
+            std::string key = what[2];
+            std::string value = what[5];
+            std::string modifier = what[4];
+            if(key == "PRODUCT")
+              entry_r.name = value;
+            else if(key == "VERSION")
+              entry_r.version = value;
+            else if(key == "DISTPRODUCT")
+              entry_r.dist = value;
+            else if(key == "DISTVERSION")
+              entry_r.dist_version = value;
+             else if(key == "BASEPRODUCT")
+              entry_r.base_product = value;
+            else if(key == "BASEVERSION")
+              entry_r.base_version = value;
+            else if(key == "YOUTYPE")
+              entry_r.you_type = value;
+            else if(key == "YOUPATH")
+              entry_r.you_path = value;
+            else if(key == "YOUURL")
+              entry_r.you_url = value;
+            else if(key == "VENDOR")
+              entry_r.vendor = value;
+            else if(key == "RELNOTESURL")
+              entry_r.release_notes_url = value;
+            else if(key == "ARCH")
+              parseLine( key, modifier, value, entry_r.arch);
+            else
+              DBG << "parse error" << std::endl;
+          }
+          else
+          {
+            std::cout << "** No Match found **\n";
+          }
+          //std::cout << "hola: [" << buffer << "]" << std::endl;
+        }
+      }
+
+      void ProductMetadataParser::parseLine( const string &key, const string &modif, const string &value, map< string, list<string> > &container)
+      {
+        std::string value_copy = value;
+        string_find_iterator it = make_find_iterator(value_copy, token_finder(is_space()));
+        if(it!=string_find_iterator())
+        {
+          DBG << "add element " << key << " " << modif << " [" << value << "]" << std::endl;
+          if( modif.size() == 0)
+            container["default"].push_back(value_copy);
+          else     
+            container[modif].push_back(value_copy);
+        }
+      }
 
+      void ProductMetadataParser::parseLine( const string &key, const string &modif, const string &value, map< string, string > &container)
+      {
+        if( modif.size() == 0)
+          container["default"] = value;
+        else
+          container[modif] = value;
       }
 
       /////////////////////////////////////////////////////////////////
index 6008ee9..267901f 100644 (file)
@@ -14,6 +14,8 @@
 
 #include <iosfwd>
 #include <set>
+#include <map>
+#include <list>
 
 #include "zypp/parser/tagfile/Tags.h"
 #include "zypp/parser/tagfile/ParseException.h"
@@ -38,15 +40,35 @@ namespace zypp
       struct ProductMetadataParser
       {
         struct ProductEntry {
-          Pathname    _dir;
-          std::string _name;
+          Pathname    dir;
+          std::string name;
+          std::string version;
+          std::string dist;
+          std::string dist_version;
+          std::string base_product;
+          std::string base_version;
+          std::string you_type;
+          std::string you_path;
+          std::string you_url;
+          std::string vendor;
+          std::string release_notes_url;
+          std::map< std::string, std::list<std::string> > arch;
+          std::string default_base;
+          std::string requires;
+          std::list<std::string> languages;
+          std::map< std::string, std::string > label;
+          std::string description_dir;
+          std::string data_dir;
+          std::list<std::string> flags;
+          std::string language;
+          std::string timezone;
 
           ProductEntry( const Pathname & dir_r = "/", const std::string & name_r = std::string() ){
-            _dir  = dir_r;
-            _name = name_r;
+            dir  = dir_r;
+            name = name_r;
           }
           bool operator<( const ProductEntry & rhs ) const {
-            return( _dir.asString() < rhs._dir.asString() );
+            return( dir.asString() < rhs.dir.asString() );
           }
         };
 
@@ -61,6 +83,14 @@ namespace zypp
          * \todo more doc on Ecaptions.
         */
         void parse( const Pathname & file_r, ProductEntry &entry_r );
+        /* Parse a key.modifier (std::list of std::strings)
+         * the default modifier will get the modifier of default (LABEL.de, LABEL as LANGUAGE.default)
+        */ 
+        void parseLine( const std::string &key, const std::string &modifr, const std::string &value, std::map< std::string, std::list<std::string> > &container);
+        /*
+         * same as above, but the value is a single std::string
+        */
+        void parseLine( const std::string &key,const std::string &modif, const std::string &value, std::map< std::string, std::string > &container);
         
       };
       ///////////////////////////////////////////////////////////////////
@@ -74,4 +104,5 @@ namespace zypp
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////
-#endif // ZYPP_PARSER_TAGFILE_ProductMetadataPPARSER_H
+//
+#endif //  ZYPP_PARSER_TAGFILE_ProductMetadataPPARSER_H