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 );
200 * Type of repository,
203 repo::RepoType type() const;
205 * This allows to adjust the \ref RepoType lazy, from \c NONE to
206 * some probed value, even for const objects.
208 * This is a NOOP if the current type is not \c NONE.
210 void setProbedType( const repo::RepoType &t ) const;
212 * set the repository type \see type
215 void setType( const repo::RepoType &t );
218 * \short Path where this repo metadata was read from
220 * \note could be an empty pathname for repo
221 * infos created in memory.
223 Pathname metadataPath() const;
225 * \short set the path where the local metadata is stored
227 * The path to the metadata of this repository
228 * was defined, or empty if nowhere.
230 * \param path directory path
232 void setMetadataPath( const Pathname &path );
235 * \short Path where this repo packages are cached
237 Pathname packagesPath() const;
239 * \short set the path where the local packages are stored
241 * \param path directory path
243 void setPackagesPath( const Pathname &path );
246 * \short Whether to check or not this repository with gpg
248 * \note This is a just a hint to the application and can
252 bool gpgCheck() const;
254 * \short Whether to check or not this repository with gpg
256 * \param check true (check) or false (dont'check)
258 * \note This is a just a hint to the application and can
262 void setGpgCheck( bool check );
265 * \short Key to use for gpg checking of this repository
267 * \param url Url to the key in ASCII armored format
269 * \note This is a just a hint to the application and can
273 Url gpgKeyUrl() const;
275 * The raw gpgKeyUrl (no variables replaced).
277 Url rawGpgKeyUrl() const;
279 * \short Key to use for gpg checking of this repository
281 * \param url Url to the key in ASCII armored format
283 * \note This is a just a hint to the application and can
287 void setGpgKeyUrl( const Url &gpgkey );
290 * \short Whether packages downloaded from this repository will be kept in local cache
292 bool keepPackages() const;
294 * \short Set if packaqes downloaded from this repository will be kept in local cache
296 * If the setting is true, all downloaded packages from this repository will be
297 * copied to the local raw cache.
299 * \param keep true (keep the downloaded packages) or false (delete them after installation)
302 void setKeepPackages( bool keep );
305 * Gets name of the service to which this repository belongs or empty string
306 * if it has been added manually.
308 std::string service() const;
310 * sets service which added this repository
312 void setService( const std::string& name );
315 * Distribution for which is this repository meant.
317 std::string targetDistribution() const;
319 * Sets the distribution for which is this repository meant. This is
320 * an in-memory value only, does not get written to the .repo file upon
323 void setTargetDistribution(const std::string & targetDistribution);
325 /** Add content keywords */
326 void addContent( const std::string & keyword_r );
327 /** \overload add keywords from container */
328 template <class _Iterator>
329 void addContentFrom( _Iterator begin_r, _Iterator end_r )
330 { for_( it, begin_r, end_r ) addContent( *it ); }
332 template <class _Container>
333 void addContentFrom( const _Container & container_r )
334 { addContentFrom( container_r.begin(), container_r.end() ); }
336 /** Check for content keywords.
337 * Checking for an empty string returns whether content kewords are
338 * known at all. They may be missing due to missing metadata in disabled
341 bool hasContent( const std::string & keyword_r = std::string() ) const;
342 /** \overload check for \b all keywords being present */
343 template <class _Iterator>
344 bool hasContentAll( _Iterator begin_r, _Iterator end_r ) const
345 { for_( it, begin_r, end_r ) if ( ! hasContent( *it ) ) return false; return true; }
347 template <class _Container>
348 bool hasContentAll( const _Container & container_r ) const
349 { return hasContentAll( container_r.begin(), container_r.end() ); }
350 /** \overload check for \b any keyword being present */
351 template <class _Iterator>
352 bool hasContentAny( _Iterator begin_r, _Iterator end_r ) const
353 { for_( it, begin_r, end_r ) if ( hasContent( *it ) ) return true; return false; }
355 template <class _Container>
356 bool hasContentAny( const _Container & container_r ) const
357 { return hasContentAny( container_r.begin(), container_r.end() ); }
360 /** \name Repository license
363 /** Whether there is a license associated with the repo. */
364 bool hasLicense() const;
366 /** Whether the repo license has to be accepted, e.g. there is no
367 * no acceptance needed for openSUSE.
369 bool needToAcceptLicense() const;
371 /** Return the best license for the current (or a specified) locale. */
372 std::string getLicense( const Locale & lang_r = Locale() ) const;
373 std::string getLicense( const Locale & lang_r = Locale() ); // LEGACY API
375 /** Return the locales the license is available for.
376 * \ref Locale::noCode is included in case of \c license.txt which does
377 * not specify a specific locale.
379 LocaleSet getLicenseLocales() const;
382 /** \name Repository global unique id
391 * Write a human-readable representation of this RepoInfo object
392 * into the \a str stream. Useful for logging.
394 virtual std::ostream & dumpOn( std::ostream & str ) const;
397 * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
398 * Raw values, no variable replacement.
400 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
403 * Write an XML representation of this RepoInfo object.
404 * Repo variables replaced.
407 * \param content this argument is ignored (used in other classed derived
410 virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
414 /** Pointer to implementation */
415 RWCOW_pointer<Impl> _pimpl;
417 ///////////////////////////////////////////////////////////////////
419 /** \relates RepoInfo */
420 typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
421 /** \relates RepoInfo */
422 typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
423 /** \relates RepoInfo */
424 typedef std::list<RepoInfo> RepoInfoList;
426 /** \relates RepoInfo Stream output */
427 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
430 /////////////////////////////////////////////////////////////////
432 ///////////////////////////////////////////////////////////////////
433 #endif // ZYPP2_REPOSITORYINFO_H