00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014
00015 #include "zypp/source/susetags/PackagesLangParser.h"
00016 #include "zypp/parser/tagfile/TagFileParser.h"
00017 #include "zypp/Package.h"
00018 #include "zypp/source/susetags/SuseTagsImpl.h"
00019 #include "zypp/source/susetags/SuseTagsPackageImpl.h"
00020
00021 #include "zypp/ZYppFactory.h"
00022
00023 using std::endl;
00024
00026 namespace zypp
00027 {
00028
00029 namespace source
00030 {
00031
00032 namespace susetags
00033 {
00034
00035 using namespace parser::tagfile;
00036
00037 struct PackagesLangParser : public parser::tagfile::TagFileParser
00038 {
00039 const PkgContent & _content;
00040 const Locale & _lang;
00041 PkgImplPtr _current;
00042
00043 NVRA _nvra;
00044 int _count;
00045 std::set<NVRA> _notfound;
00046 Arch _system_arch;
00047
00048 SuseTagsImpl::Ptr _sourceImpl;
00049
00050 PackagesLangParser ( SuseTagsImpl::Ptr sourceimpl , const PkgContent & content_r, const Locale & lang_r)
00051 : _content( content_r )
00052 , _lang( lang_r)
00053 , _count(0)
00054 , _sourceImpl( sourceimpl )
00055
00056 {
00057 ZYpp::Ptr z = getZYpp();
00058 _system_arch = z->architecture();
00059 }
00060
00061
00062 virtual void consume( const SingleTag & stag_r )
00063 {
00064 if ( stag_r.name == "Pkg" )
00065 {
00066 std::vector<std::string> words;
00067 str::split( stag_r.value, std::back_inserter(words) );
00068
00069 if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
00070 ZYPP_THROW( ParseException( "[" + _file_r.asString() + "] Parse error in tag Pkg, expected [name version release arch], found: [" + stag_r.value + "]" ) );
00071
00072 Arch arch( words[3] );
00073 _nvra = NVRA( words[0], Edition(words[1],words[2]), arch );
00074
00075
00076 if (!arch.compatibleWith( _system_arch ) && !_sourceImpl->_is_shared[_nvra])
00077 {
00078 _current = NULL;
00079 return;
00080 }
00081
00082 PkgContent::const_iterator it = _content.find(NVRAD(_nvra));
00083 if (it == _content.end())
00084 {
00085
00086 _current = NULL;
00087 _notfound.insert(_nvra);
00088 }
00089 else
00090 {
00091
00092 _count++;
00093 _current = it->second;
00094 }
00095
00096 }
00097 else if ( stag_r.name == "Sum" )
00098 {
00099 if (_current != NULL)
00100 _sourceImpl->_package_data[_nvra]._summary = TranslatedText( stag_r.value, _lang);
00101 }
00102 }
00103
00104
00105 virtual void consume( const MultiTag & mtag_r )
00106 {
00107 if ( _current == NULL )
00108 return;
00109
00110 if ( mtag_r.name == "Des" )
00111 {
00112 _sourceImpl->_package_data[_nvra]._description = TranslatedText (mtag_r.values, _lang);
00113 }
00114 else if ( mtag_r.name == "Ins" )
00115 {
00116 _sourceImpl->_package_data[_nvra]._insnotify = TranslatedText (mtag_r.values, _lang);
00117 }
00118 else if ( mtag_r.name == "Del" )
00119 {
00120 _sourceImpl->_package_data[_nvra]._delnotify = TranslatedText (mtag_r.values, _lang);
00121 }
00122 else if ( mtag_r.name == "Eul" )
00123 {
00124 for ( std::list<std::string>::const_iterator it = mtag_r.values.begin(); it != mtag_r.values.end(); ++it)
00125 {
00126 _sourceImpl->_package_data[_nvra]._license_to_confirm += *it;
00127 }
00128 }
00129 }
00130 };
00131
00133
00134 void parsePackagesLang( SuseTagsImpl::Ptr sourceimpl, const Pathname & file_r, const Locale & lang_r, const PkgContent & content_r )
00135 {
00136 PackagesLangParser p ( sourceimpl, content_r, lang_r);
00137 MIL << "Starting with " << content_r.size() << " packages" << endl;
00138 try
00139 {
00140 p.parse( file_r );
00141 }
00142 catch(zypp::parser::tagfile::ParseException &e)
00143 {
00144 ZYPP_CAUGHT(e);
00145 ERR << "Packages Lang " << file_r << " is broken." << std::endl;
00146 return;
00147 }
00148
00149 MIL << "Ending after " << p._count << " langs with " << content_r.size() << " packages and " << p._notfound.size() << " not founds." <<endl;
00150 WAR << "Not found packages:" << std::endl;
00151 for ( std::set<NVRA>::const_iterator it = p._notfound.begin(); it != p._notfound.end(); ++it)
00152 {
00153 NVRA nvra = *it;
00154 WAR << "-> " << nvra.name << " " << nvra.edition << " " << nvra.arch << std::endl;
00155 }
00156 return;
00157 }
00158
00160 }
00163 }
00166 }