1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.h
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
18 #include "zypp/base/Iterator.h"
19 #include "zypp/APIConfig.h"
22 #include "zypp/Locale.h"
23 #include "zypp/repo/RepoType.h"
24 #include "zypp/repo/RepoVariables.h"
26 #include "zypp/repo/RepoInfoBase.h"
28 ///////////////////////////////////////////////////////////////////
30 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 // CLASS NAME : RepoInfo
37 * \short What is known about a repository
39 * The class RepoInfo represents everything that
40 * is known about a software repository.
42 * It can be used to store information about known
45 * This class tries to be compatible with the
46 * concept of a .repo file used by YUM and
47 * also available in the openSUSE build service.
48 * See <tt>man yum.conf</tt>.
54 * name=Ruby repository (openSUSE_10.2)
56 * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
57 * http://some.opensuse.mirror/ruby/openSUSE_10.2/
59 * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
64 * \note A RepoInfo is a hint about how
65 * to create a Repository.
67 * \note Name, baseUrls and mirrorUrl are subject to repo variable replacement
68 * (\see \ref RepoVariablesStringReplacer).
70 class RepoInfo : public repo::RepoInfoBase
72 friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
78 /** Represents no Repository (one with an empty alias). */
79 static const RepoInfo noRepo;
83 * The default priority (\c 99).
85 static unsigned defaultPriority();
87 * Repository priority for solver.
88 * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
90 unsigned priority() const;
92 * Set repository priority for solver.
93 * A \c newval_r of \c 0 sets the default priority.
96 void setPriority( unsigned newval_r );
98 typedef std::list<Url> url_set;
99 typedef url_set::size_type urls_size_type;
100 typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
102 * whether repository urls are available
104 bool baseUrlsEmpty() const;
106 * Whether there are manualy configured repository urls.
107 * If \c false, a mirrorlist might be used.
109 bool baseUrlSet() const;
111 * number of repository urls
113 urls_size_type baseUrlsSize() const;
115 * iterator that points at begin of repository urls
117 urls_const_iterator baseUrlsBegin() const;
119 * iterator that points at end of repository urls
121 urls_const_iterator baseUrlsEnd() const;
124 * Pars pro toto: The first repository url
127 { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
129 * Pars pro toto: The first repository raw url (no variables replaced)
134 * The complete set of repository urls
136 * These are either the configured baseurls, or if empty, the downloaded
137 * mirror list (\see \ref mirrorListUrl)
139 url_set baseUrls() const;
141 * The complete set of raw repository urls (no variables replaced)
143 url_set rawBaseUrls() const;
146 * Add a base url. \see baseUrls
147 * \param url The base url for the repository.
149 * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
152 void addBaseUrl( const Url &url );
154 * Clears current base URL list and adds \a url.
156 void setBaseUrl( const Url &url );
159 * \short Repository path
161 * Pathname relative to the base Url where the product/repository
164 * For media containing more than one product, or repositories not
165 * located at the root of the media it is important to know the path
166 * to the product directory relative to the media root. So a media
167 * verifier can be set for that media. You may also read it as
168 * <tt>baseUrl = url to mount</tt> and <tt>path = path on the
169 * mounted media</tt>.
171 * It is not mandatory, and the default is \c /.
173 * \note As a repository can have multiple Urls, the path is unique and
174 * the same for all Urls, so it is assumed all the Urls have the
178 Pathname path() const;
180 * set the product path. \see path()
181 * \param path the path to the product
183 void setPath( const Pathname &path );
186 * Url of a file which contains a list of repository urls
188 Url mirrorListUrl() const;
190 * The raw mirrorListUrl (no variables replaced).
192 Url rawMirrorListUrl() const;
194 * Set mirror list url. \see mirrorListUrl
195 * \param url The base url for the list
197 void setMirrorListUrl( const Url &url );
199 * Like \ref setMirrorListUrl but expect metalink format.
201 void setMetalinkUrl( const Url &url );
204 * Type of repository,
207 repo::RepoType type() const;
209 * This allows to adjust the \ref RepoType lazy, from \c NONE to
210 * some probed value, even for const objects.
212 * This is a NOOP if the current type is not \c NONE.
214 void setProbedType( const repo::RepoType &t ) const;
216 * set the repository type \see type
219 void setType( const repo::RepoType &t );
222 * \short Path where this repo metadata was read from
224 * \note could be an empty pathname for repo
225 * infos created in memory.
227 Pathname metadataPath() const;
229 * \short set the path where the local metadata is stored
231 * The path to the metadata of this repository
232 * was defined, or empty if nowhere.
234 * \param path directory path
236 void setMetadataPath( const Pathname &path );
239 * \short Path where this repo packages are cached
241 Pathname packagesPath() const;
243 * \short set the path where the local packages are stored
245 * \param path directory path
247 void setPackagesPath( const Pathname &path );
250 * \short Whether to check or not this repository with gpg
252 * \note This is a just a hint to the application and can
256 bool gpgCheck() const;
258 * \short Whether to check or not this repository with gpg
260 * \param check true (check) or false (dont'check)
262 * \note This is a just a hint to the application and can
266 void setGpgCheck( bool check );
269 * \short Key to use for gpg checking of this repository
271 * \param url Url to the key in ASCII armored format
273 * \note This is a just a hint to the application and can
277 Url gpgKeyUrl() const;
279 * The raw gpgKeyUrl (no variables replaced).
281 Url rawGpgKeyUrl() const;
283 * \short Key to use for gpg checking of this repository
285 * \param url Url to the key in ASCII armored format
287 * \note This is a just a hint to the application and can
291 void setGpgKeyUrl( const Url &gpgkey );
294 * \short Whether packages downloaded from this repository will be kept in local cache
296 bool keepPackages() const;
298 * \short Set if packaqes downloaded from this repository will be kept in local cache
300 * If the setting is true, all downloaded packages from this repository will be
301 * copied to the local raw cache.
303 * \param keep true (keep the downloaded packages) or false (delete them after installation)
306 void setKeepPackages( bool keep );
309 * Gets name of the service to which this repository belongs or empty string
310 * if it has been added manually.
312 std::string service() const;
314 * sets service which added this repository
316 void setService( const std::string& name );
319 * Distribution for which is this repository meant.
321 std::string targetDistribution() const;
323 * Sets the distribution for which is this repository meant. This is
324 * an in-memory value only, does not get written to the .repo file upon
327 void setTargetDistribution(const std::string & targetDistribution);
329 /** Add content keywords */
330 void addContent( const std::string & keyword_r );
331 /** \overload add keywords from container */
332 template <class _Iterator>
333 void addContentFrom( _Iterator begin_r, _Iterator end_r )
334 { for_( it, begin_r, end_r ) addContent( *it ); }
336 template <class _Container>
337 void addContentFrom( const _Container & container_r )
338 { addContentFrom( container_r.begin(), container_r.end() ); }
340 /** Check for content keywords.
341 * Checking for an empty string returns whether content kewords are
342 * known at all. They may be missing due to missing metadata in disabled
345 bool hasContent( const std::string & keyword_r = std::string() ) const;
346 /** \overload check for \b all keywords being present */
347 template <class _Iterator>
348 bool hasContentAll( _Iterator begin_r, _Iterator end_r ) const
349 { for_( it, begin_r, end_r ) if ( ! hasContent( *it ) ) return false; return true; }
351 template <class _Container>
352 bool hasContentAll( const _Container & container_r ) const
353 { return hasContentAll( container_r.begin(), container_r.end() ); }
354 /** \overload check for \b any keyword being present */
355 template <class _Iterator>
356 bool hasContentAny( _Iterator begin_r, _Iterator end_r ) const
357 { for_( it, begin_r, end_r ) if ( hasContent( *it ) ) return true; return false; }
359 template <class _Container>
360 bool hasContentAny( const _Container & container_r ) const
361 { return hasContentAny( container_r.begin(), container_r.end() ); }
364 /** \name Repository license
367 /** Whether there is a license associated with the repo. */
368 bool hasLicense() const;
370 /** Whether the repo license has to be accepted, e.g. there is no
371 * no acceptance needed for openSUSE.
373 bool needToAcceptLicense() const;
375 /** Return the best license for the current (or a specified) locale. */
376 std::string getLicense( const Locale & lang_r = Locale() ) const;
377 std::string getLicense( const Locale & lang_r = Locale() ); // LEGACY API
379 /** Return the locales the license is available for.
380 * \ref Locale::noCode is included in case of \c license.txt which does
381 * not specify a specific locale.
383 LocaleSet getLicenseLocales() const;
386 /** \name Repository global unique id
395 * Write a human-readable representation of this RepoInfo object
396 * into the \a str stream. Useful for logging.
398 virtual std::ostream & dumpOn( std::ostream & str ) const;
401 * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
402 * Raw values, no variable replacement.
404 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
407 * Write an XML representation of this RepoInfo object.
408 * Repo variables replaced.
411 * \param content this argument is ignored (used in other classed derived
414 virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
418 /** Pointer to implementation */
419 RWCOW_pointer<Impl> _pimpl;
421 ///////////////////////////////////////////////////////////////////
423 /** \relates RepoInfo */
424 typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
425 /** \relates RepoInfo */
426 typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
427 /** \relates RepoInfo */
428 typedef std::list<RepoInfo> RepoInfoList;
430 /** \relates RepoInfo Stream output */
431 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
434 /////////////////////////////////////////////////////////////////
436 ///////////////////////////////////////////////////////////////////
437 #endif // ZYPP2_REPOSITORYINFO_H