00001
00002
00003
00004
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/MediaMetadataParser.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 static void dumpRegexpResults( const boost::smatch &what )
00042 {
00043 for ( unsigned int k=0; k < what.size(); k++)
00044 {
00045 DBG << "[match "<< k << "] [" << what[k] << "]" << std::endl;
00046 }
00047 }
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00071
00072
00073
00074
00075 void MediaMetadataParser::parse( const Pathname & file_r, MediaEntry &entry_r )
00076 {
00077 std::ifstream file(file_r.asString().c_str());
00078 if (!file) {
00079 ZYPP_THROW(Exception("Can't read media file "+file_r.asString()));
00080 }
00081
00082 std::string buffer;
00083
00084 getline(file, entry_r.vendor);
00085
00086 getline(file, entry_r.timestamp);
00087
00088 std::string media_count_str;
00089
00090 getline(file, buffer);
00091 regex is_digit_rx("^[\\d]+$");
00092 boost::smatch what_digit;
00093
00094
00095
00096 bool consume = false;
00097
00098 if(boost::regex_match(buffer, what_digit, is_digit_rx))
00099 {
00100
00101 str::strtonum(buffer, entry_r.count);
00102
00103 consume = true;
00104 }
00105 else
00106 {
00107
00108 entry_r.count = 1;
00109 }
00110
00111 while(file && !file.eof())
00112 {
00113
00114 if (consume)
00115 getline(file, buffer);
00116
00117
00118 consume = true;
00119 boost::regex e("^MEDIA([\\d]+)(\\.([_A-Za-z]+)){0,1} (.+)$");
00120 boost::smatch what;
00121 if(boost::regex_match(buffer, what, e, boost::match_extra))
00122 {
00123 if ( what.size() < 5 ) {
00124 ZYPP_THROW (Exception("Can't match MEDIA in '" + buffer + "'"));
00125 }
00126
00127 dumpRegexpResults(what);
00128
00129 unsigned int number = 1;
00130 str::strtonum( what[1], number);
00131 std::string lang = what[3];
00132 std::string desc = what[4];
00133 entry_r.alternate_names[number][lang] = desc;
00134 }
00135 else
00136 {
00137 ZYPP_THROW (Exception("Can't find MEDIA in '" + buffer + "'"));
00138 }
00139
00140 }
00141 }
00142
00144 }
00147 }
00150 }