first pieces for the media.1/patches parser
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 26 Jan 2006 10:36:30 +0000 (10:36 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Thu, 26 Jan 2006 10:36:30 +0000 (10:36 +0000)
testsuite/parser/MediaMetadataParserTest.cc
zypp/parser/tagfile/Makefile.am
zypp/parser/tagfile/MediaMetadataParser.cc
zypp/parser/tagfile/MediaMetadataParser.h
zypp/parser/tagfile/MediaPatchesMetadataParser.cc [new file with mode: 0644]
zypp/parser/tagfile/MediaPatchesMetadataParser.h [new file with mode: 0644]
zypp/parser/tagfile/ProductMetadataParser.h

index aab06db..12d4a07 100644 (file)
@@ -1,5 +1,6 @@
 
 #include <zypp/parser/tagfile/MediaMetadataParser.h> 
+#include <zypp/parser/tagfile/MediaPatchesMetadataParser.h> 
 #include <zypp/base/Logger.h>
 #include <zypp/Pathname.h>
 
@@ -16,5 +17,11 @@ int main()
   
   parser.parse(Pathname("tagfiles/media/media-1-SUSE-9.3-DVD-RC3.txt"), entry);
   //DBG << "arch: " << entry.arch["x86_64"].size() << std::endl;
+  
+  MediaPatchesMetadataParser patches_parser;
+  MediaPatchesMetadataParser::MediaPatchesEntry patches_entry;
+  patches_parser.parse("tagfiles/patches/patches-1", patches_entry);
+
+  
   return 0;
 }
index 876e7a3..9f3be78 100644 (file)
@@ -15,7 +15,8 @@ parsertagfileinclude_HEADERS = \
        Grammar.h       \
        Parser.h \
   ProductMetadataParser.h      \
-       MediaMetadataParser.h
+       MediaMetadataParser.h \
+       MediaPatchesMetadataParser.h
 
 noinst_LTLIBRARIES =   lib@PACKAGE@_parser_tagfile.la
 
@@ -26,7 +27,8 @@ lib@PACKAGE@_parser_tagfile_la_SOURCES = \
        Tags.cc         \
        Parser.cc \
        ProductMetadataParser.cc \
-       MediaMetadataParser.cc
+       MediaMetadataParser.cc \
+       MediaPatchesMetadataParser.cc
 
 lib@PACKAGE@_parser_tagfile_la_LIBADD = 
 
index 7153102..b0f9c35 100644 (file)
@@ -27,8 +27,6 @@
 using namespace std;
 using namespace boost;
 
-typedef find_iterator<string::iterator> string_find_iterator;
-
 ///////////////////////////////////////////////////////////////////
 namespace zypp
 { /////////////////////////////////////////////////////////////////
@@ -136,29 +134,7 @@ namespace zypp
         }
       }
 
-      void MediaMetadataParser::parseLine( const string &key, const string &modif, const string &value, map< string, list<string> > &container)
-      {
-        if ( modif.size() == 0)
-          parseLine( key, value, container["default"]); 
-        else
-          parseLine( key, value, container[modif]);
-      }
-
-      void MediaMetadataParser::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;
-      }
-
-      void MediaMetadataParser::parseLine( const string &key, const string &value, std::list<std::string> &container)
-      {
-          str::split( value, std::back_inserter(container), " ");
-      }
-
-
-      /////////////////////////////////////////////////////////////////
+       /////////////////////////////////////////////////////////////////
     } // namespace tagfile
     ///////////////////////////////////////////////////////////////////
     /////////////////////////////////////////////////////////////////
index 681850c..298ec28 100644 (file)
@@ -40,7 +40,6 @@ namespace zypp
       struct MediaMetadataParser
       {
         struct MediaEntry {
-          Pathname    dir;
           std::string vendor;
           std::string timestamp;
           unsigned int count;
@@ -48,18 +47,8 @@ namespace zypp
           // map media number to ( map language -> description string )
           // entry.alternate_names[1]["de"] -> "SUSE Linux"
           std::map< unsigned int, std::map<std::string, std::string> > alternate_names;
-              
-          MediaEntry( const Pathname & dir_r = "/" ){
-            dir  = dir_r;
-          }
-          bool operator<( const MediaEntry & rhs ) const {
-            return( dir.asString() < rhs.dir.asString() );
-          }
         };
 
-        typedef std::set<MediaEntry> MediaSet;
-
-
         virtual ~MediaMetadataParser()
         {}
 
@@ -71,16 +60,7 @@ namespace zypp
         /* Parse a key.modifier (std::list of std::strings)
          * That means, translatable tag with multiple values
          * the default modifier will get the modifier of default (LABEL.de, LABEL as LANGUAGE.default)
-        */ 
-        void parseLine( const std::string &key, const std::string &modif, const std::string &value, std::map< std::string, std::list<std::string> > &container);
-        /*
-         * same as above, but the value is a single std::string, this means, translatable tags, with only 1 value
-        */
-        void parseLine( const std::string &key,const std::string &modif, const std::string &value, std::map< std::string, std::string > &container);
-        /*
-         * Non translatable tag with multiple values
-         */
-        void parseLine( const std::string &key, const std::string &value, std::list<std::string> &container);
+         */ 
       };
       ///////////////////////////////////////////////////////////////////
 
diff --git a/zypp/parser/tagfile/MediaPatchesMetadataParser.cc b/zypp/parser/tagfile/MediaPatchesMetadataParser.cc
new file mode 100644 (file)
index 0000000..422f9c7
--- /dev/null
@@ -0,0 +1,139 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/parser/tagfile/MediaPatchesMetadataParser.cc
+ *
+*/
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
+#include <boost/tokenizer.hpp>
+#include <boost/algorithm/string.hpp>
+
+#include "zypp/base/Logger.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/base/String.h"
+
+#include "zypp/parser/tagfile/MediaPatchesMetadataParser.h"
+#include <boost/regex.hpp>
+#include "zypp/parser/tagfile/Grammar.h"
+
+using namespace std;
+using namespace boost;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace parser
+  { /////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////
+    namespace tagfile
+    { /////////////////////////////////////////////////////////////////
+
+      static void dumpRegexpResults( const boost::smatch &what )
+      {
+        for ( unsigned int k=0; k < what.size(); k++)
+        {
+          DBG << "[match "<< k << "] [" << what[k] << "]" << std::endl; 
+        }
+      }
+      
+      /*
+        File:  media
+        Location  /media.N/ directory on media
+        Content  two or more lines of ASCII as follows
+        <vendor>
+        <YYYYMMDDHHMMSS>
+        [<media count>]
+        [<media flags>]
+        [<media names>]
+
+        Currently defined flags:
+         
+        doublesided 
+        media is double sided, YaST will ask for 'front side' for odd-numbered media and 'back side' for even-numbered media.
+        The default is single-sided media.
+
+        <media names> may define alternate strings to use when asking to insert a certain media.
+         They are defined as <key><whitespace><value> pairs, separated by \n.
+         
+      */
+      
+      ///////////////////////////////////////////////////////////////////
+      //
+      //       METHOD NAME : Parser::parse
+      //       METHOD TYPE : void
+      //
+      void MediaPatchesMetadataParser::parse( const Pathname & file_r, MediaPatchesEntry &entry_r )
+      {
+        std::ifstream file(file_r.asString().c_str());
+        std::string buffer;
+        // read vendor
+        getline(file, buffer);
+
+        regex rx("^[\\S]+( (.*))?$");
+        boost::smatch what;
+
+        if(boost::regex_match(buffer, what, rx))
+        {
+          dumpRegexpResults(what);
+
+          // it was the media count
+          //str::strtonum(buffer, entry_r.count);
+          // consume another line
+          //consume = true;
+        }
+        else
+        {
+          //entry_r.count = 1;
+        }
+
+        /* 
+        while(!file.eof())
+        {
+          // probably is the first line after we dont find the media number
+          if(consume)
+            getline(file, buffer);
+          
+          // only skip once
+          consume = true;
+          boost::regex e("^MEDIA([\\d]+)(\\.([_A-Za-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;
+           
+            dumpRegexpResults(what);
+            
+            unsigned int number = 1;
+            str::strtonum( what[1], number);
+            std::string lang = what[3];
+            std::string desc = what[4];
+            entry_r.alternate_names[number][lang] = desc;
+          }
+          else
+          {
+            DBG << "** No Match found:  " << buffer << std::endl;
+          }
+          
+        }
+        */
+      }
+
+      /////////////////////////////////////////////////////////////////
+    } // namespace tagfile
+    ///////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////
+  } // namespace parser
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
diff --git a/zypp/parser/tagfile/MediaPatchesMetadataParser.h b/zypp/parser/tagfile/MediaPatchesMetadataParser.h
new file mode 100644 (file)
index 0000000..5b75071
--- /dev/null
@@ -0,0 +1,76 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file      zypp/parser/tagfile/Parser.h
+ *
+*/
+#ifndef ZYPP_PARSER_TAGFILE_MediaPatchesMetadataPARSER_H
+#define ZYPP_PARSER_TAGFILE_MediaPatchesMetadataPARSER_H
+
+#include <iosfwd>
+#include <set>
+#include <map>
+#include <list>
+
+#include "zypp/parser/tagfile/Tags.h"
+#include "zypp/parser/tagfile/ParseException.h"
+
+#include "zypp/Pathname.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+  ///////////////////////////////////////////////////////////////////
+  namespace parser
+  { /////////////////////////////////////////////////////////////////
+    ///////////////////////////////////////////////////////////////////
+    namespace tagfile
+    { /////////////////////////////////////////////////////////////////
+      
+      /*
+        Location  /media.1/ directory
+        Content  one line of ASCII as follows
+        <directory> <whitespace> <optional comment>
+        zero or more lines specifying exclusive products: <productname>-<productversion>
+      */
+      
+      ///////////////////////////////////////////////////////////////////
+      //
+      //       CLASS NAME : MediaPatchesMetadataParser
+      //
+      /** Tagfile parser. */
+      struct MediaPatchesMetadataParser
+      {
+        struct MediaPatchesEntry {
+          Pathname dir;
+          std::string comment;
+          std::set<std::string> products;
+        };
+
+        virtual ~MediaPatchesMetadataParser()
+        {}
+
+        /* Parse file and invoke consume on each tag found.
+         * \throw ParseException
+         * \todo more doc on Ecaptions.
+        */
+        void parse( const Pathname & file_r, MediaPatchesEntry &entry_r );
+      };
+        ///////////////////////////////////////////////////////////////////
+
+      /////////////////////////////////////////////////////////////////
+    } // namespace tagfile
+    ///////////////////////////////////////////////////////////////////
+    /////////////////////////////////////////////////////////////////
+  } // namespace parser
+  ///////////////////////////////////////////////////////////////////
+  /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+//
+#endif //  ZYPP_PARSER_TAGFILE_MediaPatchesMetadataPPARSER_H
index 345c01a..a2df410 100644 (file)
@@ -40,7 +40,6 @@ namespace zypp
       struct ProductMetadataParser
       {
         struct ProductEntry {
-          Pathname    dir;
           std::string name;
           std::string version;
           std::string dist;
@@ -62,19 +61,8 @@ namespace zypp
           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;
-          }
-          bool operator<( const ProductEntry & rhs ) const {
-            return( dir.asString() < rhs.dir.asString() );
-          }
         };
 
-        typedef std::set<ProductEntry> ProductSet;
-
-
         virtual ~ProductMetadataParser()
         {}