00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include "zypp/base/Logger.h" 00014 #include "zypp/base/String.h" 00015 #include "zypp/base/InputStream.h" 00016 #include "zypp/base/UserRequestException.h" 00017 00018 #include "zypp/parser/IniDict.h" 00019 #include "zypp/parser/RepoFileReader.h" 00020 00021 using std::endl; 00022 using zypp::parser::IniDict; 00023 00025 namespace zypp 00026 { 00027 00028 namespace parser 00029 { 00030 00035 static void repositories_in_file( const Pathname &file, 00036 const RepoFileReader::ProcessRepo &callback, 00037 const ProgressData::ReceiverFnc &progress ) 00038 { 00039 InputStream is(file); 00040 parser::IniDict dict(is); 00041 for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin(); 00042 its != dict.sectionsEnd(); 00043 ++its ) 00044 { 00045 RepoInfo info; 00046 info.setAlias(*its); 00047 00048 for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its); 00049 it != dict.entriesEnd(*its); 00050 ++it ) 00051 { 00052 //MIL << (*it).first << endl; 00053 if (it->first == "name" ) 00054 info.setName(it-> second); 00055 else if ( it->first == "enabled" ) 00056 info.setEnabled( str::strToTrue( it->second ) ); 00057 else if ( it->first == "priority" ) 00058 info.setPriority( str::strtonum<unsigned>( it->second ) ); 00059 else if ( it->first == "baseurl" && !it->second.empty()) 00060 info.addBaseUrl( Url(it->second) ); 00061 else if ( it->first == "path" ) 00062 info.setPath( Pathname(it->second) ); 00063 else if ( it->first == "type" ) 00064 info.setType(repo::RepoType(it->second)); 00065 else if ( it->first == "autorefresh" ) 00066 info.setAutorefresh( str::strToTrue( it->second ) ); 00067 else if ( it->first == "mirrorlist" && !it->second.empty()) 00068 info.setMirrorListUrl(Url(it->second)); 00069 else if ( it->first == "gpgkey" && !it->second.empty()) 00070 info.setGpgKeyUrl( Url(it->second) ); 00071 else if ( it->first == "gpgcheck" ) 00072 info.setGpgCheck( str::strToTrue( it->second ) ); 00073 else if ( it->first == "keeppackages" ) 00074 info.setKeepPackages( str::strToTrue( it->second ) ); 00075 else if ( it->first == "service" ) 00076 info.setService( it->second ); 00077 else 00078 ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl; 00079 } 00080 info.setFilepath(file); 00081 MIL << info << endl; 00082 // add it to the list. 00083 callback(info); 00084 //if (!progress.tick()) 00085 // ZYPP_THROW(AbortRequestException()); 00086 } 00087 } 00088 00090 // 00091 // CLASS NAME : RepoFileReader 00092 // 00094 00095 RepoFileReader::RepoFileReader( const Pathname & repo_file, 00096 const ProcessRepo & callback, 00097 const ProgressData::ReceiverFnc &progress ) 00098 : _callback(callback) 00099 { 00100 repositories_in_file(repo_file, _callback, progress); 00101 //MIL << "Done" << endl; 00102 } 00103 00104 RepoFileReader::~RepoFileReader() 00105 {} 00106 00107 std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj ) 00108 { 00109 return str; 00110 } 00111 00113 } // namespace parser 00116 } // namespace zypp