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   {
00072     ZYPP_THROW(Exception("Can't read patches file "+file_r.asString()));
00073   }
00074   std::string buffer;
00075   // read vendor
00076   getline(file, buffer);
00077 
00078   regex rx("^([\\S]+)( (.*))?$");
00079   boost::smatch what;
00080 
00081   if (boost::regex_match(buffer, what, rx))
00082   {
00083     //dumpRegexpResults(what);
00084     entry_r.dir = Pathname(what[1]);
00085     entry_r.comment = what[3];
00086   }
00087   else
00088   {
00089     // throw exception?
00090   }
00091 
00092   while (file && !file.eof())
00093   {
00094     getline(file, buffer);
00095     rx = boost::regex("^(.+)-(.+)$");
00096     if (boost::regex_match(buffer, what, rx, boost::match_extra))
00097     {
00098       zypp::parser::tagfile::dumpRegexpResults(what);
00099       entry_r.products.insert(std::pair<std::string, std::string>(what[1],what[2]));
00100     }
00101     else
00102     {
00103       // throw exception?
00104     }
00105 
00106   }
00107 }
00108 
00110 } // namespace tagfile
00113 } // namespace parser
00116 } // namespace zypp

Generated on Tue Nov 28 16:49:32 2006 for zypp by  doxygen 1.5.0