Merge branch 'repo-variables' of git://piscola.suse.de/suse/libzypp into repo-variables
[platform/upstream/libzypp.git] / zypp / RepoInfo.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.cc
10  *
11 */
12 #include <iostream>
13
14 #include "zypp/base/Logger.h"
15
16 #include "zypp/RepoInfo.h"
17
18 using namespace std;
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24   ///////////////////////////////////////////////////////////////////
25   //
26   //    CLASS NAME : RepoInfo::Impl
27   //
28   /** RepoInfo implementation. */
29   struct RepoInfo::Impl
30   {
31
32     Impl()
33       : enabled (false),
34         autorefresh(false),
35         gpgcheck(true),
36         type(repo::RepoType::NONE_e)
37     {}
38
39     ~Impl()
40     {
41       //MIL << std::endl;
42     }
43   public:
44     bool enabled;
45     bool autorefresh;
46     bool gpgcheck;
47     Url gpgkey_url;
48     repo::RepoType type;
49     Url mirrorlist_url;
50     std::set<Url> baseUrls;
51     Pathname path;
52     std::string alias;
53     std::string name;
54     Pathname filepath;
55     Pathname metadatapath;
56   public:
57
58   private:
59     friend Impl * rwcowClone<Impl>( const Impl * rhs );
60     /** clone for RWCOW_pointer */
61     Impl * clone() const
62     { return new Impl( *this ); }
63   };
64   ///////////////////////////////////////////////////////////////////
65
66   /** \relates RepoInfo::Impl Stream output */
67   inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
68   {
69     return str << "RepoInfo::Impl";
70   }
71
72   ///////////////////////////////////////////////////////////////////
73   //
74   //    CLASS NAME : RepoInfo
75   //
76   ///////////////////////////////////////////////////////////////////
77
78   ///////////////////////////////////////////////////////////////////
79   //
80   //    METHOD NAME : RepoInfo::RepoInfo
81   //    METHOD TYPE : Ctor
82   //
83   RepoInfo::RepoInfo()
84   : _pimpl( new Impl() )
85   {}
86
87   ///////////////////////////////////////////////////////////////////
88   //
89   //    METHOD NAME : RepoInfo::~RepoInfo
90   //    METHOD TYPE : Dtor
91   //
92   RepoInfo::~RepoInfo()
93   {
94     //MIL << std::endl;
95   }
96
97   RepoInfo & RepoInfo::setEnabled( bool enabled )
98   {
99     _pimpl->enabled = enabled;
100     return *this;
101   }
102
103   RepoInfo & RepoInfo::setAutorefresh( bool autorefresh )
104   {
105     _pimpl->autorefresh = autorefresh;
106     return *this;
107   }
108
109   RepoInfo & RepoInfo::setGpgCheck( bool check )
110   {
111     _pimpl->gpgcheck = check;
112     return *this;
113   }
114
115   RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
116   {
117     _pimpl->mirrorlist_url = url;
118     return *this;
119   }
120
121   RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
122   {
123     _pimpl->gpgkey_url = url;
124     return *this;
125   }
126
127   RepoInfo & RepoInfo::addBaseUrl( const Url &url )
128   {
129     _pimpl->baseUrls.insert(url);
130     return *this;
131   }
132
133   RepoInfo & RepoInfo::setBaseUrl( const Url &url )
134   {
135     _pimpl->baseUrls.clear();
136     addBaseUrl(url);
137     return *this;
138   }
139
140   RepoInfo & RepoInfo::setPath( const Pathname &path )
141   {
142     _pimpl->path = path;
143     return *this;
144   }
145
146   RepoInfo & RepoInfo::setAlias( const std::string &alias )
147   {
148     _pimpl->alias = alias;
149     return *this;
150   }
151
152   RepoInfo & RepoInfo::setType( const repo::RepoType &t )
153   {
154     _pimpl->type = t;
155     return *this;
156   }
157
158   RepoInfo & RepoInfo::setName( const std::string &name )
159   {
160     _pimpl->name = name;
161     return *this;
162   }
163
164   RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
165   {
166     _pimpl->filepath = filepath;
167     return *this;
168   }
169
170   RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
171   {
172     _pimpl->metadatapath = path;
173     return *this;
174   }
175
176   bool RepoInfo::enabled() const
177   { return _pimpl->enabled; }
178
179   bool RepoInfo::autorefresh() const
180   { return _pimpl->autorefresh; }
181
182   bool RepoInfo::gpgCheck() const
183   { return _pimpl->gpgcheck; }
184
185   std::string RepoInfo::alias() const
186   { return _pimpl->alias; }
187
188   std::string RepoInfo::name() const
189   { return _pimpl->name; }
190
191   Pathname RepoInfo::filepath() const
192   { return _pimpl->filepath; }
193
194   Pathname RepoInfo::metadataPath() const
195   { return _pimpl->metadatapath; }
196
197   repo::RepoType RepoInfo::type() const
198   { return _pimpl->type; }
199
200   Url RepoInfo::mirrorListUrl() const
201   { return _pimpl->mirrorlist_url; }
202
203   Url RepoInfo::gpgKeyUrl() const
204   { return _pimpl->gpgkey_url; }
205
206   std::set<Url> RepoInfo::baseUrls() const
207   { return _pimpl->baseUrls; }
208
209   Pathname RepoInfo::path() const
210   { return _pimpl->path; }
211
212   RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
213   {
214     return make_transform_iterator( _pimpl->baseUrls.begin(),
215                                     repo::RepoVariablesUrlReplacer() );
216     //return _pimpl->baseUrls.begin();
217   }
218
219   RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
220   {
221     //return _pimpl->baseUrls.end();
222     return make_transform_iterator( _pimpl->baseUrls.end(),
223                                     repo::RepoVariablesUrlReplacer() );
224   }
225
226   RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
227   { return _pimpl->baseUrls.size(); }
228
229   bool RepoInfo::baseUrlsEmpty() const
230   { return _pimpl->baseUrls.empty(); }
231
232   std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
233   {
234     str << "--------------------------------------" << std::endl;
235     str << "- alias       : " << alias() << std::endl;
236     std::set<Url> url_set(baseUrls());
237     for ( std::set<Url>::const_iterator it = url_set.begin();
238           it != url_set.end();
239           ++it )
240     {
241       str << "- url         : " << *it << std::endl;
242     }
243     str << "- path        : " << path() << std::endl;
244     str << "- type        : " << type() << std::endl;
245     str << "- enabled     : " << enabled() << std::endl;
246
247     str << "- autorefresh : " << autorefresh() << std::endl;
248     str << "- gpgcheck : " << gpgCheck() << std::endl;
249     str << "- gpgkey : " << gpgKeyUrl() << std::endl;
250
251     return str;
252   }
253
254   std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
255   {
256     str << "[" << alias() << "]" << endl;
257     str << "name=" << name() << endl;
258
259     if ( ! baseUrls().empty() )
260       str << "baseurl=";
261     for ( urls_const_iterator it = baseUrlsBegin();
262           it != baseUrlsEnd();
263           ++it )
264     {
265       str << *it << endl;
266     }
267
268     if ( ! path().empty() )
269       str << "path="<< path() << endl;
270
271     if ( ! (mirrorListUrl().asString().empty()) )
272       str << "mirrorlist=" << mirrorListUrl() << endl;
273
274     str << "type=" << type().asString() << endl;
275     str << "enabled=" << (enabled() ? "1" : "0") << endl;
276     str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
277     str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
278     if ( ! (gpgKeyUrl().asString().empty()) )
279       str << "gpgkey=" <<gpgKeyUrl() << endl;
280
281     return str;
282   }
283
284   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
285   {
286     return obj.dumpOn(str);
287   }
288
289   /////////////////////////////////////////////////////////////////
290 } // namespace zypp
291 ///////////////////////////////////////////////////////////////////