rename Local Services to Plugin Services as discussed with Michael
[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_stream( const InputStream &is,
36                                         const RepoFileReader::ProcessRepo &callback,
37                                         const ProgressData::ReceiverFnc &progress )
38     {
39       parser::IniDict dict(is);
40       for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
41             its != dict.sectionsEnd();
42             ++its )
43       {
44         RepoInfo info;
45         info.setAlias(*its);
46
47         for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
48               it != dict.entriesEnd(*its);
49               ++it )
50         {
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 );
76           else
77             ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl;
78         }
79         info.setFilepath(is.path());
80         MIL << info << endl;
81         // add it to the list.
82         callback(info);
83         //if (!progress.tick())
84         //  ZYPP_THROW(AbortRequestException());
85       }
86     }
87
88     ///////////////////////////////////////////////////////////////////
89     //
90     //  CLASS NAME : RepoFileReader
91     //
92     ///////////////////////////////////////////////////////////////////
93
94     RepoFileReader::RepoFileReader( const Pathname & repo_file,
95                                     const ProcessRepo & callback,
96                                     const ProgressData::ReceiverFnc &progress )
97       : _callback(callback)
98     {
99       repositories_in_stream(InputStream(repo_file), _callback, progress);
100     }
101
102     RepoFileReader::RepoFileReader( const InputStream &is,
103                                     const ProcessRepo & callback,
104                                     const ProgressData::ReceiverFnc &progress )
105       : _callback(callback)
106     {
107       repositories_in_stream(is, _callback, progress);
108     }
109
110     RepoFileReader::~RepoFileReader()
111     {}
112
113
114     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
115     {
116       return str;
117     }
118
119     /////////////////////////////////////////////////////////////////
120   } // namespace parser
121   ///////////////////////////////////////////////////////////////////
122   /////////////////////////////////////////////////////////////////
123 } // namespace zypp
124 ///////////////////////////////////////////////////////////////////