1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/repo/RepoFileReader.cc
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/String.h"
15 #include "zypp/base/InputStream.h"
16 #include "zypp/base/UserRequestException.h"
18 #include "zypp/parser/IniDict.h"
19 #include "zypp/parser/RepoFileReader.h"
22 using zypp::parser::IniDict;
24 ///////////////////////////////////////////////////////////////////
26 { /////////////////////////////////////////////////////////////////
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
32 * \short List of RepoInfo's from a file.
33 * \param file pathname of the file to read.
35 static void repositories_in_stream( const InputStream &is,
36 const RepoFileReader::ProcessRepo &callback,
37 const ProgressData::ReceiverFnc &progress )
39 parser::IniDict dict(is);
40 for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
41 its != dict.sectionsEnd();
47 for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
48 it != dict.entriesEnd(*its);
51 //MIL << (*it).first << endl;
52 if (it->first == "name" )
53 info.setName(it-> second);
54 else if ( it->first == "enabled" )
55 info.setEnabled( str::strToTrue( it->second ) );
56 else if ( it->first == "priority" )
57 info.setPriority( str::strtonum<unsigned>( it->second ) );
58 else if ( it->first == "baseurl" && !it->second.empty())
59 info.addBaseUrl( Url(it->second) );
60 else if ( it->first == "path" )
61 info.setPath( Pathname(it->second) );
62 else if ( it->first == "type" )
63 info.setType(repo::RepoType(it->second));
64 else if ( it->first == "autorefresh" )
65 info.setAutorefresh( str::strToTrue( it->second ) );
66 else if ( it->first == "mirrorlist" && !it->second.empty())
67 info.setMirrorListUrl(Url(it->second));
68 else if ( it->first == "gpgkey" && !it->second.empty())
69 info.setGpgKeyUrl( Url(it->second) );
70 else if ( it->first == "gpgcheck" )
71 info.setGpgCheck( str::strToTrue( it->second ) );
72 else if ( it->first == "keeppackages" )
73 info.setKeepPackages( str::strToTrue( it->second ) );
74 else if ( it->first == "service" )
75 info.setService( it->second );
77 ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl;
79 info.setFilepath(is.path());
81 // add it to the list.
83 //if (!progress.tick())
84 // ZYPP_THROW(AbortRequestException());
88 ///////////////////////////////////////////////////////////////////
90 // CLASS NAME : RepoFileReader
92 ///////////////////////////////////////////////////////////////////
94 RepoFileReader::RepoFileReader( const Pathname & repo_file,
95 const ProcessRepo & callback,
96 const ProgressData::ReceiverFnc &progress )
99 repositories_in_stream(InputStream(repo_file), _callback, progress);
102 RepoFileReader::RepoFileReader( const InputStream &is,
103 const ProcessRepo & callback,
104 const ProgressData::ReceiverFnc &progress )
105 : _callback(callback)
107 repositories_in_stream(is, _callback, progress);
110 RepoFileReader::~RepoFileReader()
114 std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
119 /////////////////////////////////////////////////////////////////
120 } // namespace parser
121 ///////////////////////////////////////////////////////////////////
122 /////////////////////////////////////////////////////////////////
124 ///////////////////////////////////////////////////////////////////