Imported Upstream version 15.1.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        * Like \ref setMirrorListUrl but expect metalink format.
200        */
201       void setMetalinkUrl( const Url &url );
202
203       /**
204        * Type of repository,
205        *
206        */
207       repo::RepoType type() const;
208       /**
209        * This allows to adjust the \ref  RepoType lazy, from \c NONE to
210        * some probed value, even for const objects.
211        *
212        * This is a NOOP if the current type is not \c NONE.
213        */
214       void setProbedType( const repo::RepoType &t ) const;
215       /**
216        * set the repository type \see type
217        * \param t
218        */
219       void setType( const repo::RepoType &t );
220
221       /**
222        * \short Path where this repo metadata was read from
223        *
224        * \note could be an empty pathname for repo
225        * infos created in memory.
226        */
227       Pathname metadataPath() const;
228       /**
229        * \short set the path where the local metadata is stored
230        *
231        * The path to the metadata of this repository
232        * was defined, or empty if nowhere.
233        *
234        * \param path directory path
235        */
236       void setMetadataPath( const Pathname &path );
237
238       /**
239        * \short Path where this repo packages are cached
240        */
241       Pathname packagesPath() const;
242       /**
243        * \short set the path where the local packages are stored
244        *
245        * \param path directory path
246        */
247       void setPackagesPath( const Pathname &path );
248
249       /**
250        * \short Whether to check or not this repository with gpg
251        *
252        * \note This is a just a hint to the application and can
253        * be ignored.
254        *
255        */
256       bool gpgCheck() const;
257       /**
258        * \short Whether to check or not this repository with gpg
259        *
260        * \param check true (check) or false (dont'check)
261        *
262        * \note This is a just a hint to the application and can
263        * be ignored.
264        *
265        */
266       void setGpgCheck( bool check );
267
268       /**
269        * \short Key to use for gpg checking of this repository
270        *
271        * \param url Url to the key in ASCII armored format
272        *
273        * \note This is a just a hint to the application and can
274        * be ignored.
275        *
276        */
277       Url gpgKeyUrl() const;
278       /**
279        * The raw gpgKeyUrl (no variables replaced).
280        */
281       Url rawGpgKeyUrl() const;
282       /**
283        * \short Key to use for gpg checking of this repository
284        *
285        * \param url Url to the key in ASCII armored format
286        *
287        * \note This is a just a hint to the application and can
288        * be ignored.
289        *
290        */
291       void setGpgKeyUrl( const Url &gpgkey );
292
293       /**
294        * \short Whether packages downloaded from this repository will be kept in local cache
295        */
296       bool keepPackages() const;
297       /**
298        * \short Set if packaqes downloaded from this repository will be kept in local cache
299        *
300        * If the setting is true, all downloaded packages from this repository will be
301        * copied to the local raw cache.
302        *
303        * \param keep true (keep the downloaded packages) or false (delete them after installation)
304        *
305        */
306       void setKeepPackages( bool keep );
307
308       /**
309        * Gets name of the service to which this repository belongs or empty string
310        * if it has been added manually.
311        */
312       std::string service() const;
313       /**
314        * sets service which added this repository
315        */
316       void setService( const std::string& name );
317
318       /**
319        * Distribution for which is this repository meant.
320        */
321       std::string targetDistribution() const;
322       /**
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
325        * saving.
326        */
327       void setTargetDistribution(const std::string & targetDistribution);
328
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 ); }
335       /** \overload  */
336       template <class _Container>
337       void addContentFrom( const _Container & container_r )
338       { addContentFrom( container_r.begin(), container_r.end() ); }
339
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
343        * repos.
344        */
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; }
350       /** \overload  */
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; }
358       /** \overload  */
359       template <class _Container>
360       bool hasContentAny( const _Container & container_r ) const
361       { return hasContentAny( container_r.begin(), container_r.end() ); }
362
363     public:
364       /** \name Repository license
365       */
366       //@{
367       /** Whether there is a license associated with the repo. */
368       bool hasLicense() const;
369
370       /** Whether the repo license has to be accepted, e.g. there is no
371        * no acceptance needed for openSUSE.
372        */
373       bool needToAcceptLicense() const;
374
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
378
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.
382        */
383       LocaleSet getLicenseLocales() const;
384       //@}
385
386       /** \name Repository global unique id
387        *
388        *
389        */
390       //@{
391       //@}
392
393     public:
394       /**
395        * Write a human-readable representation of this RepoInfo object
396        * into the \a str stream. Useful for logging.
397        */
398       virtual std::ostream & dumpOn( std::ostream & str ) const;
399
400       /**
401        * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
402        * Raw values, no variable replacement.
403        */
404       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
405
406       /**
407        * Write an XML representation of this RepoInfo object.
408        * Repo variables replaced.
409        *
410        * \param str
411        * \param content this argument is ignored (used in other classed derived
412        *                from RepoInfoBase.
413        */
414       virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
415
416       class Impl;
417     private:
418       /** Pointer to implementation */
419       RWCOW_pointer<Impl> _pimpl;
420   };
421   ///////////////////////////////////////////////////////////////////
422
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;
429
430   /** \relates RepoInfo Stream output */
431   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
432
433
434   /////////////////////////////////////////////////////////////////
435 } // namespace zypp
436 ///////////////////////////////////////////////////////////////////
437 #endif // ZYPP2_REPOSITORYINFO_H