00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 00014 #include "zypp/base/Logger.h" 00015 00016 #include "zypp/RepoInfo.h" 00017 00018 using namespace std; 00019 00021 namespace zypp 00022 { 00023 00025 // 00026 // CLASS NAME : RepoInfo::Impl 00027 // 00029 struct RepoInfo::Impl 00030 { 00031 00032 Impl() 00033 : enabled (false), 00034 autorefresh(false), 00035 gpgcheck(true), 00036 type(repo::RepoType::NONE_e) 00037 {} 00038 00039 ~Impl() 00040 { 00041 //MIL << std::endl; 00042 } 00043 public: 00044 bool enabled; 00045 bool autorefresh; 00046 bool gpgcheck; 00047 Url gpgkey_url; 00048 repo::RepoType type; 00049 Url mirrorlist_url; 00050 std::set<Url> baseUrls; 00051 Pathname path; 00052 std::string alias; 00053 std::string name; 00054 Pathname filepath; 00055 Pathname metadatapath; 00056 public: 00057 00058 private: 00059 friend Impl * rwcowClone<Impl>( const Impl * rhs ); 00061 Impl * clone() const 00062 { return new Impl( *this ); } 00063 }; 00065 00067 inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj ) 00068 { 00069 return str << "RepoInfo::Impl"; 00070 } 00071 00073 // 00074 // CLASS NAME : RepoInfo 00075 // 00077 00079 // 00080 // METHOD NAME : RepoInfo::RepoInfo 00081 // METHOD TYPE : Ctor 00082 // 00083 RepoInfo::RepoInfo() 00084 : _pimpl( new Impl() ) 00085 {} 00086 00088 // 00089 // METHOD NAME : RepoInfo::~RepoInfo 00090 // METHOD TYPE : Dtor 00091 // 00092 RepoInfo::~RepoInfo() 00093 { 00094 //MIL << std::endl; 00095 } 00096 00097 RepoInfo & RepoInfo::setEnabled( bool enabled ) 00098 { 00099 _pimpl->enabled = enabled; 00100 return *this; 00101 } 00102 00103 RepoInfo & RepoInfo::setAutorefresh( bool autorefresh ) 00104 { 00105 _pimpl->autorefresh = autorefresh; 00106 return *this; 00107 } 00108 00109 RepoInfo & RepoInfo::setGpgCheck( bool check ) 00110 { 00111 _pimpl->gpgcheck = check; 00112 return *this; 00113 } 00114 00115 RepoInfo & RepoInfo::setMirrorListUrl( const Url &url ) 00116 { 00117 _pimpl->mirrorlist_url = url; 00118 return *this; 00119 } 00120 00121 RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url ) 00122 { 00123 _pimpl->gpgkey_url = url; 00124 return *this; 00125 } 00126 00127 RepoInfo & RepoInfo::addBaseUrl( const Url &url ) 00128 { 00129 _pimpl->baseUrls.insert(url); 00130 return *this; 00131 } 00132 00133 RepoInfo & RepoInfo::setBaseUrl( const Url &url ) 00134 { 00135 _pimpl->baseUrls.clear(); 00136 addBaseUrl(url); 00137 return *this; 00138 } 00139 00140 RepoInfo & RepoInfo::setPath( const Pathname &path ) 00141 { 00142 _pimpl->path = path; 00143 return *this; 00144 } 00145 00146 RepoInfo & RepoInfo::setAlias( const std::string &alias ) 00147 { 00148 _pimpl->alias = alias; 00149 return *this; 00150 } 00151 00152 RepoInfo & RepoInfo::setType( const repo::RepoType &t ) 00153 { 00154 _pimpl->type = t; 00155 return *this; 00156 } 00157 00158 RepoInfo & RepoInfo::setName( const std::string &name ) 00159 { 00160 _pimpl->name = name; 00161 return *this; 00162 } 00163 00164 RepoInfo & RepoInfo::setFilepath( const Pathname &filepath ) 00165 { 00166 _pimpl->filepath = filepath; 00167 return *this; 00168 } 00169 00170 RepoInfo & RepoInfo::setMetadataPath( const Pathname &path ) 00171 { 00172 _pimpl->metadatapath = path; 00173 return *this; 00174 } 00175 00176 bool RepoInfo::enabled() const 00177 { return _pimpl->enabled; } 00178 00179 bool RepoInfo::autorefresh() const 00180 { return _pimpl->autorefresh; } 00181 00182 bool RepoInfo::gpgCheck() const 00183 { return _pimpl->gpgcheck; } 00184 00185 std::string RepoInfo::alias() const 00186 { return _pimpl->alias; } 00187 00188 std::string RepoInfo::name() const 00189 { 00190 if ( _pimpl->name.empty() ) 00191 { 00192 return alias(); 00193 } 00194 00195 repo::RepoVariablesStringReplacer replacer; 00196 return replacer(_pimpl->name); 00197 } 00198 00199 Pathname RepoInfo::filepath() const 00200 { return _pimpl->filepath; } 00201 00202 Pathname RepoInfo::metadataPath() const 00203 { return _pimpl->metadatapath; } 00204 00205 repo::RepoType RepoInfo::type() const 00206 { return _pimpl->type; } 00207 00208 Url RepoInfo::mirrorListUrl() const 00209 { return _pimpl->mirrorlist_url; } 00210 00211 Url RepoInfo::gpgKeyUrl() const 00212 { return _pimpl->gpgkey_url; } 00213 00214 std::set<Url> RepoInfo::baseUrls() const 00215 { 00216 RepoInfo::url_set replaced_urls; 00217 repo::RepoVariablesUrlReplacer replacer; 00218 for ( url_set::const_iterator it = _pimpl->baseUrls.begin(); 00219 it != _pimpl->baseUrls.end(); 00220 ++it ) 00221 { 00222 replaced_urls.insert(replacer(*it)); 00223 } 00224 return replaced_urls; 00225 00226 return _pimpl->baseUrls; 00227 } 00228 00229 Pathname RepoInfo::path() const 00230 { return _pimpl->path; } 00231 00232 RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const 00233 { 00234 return make_transform_iterator( _pimpl->baseUrls.begin(), 00235 repo::RepoVariablesUrlReplacer() ); 00236 //return _pimpl->baseUrls.begin(); 00237 } 00238 00239 RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const 00240 { 00241 //return _pimpl->baseUrls.end(); 00242 return make_transform_iterator( _pimpl->baseUrls.end(), 00243 repo::RepoVariablesUrlReplacer() ); 00244 } 00245 00246 RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const 00247 { return _pimpl->baseUrls.size(); } 00248 00249 bool RepoInfo::baseUrlsEmpty() const 00250 { return _pimpl->baseUrls.empty(); } 00251 00252 std::ostream & RepoInfo::dumpOn( std::ostream & str ) const 00253 { 00254 str << "--------------------------------------" << std::endl; 00255 str << "- alias : " << alias() << std::endl; 00256 for ( urls_const_iterator it = baseUrlsBegin(); 00257 it != baseUrlsEnd(); 00258 ++it ) 00259 { 00260 str << "- url : " << *it << std::endl; 00261 } 00262 str << "- path : " << path() << std::endl; 00263 str << "- type : " << type() << std::endl; 00264 str << "- enabled : " << enabled() << std::endl; 00265 00266 str << "- autorefresh : " << autorefresh() << std::endl; 00267 str << "- gpgcheck : " << gpgCheck() << std::endl; 00268 str << "- gpgkey : " << gpgKeyUrl() << std::endl; 00269 00270 return str; 00271 } 00272 00273 std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const 00274 { 00275 // we save the original data without variable replacement 00276 str << "[" << alias() << "]" << endl; 00277 str << "name=" << _pimpl->name << endl; 00278 00279 if ( ! _pimpl->baseUrls.empty() ) 00280 str << "baseurl="; 00281 for ( url_set::const_iterator it = _pimpl->baseUrls.begin(); 00282 it != _pimpl->baseUrls.end(); 00283 ++it ) 00284 { 00285 str << *it << endl; 00286 } 00287 00288 if ( ! _pimpl->path.empty() ) 00289 str << "path="<< path() << endl; 00290 00291 if ( ! (_pimpl->mirrorlist_url.asString().empty()) ) 00292 str << "mirrorlist=" << _pimpl->mirrorlist_url << endl; 00293 00294 str << "type=" << type().asString() << endl; 00295 str << "enabled=" << (enabled() ? "1" : "0") << endl; 00296 str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl; 00297 str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl; 00298 if ( ! (gpgKeyUrl().asString().empty()) ) 00299 str << "gpgkey=" <<gpgKeyUrl() << endl; 00300 00301 return str; 00302 } 00303 00304 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj ) 00305 { 00306 return obj.dumpOn(str); 00307 } 00308 00310 } // namespace zypp
1.5.3