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
00077 if (!arch.compatibleWith( _system_arch ) && !_sourceImpl->_provides_shared_data[_nvra])
00078 {
00079 _current = NULL;
00080 return;
00081 }
00082
00083 _count++;
00084 }
00085 else if ( stag_r.name == "Sum" )
00086 {
00087 _sourceImpl->_package_data[_nvra]._summary = TranslatedText( stag_r.value, _lang);
00088 }
00089 }
00090
00091
00092 virtual void consume( const MultiTag & mtag_r )
00093 {
00094
00095
00096
00097 if ( mtag_r.name == "Des" )
00098 {
00099 _sourceImpl->_package_data[_nvra]._description = TranslatedText (mtag_r.values, _lang);
00100 }
00101 else if ( mtag_r.name == "Ins" )
00102 {
00103 _sourceImpl->_package_data[_nvra]._insnotify = TranslatedText (mtag_r.values, _lang);
00104 }
00105 else if ( mtag_r.name == "Del" )
00106 {
00107 _sourceImpl->_package_data[_nvra]._delnotify = TranslatedText (mtag_r.values, _lang);
00108 }
00109 else if ( mtag_r.name == "Eul" )
00110 {
00111 _sourceImpl->_package_data[_nvra]._license_to_confirm = TranslatedText (mtag_r.values, _lang);
00112 }
00113 }
00114 };
00115
00117
00118 void parsePackagesLang( SuseTagsImpl::Ptr sourceimpl, const Pathname & file_r, const Locale & lang_r, const PkgContent & content_r )
00119 {
00120 PackagesLangParser p ( sourceimpl, content_r, lang_r);
00121 MIL << "Package descriptions/translations parser: [" << file_r << "]. Source [" << sourceimpl->selfSourceRef().alias() << "] at URL:[" << sourceimpl->selfSourceRef().url().asString() << "]. Starting with " << content_r.size() << " packages" << std::endl;
00122 try
00123 {
00124 p.parse( file_r );
00125 }
00126 catch(zypp::parser::tagfile::ParseException &e)
00127 {
00128 ZYPP_CAUGHT(e);
00129 ERR << "Bad Source [" << sourceimpl->selfSourceRef().alias() << "] at URL:[" << sourceimpl->selfSourceRef().url().asString() << "]. Packages descriptions/translations " << file_r << " is broken. You will not see translations." << std::endl;
00130 return;
00131 }
00132
00133 MIL << "Source [" << sourceimpl->selfSourceRef().alias() << "] at URL:[" << sourceimpl->selfSourceRef().url().asString() << "]. packages.LANG parser done. [ Total packages: " << content_r.size() << " ] [ Package data: " << sourceimpl->_package_data.size() << " ]" << std::endl;
00134
00135 return;
00136 }
00137
00139 }
00142 }
00145 }