PackagesLangParser.cc

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
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 ( parser::ParserProgress::Ptr progress, SuseTagsImpl::Ptr sourceimpl , const PkgContent & content_r, const Locale & lang_r )
00051       : parser::tagfile::TagFileParser(progress)
00052       ,_content( content_r )
00053       , _lang( lang_r)
00054       , _count(0)
00055       , _sourceImpl( sourceimpl )
00056 
00057   {
00058     ZYpp::Ptr z = getZYpp();
00059     _system_arch = z->architecture();
00060   }
00061 
00062   /* Consume SingleTag data. */
00063   virtual void consume( const SingleTag & stag_r )
00064   {
00065     if ( stag_r.name == "Pkg" )
00066     {
00067       std::vector<std::string> words;
00068       str::split( stag_r.value, std::back_inserter(words) );
00069 
00070       if ( str::split( stag_r.value, std::back_inserter(words) ) != 4 )
00071         ZYPP_THROW( ParseException( "[" + _file_r.asString() + "] Parse error in tag Pkg, expected [name version release arch], found: [" + stag_r.value + "]" ) );
00072 
00073       Arch arch( words[3] );
00074       _nvra = NVRA( words[0], Edition(words[1],words[2]), arch );
00075       // only discard the package if it is not compatible AND it does not provide data
00076       // to other packages
00077 
00078       if (!arch.compatibleWith( _system_arch ) && !_sourceImpl->_provides_shared_data[_nvra])
00079       {
00080         _current = NULL;
00081         return;
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   /* Consume MulitTag data. */
00092   virtual void consume( const MultiTag & mtag_r )
00093   {
00094     //if ( _current == NULL )
00095     //  return;
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( parser::ParserProgress::Ptr progress, SuseTagsImpl::Ptr sourceimpl, const Pathname & file_r, const Locale & lang_r, const PkgContent & content_r )
00119 {
00120   PackagesLangParser p( progress, 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 } // namespace susetags
00142 } // namespace source
00145 } // namespace zypp

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