Imported Upstream version 15.0.0
[platform/upstream/libzypp.git] / zypp / RepoInfo.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.h
10  *
11 */
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
14
15 #include <list>
16 #include <set>
17
18 #include "zypp/base/Iterator.h"
19 #include "zypp/APIConfig.h"
20
21 #include "zypp/Url.h"
22 #include "zypp/Locale.h"
23 #include "zypp/repo/RepoType.h"
24 #include "zypp/repo/RepoVariables.h"
25
26 #include "zypp/repo/RepoInfoBase.h"
27
28 ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : RepoInfo
35   //
36   /**
37    * \short What is known about a repository
38    *
39    * The class RepoInfo represents everything that
40    * is known about a software repository.
41    *
42    * It can be used to store information about known
43    * sources.
44    *
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>.
49    *
50    * Example file
51    *
52    * \code
53    * [ruby]
54    * name=Ruby repository (openSUSE_10.2)
55    * type=rpm-md
56    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
57    *         http://some.opensuse.mirror/ruby/openSUSE_10.2/
58    * gpgcheck=1
59    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
60    * enabled=1
61    * priority=10
62    * \endcode
63    *
64    * \note A RepoInfo is a hint about how
65    * to create a Repository.
66    *
67    * \note Name, baseUrls and mirrorUrl are subject to repo variable replacement
68    * (\see \ref RepoVariablesStringReplacer).
69    */
70   class RepoInfo : public repo::RepoInfoBase
71   {
72     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
73
74     public:
75       RepoInfo();
76       virtual ~RepoInfo();
77
78       /** Represents no Repository (one with an empty alias). */
79       static const RepoInfo noRepo;
80
81     public:
82       /**
83        * The default priority (\c 99).
84        */
85       static unsigned defaultPriority();
86       /**
87        * Repository priority for solver.
88        * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
89        */
90       unsigned priority() const;
91       /**
92        * Set repository priority for solver.
93        * A \c newval_r of \c 0 sets the default priority.
94        * \see \ref priority.
95        */
96       void setPriority( unsigned newval_r );
97
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;
101       /**
102        * whether repository urls are available
103        */
104       bool baseUrlsEmpty() const;
105       /**
106        * Whether there are manualy configured repository urls.
107        * If \c false, a mirrorlist might be used.
108        */
109       bool baseUrlSet() const;
110       /**
111        * number of repository urls
112        */
113       urls_size_type baseUrlsSize() const;
114       /**
115        * iterator that points at begin of repository urls
116        */
117       urls_const_iterator baseUrlsBegin() const;
118       /**
119        * iterator that points at end of repository urls
120        */
121       urls_const_iterator baseUrlsEnd() const;
122
123       /**
124        * Pars pro toto: The first repository url
125        */
126       Url url() const
127       { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
128       /**
129        * Pars pro toto: The first repository raw url (no variables replaced)
130        */
131       Url rawUrl() const;
132
133       /**
134        * The complete set of repository urls
135        *
136        * These are either the configured baseurls, or if empty, the downloaded
137        * mirror list (\see \ref mirrorListUrl)
138        */
139       url_set baseUrls() const;
140       /**
141        * The complete set of raw repository urls (no variables replaced)
142        */
143       url_set rawBaseUrls() const;
144
145       /**
146        * Add a base url. \see baseUrls
147        * \param url The base url for the repository.
148        *
149        * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
150        * by addBaseUrl().
151        */
152       void addBaseUrl( const Url &url );
153       /**
154        * Clears current base URL list and adds \a url.
155        */
156       void setBaseUrl( const Url &url );
157
158       /**
159        * \short Repository path
160        *
161        * Pathname relative to the base Url where the product/repository
162        * is located
163        *
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>.
170        *
171        * It is not mandatory, and the default is \c /.
172        *
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
175        * same media layout.
176        *
177        */
178       Pathname path() const;
179       /**
180        * set the product path. \see path()
181        * \param path the path to the product
182        */
183       void setPath( const Pathname &path );
184
185       /**
186        * Url of a file which contains a list of repository urls
187        */
188       Url mirrorListUrl() const;
189       /**
190        * The raw mirrorListUrl (no variables replaced).
191        */
192       Url rawMirrorListUrl() const;
193       /**
194        * Set mirror list url. \see mirrorListUrl
195        * \param url The base url for the list
196        */
197       void setMirrorListUrl( const Url &url );
198
199       /**
200        * Type of repository,
201        *
202        */
203       repo::RepoType type() const;
204       /**
205        * This allows to adjust the \ref  RepoType lazy, from \c NONE to
206        * some probed value, even for const objects.
207        *
208        * This is a NOOP if the current type is not \c NONE.
209        */
210       void setProbedType( const repo::RepoType &t ) const;
211       /**
212        * set the repository type \see type
213        * \param t
214        */
215       void setType( const repo::RepoType &t );
216
217       /**
218        * \short Path where this repo metadata was read from
219        *
220        * \note could be an empty pathname for repo
221        * infos created in memory.
222        */
223       Pathname metadataPath() const;
224       /**
225        * \short set the path where the local metadata is stored
226        *
227        * The path to the metadata of this repository
228        * was defined, or empty if nowhere.
229        *
230        * \param path directory path
231        */
232       void setMetadataPath( const Pathname &path );
233
234       /**
235        * \short Path where this repo packages are cached
236        */
237       Pathname packagesPath() const;
238       /**
239        * \short set the path where the local packages are stored
240        *
241        * \param path directory path
242        */
243       void setPackagesPath( const Pathname &path );
244
245       /**
246        * \short Whether to check or not this repository with gpg
247        *
248        * \note This is a just a hint to the application and can
249        * be ignored.
250        *
251        */
252       bool gpgCheck() const;
253       /**
254        * \short Whether to check or not this repository with gpg
255        *
256        * \param check true (check) or false (dont'check)
257        *
258        * \note This is a just a hint to the application and can
259        * be ignored.
260        *
261        */
262       void setGpgCheck( bool check );
263
264       /**
265        * \short Key to use for gpg checking of this repository
266        *
267        * \param url Url to the key in ASCII armored format
268        *
269        * \note This is a just a hint to the application and can
270        * be ignored.
271        *
272        */
273       Url gpgKeyUrl() const;
274       /**
275        * The raw gpgKeyUrl (no variables replaced).
276        */
277       Url rawGpgKeyUrl() const;
278       /**
279        * \short Key to use for gpg checking of this repository
280        *
281        * \param url Url to the key in ASCII armored format
282        *
283        * \note This is a just a hint to the application and can
284        * be ignored.
285        *
286        */
287       void setGpgKeyUrl( const Url &gpgkey );
288
289       /**
290        * \short Whether packages downloaded from this repository will be kept in local cache
291        */
292       bool keepPackages() const;
293       /**
294        * \short Set if packaqes downloaded from this repository will be kept in local cache
295        *
296        * If the setting is true, all downloaded packages from this repository will be
297        * copied to the local raw cache.
298        *
299        * \param keep true (keep the downloaded packages) or false (delete them after installation)
300        *
301        */
302       void setKeepPackages( bool keep );
303
304       /**
305        * Gets name of the service to which this repository belongs or empty string
306        * if it has been added manually.
307        */
308       std::string service() const;
309       /**
310        * sets service which added this repository
311        */
312       void setService( const std::string& name );
313
314       /**
315        * Distribution for which is this repository meant.
316        */
317       std::string targetDistribution() const;
318       /**
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
321        * saving.
322        */
323       void setTargetDistribution(const std::string & targetDistribution);
324
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 ); }
331       /** \overload  */
332       template <class _Container>
333       void addContentFrom( const _Container & container_r )
334       { addContentFrom( container_r.begin(), container_r.end() ); }
335
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
339        * repos.
340        */
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; }
346       /** \overload  */
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; }
354       /** \overload  */
355       template <class _Container>
356       bool hasContentAny( const _Container & container_r ) const
357       { return hasContentAny( container_r.begin(), container_r.end() ); }
358
359     public:
360       /** \name Repository license
361       */
362       //@{
363       /** Whether there is a license associated with the repo. */
364       bool hasLicense() const;
365
366       /** Whether the repo license has to be accepted, e.g. there is no
367        * no acceptance needed for openSUSE.
368        */
369       bool needToAcceptLicense() const;
370
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
374
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.
378        */
379       LocaleSet getLicenseLocales() const;
380       //@}
381
382       /** \name Repository global unique id
383        *
384        *
385        */
386       //@{
387       //@}
388
389     public:
390       /**
391        * Write a human-readable representation of this RepoInfo object
392        * into the \a str stream. Useful for logging.
393        */
394       virtual std::ostream & dumpOn( std::ostream & str ) const;
395
396       /**
397        * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
398        * Raw values, no variable replacement.
399        */
400       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
401
402       /**
403        * Write an XML representation of this RepoInfo object.
404        * Repo variables replaced.
405        *
406        * \param str
407        * \param content this argument is ignored (used in other classed derived
408        *                from RepoInfoBase.
409        */
410       virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
411
412       class Impl;
413     private:
414       /** Pointer to implementation */
415       RWCOW_pointer<Impl> _pimpl;
416   };
417   ///////////////////////////////////////////////////////////////////
418
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;
425
426   /** \relates RepoInfo Stream output */
427   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
428
429
430   /////////////////////////////////////////////////////////////////
431 } // namespace zypp
432 ///////////////////////////////////////////////////////////////////
433 #endif // ZYPP2_REPOSITORYINFO_H