RepoFileReader.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 #include "zypp/base/InputStream.h"
00015 #include "zypp/base/UserRequestException.h"
00016 
00017 #include "zypp/parser/IniDict.h"
00018 #include "zypp/parser/RepoFileReader.h"
00019 
00020 using std::endl;
00021 using zypp::parser::IniDict;
00022 
00024 namespace zypp
00025 { 
00026 
00027   namespace parser
00028   { 
00029 
00034     static void repositories_in_file( const Pathname &file,
00035                                       const RepoFileReader::ProcessRepo &callback,
00036                                       const ProgressData::ReceiverFnc &progress )
00037     {
00038       InputStream is(file);
00039       parser::IniDict dict(is);
00040       for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
00041             its != dict.sectionsEnd();
00042             ++its )
00043       {
00044         MIL << (*its) << endl;
00045         
00046         RepoInfo info;
00047         info.setAlias(*its);
00048                       
00049         for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
00050               it != dict.entriesEnd(*its);
00051               ++it )
00052         {
00053           //MIL << (*it).first << endl;
00054           if (it->first == "name" )
00055             info.setName(it-> second);
00056           else if ( it->first == "enabled" )
00057             info.setEnabled( it->second == "1" );
00058           else if ( it->first == "baseurl" && !it->second.empty())
00059             info.addBaseUrl( Url(it->second) );
00060           else if ( it->first == "path" )
00061             info.setPath( Pathname(it->second) );
00062           else if ( it->first == "type" )
00063             info.setType(repo::RepoType(it->second));
00064           else if ( it->first == "autorefresh" )
00065             info.setAutorefresh( it->second == "1" );
00066           else if ( it->first == "mirrorlist" && !it->second.empty())
00067             info.setMirrorListUrl(Url(it->second));
00068           else if ( it->first == "gpgkey" && !it->second.empty())
00069             info.setGpgKeyUrl( Url(it->second) );
00070           else if ( it->first == "gpgcheck" )
00071             info.setGpgCheck( it->second == "1" );
00072           else
00073             ERR << "Unknown attribute " << it->second << " ignored" << endl;
00074         }
00075         MIL << "Linking repo info with file " << file << endl;
00076         info.setFilepath(file);
00077         // add it to the list.
00078         callback(info);
00079         //if (!progress.tick())
00080         //  ZYPP_THROW(AbortRequestException());
00081       }
00082     }
00083 
00085     //
00086     //  CLASS NAME : RepoFileReader
00087     //
00089 
00090     RepoFileReader::RepoFileReader( const Pathname & repo_file,
00091                                     const ProcessRepo & callback,
00092                                     const ProgressData::ReceiverFnc &progress )
00093       : _callback(callback)
00094     {
00095       repositories_in_file(repo_file, _callback, progress);
00096       //MIL << "Done" << endl;
00097     }
00098 
00099     RepoFileReader::~RepoFileReader()
00100     {}
00101 
00102     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
00103     {
00104       return str;
00105     }
00106 
00108   } // namespace parser
00111 } // namespace zypp

Generated on Tue Sep 25 19:23:02 2007 for libzypp by  doxygen 1.5.3