MediaPatchesMetadataParser.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include <iostream>
00013 #include <fstream>
00014 #include <sstream>
00015 
00016 #include <boost/tokenizer.hpp>
00017 #include <boost/algorithm/string.hpp>
00018 
00019 #include "zypp/base/Logger.h"
00020 #include "zypp/base/Exception.h"
00021 #include "zypp/base/PtrTypes.h"
00022 #include "zypp/base/String.h"
00023 
00024 #include "zypp/parser/tagfile/TagFileParser.h"
00025 #include "zypp/source/susetags/MediaPatchesMetadataParser.h"
00026 #include <boost/regex.hpp>
00027 
00028 using namespace std;
00029 using namespace boost;
00030 
00032 namespace zypp
00033 { 
00034 
00035   namespace source
00036   { 
00037 
00038     namespace susetags
00039     { 
00040       
00041       /*
00042         File:  media
00043         Location  /media.N/ directory on media
00044         Content  two or more lines of ASCII as follows
00045         <vendor>
00046         <YYYYMMDDHHMMSS>
00047         [<media count>]
00048         [<media flags>]
00049         [<media names>]
00050 
00051         Currently defined flags:
00052          
00053         doublesided 
00054         media is double sided, YaST will ask for 'front side' for odd-numbered media and 'back side' for even-numbered media.
00055         The default is single-sided media.
00056 
00057         <media names> may define alternate strings to use when asking to insert a certain media.
00058          They are defined as <key><whitespace><value> pairs, separated by \n.
00059          
00060       */
00061       
00063       //
00064       //        METHOD NAME : Parser::parse
00065       //        METHOD TYPE : void
00066       //
00067       void MediaPatchesMetadataParser::parse( const Pathname & file_r, MediaPatchesEntry &entry_r )
00068       {
00069         std::ifstream file(file_r.asString().c_str());
00070         if (!file) {
00071             ZYPP_THROW(Exception("Can't read patches file "+file_r.asString()));
00072         }
00073         std::string buffer;
00074         // read vendor
00075         getline(file, buffer);
00076 
00077         regex rx("^([\\S]+)( (.*))?$");
00078         boost::smatch what;
00079 
00080         if(boost::regex_match(buffer, what, rx))
00081         {
00082           //dumpRegexpResults(what);
00083           entry_r.dir = Pathname(what[1]);
00084           entry_r.comment = what[3];
00085         }
00086         else
00087         {
00088           // throw exception? 
00089         }
00090 
00091         while(file && !file.eof())
00092         {
00093           getline(file, buffer);
00094           rx = boost::regex("^(.+)-(.+)$");
00095           if(boost::regex_match(buffer, what, rx, boost::match_extra))
00096           {
00097             zypp::parser::tagfile::dumpRegexpResults(what);
00098             entry_r.products.insert(std::pair<std::string, std::string>(what[1],what[2])); 
00099           }
00100           else
00101           {
00102             // throw exception?
00103           }
00104           
00105         }
00106       }
00107 
00109     } // namespace tagfile
00112   } // namespace parser
00115 } // namespace zypp

Generated on Thu Jul 6 00:07:24 2006 for zypp by  doxygen 1.4.6