improve log
[platform/upstream/libzypp.git] / zypp / parser / RepoFileReader.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/repo/RepoFileReader.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/String.h"
15 #include "zypp/base/InputStream.h"
16 #include "zypp/base/UserRequestException.h"
17
18 #include "zypp/parser/IniDict.h"
19 #include "zypp/parser/RepoFileReader.h"
20
21 using std::endl;
22 using zypp::parser::IniDict;
23
24 ///////////////////////////////////////////////////////////////////
25 namespace zypp
26 { /////////////////////////////////////////////////////////////////
27   ///////////////////////////////////////////////////////////////////
28   namespace parser
29   { /////////////////////////////////////////////////////////////////
30
31     /**
32    * \short List of RepoInfo's from a file.
33    * \param file pathname of the file to read.
34    */
35     static void repositories_in_file( const Pathname &file,
36                                       const RepoFileReader::ProcessRepo &callback,
37                                       const ProgressData::ReceiverFnc &progress )
38     {
39       InputStream is(file);
40       parser::IniDict dict(is);
41       for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
42             its != dict.sectionsEnd();
43             ++its )
44       {
45         RepoInfo info;
46         info.setAlias(*its);
47
48         for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
49               it != dict.entriesEnd(*its);
50               ++it )
51         {
52           //MIL << (*it).first << endl;
53           if (it->first == "name" )
54             info.setName(it-> second);
55           else if ( it->first == "enabled" )
56             info.setEnabled( str::strToTrue( it->second ) );
57           else if ( it->first == "priority" )
58             info.setPriority( str::strtonum<unsigned>( it->second ) );
59           else if ( it->first == "baseurl" && !it->second.empty())
60             info.addBaseUrl( Url(it->second) );
61           else if ( it->first == "path" )
62             info.setPath( Pathname(it->second) );
63           else if ( it->first == "type" )
64             info.setType(repo::RepoType(it->second));
65           else if ( it->first == "autorefresh" )
66             info.setAutorefresh( str::strToTrue( it->second ) );
67           else if ( it->first == "mirrorlist" && !it->second.empty())
68             info.setMirrorListUrl(Url(it->second));
69           else if ( it->first == "gpgkey" && !it->second.empty())
70             info.setGpgKeyUrl( Url(it->second) );
71           else if ( it->first == "gpgcheck" )
72             info.setGpgCheck( str::strToTrue( it->second ) );
73           else if ( it->first == "keeppackages" )
74             info.setKeepPackages( str::strToTrue( it->second ) );
75           else if ( it->first == "service" )
76             info.setService( it->second );
77           else
78             ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl;
79         }
80         info.setFilepath(file);
81         MIL << info << endl;
82         // add it to the list.
83         callback(info);
84         //if (!progress.tick())
85         //  ZYPP_THROW(AbortRequestException());
86       }
87     }
88
89     ///////////////////////////////////////////////////////////////////
90     //
91     //  CLASS NAME : RepoFileReader
92     //
93     ///////////////////////////////////////////////////////////////////
94
95     RepoFileReader::RepoFileReader( const Pathname & repo_file,
96                                     const ProcessRepo & callback,
97                                     const ProgressData::ReceiverFnc &progress )
98       : _callback(callback)
99     {
100       repositories_in_file(repo_file, _callback, progress);
101       //MIL << "Done" << endl;
102     }
103
104     RepoFileReader::~RepoFileReader()
105     {}
106
107     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
108     {
109       return str;
110     }
111
112     /////////////////////////////////////////////////////////////////
113   } // namespace parser
114   ///////////////////////////////////////////////////////////////////
115   /////////////////////////////////////////////////////////////////
116 } // namespace zypp
117 ///////////////////////////////////////////////////////////////////