Deprecate MediaAccess::downloads (accidentally deleted)
[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/base/Deprecated.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    * gpgcheck=1
58    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
59    * enabled=1
60    * priority=10
61    * \endcode
62    *
63    * \note A RepoInfo is a hint about how
64    * to create a Repository.
65    */
66   class RepoInfo : public repo::RepoInfoBase
67   {
68     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
69
70     public:
71       RepoInfo();
72       virtual ~RepoInfo();
73
74       /** Represents no Repository (one with an empty alias). */
75       static const RepoInfo noRepo;
76
77     public:
78       /**
79        * The default priority (\c 99).
80        */
81       static unsigned defaultPriority();
82       /**
83        * Repository priority for solver.
84        * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
85        */
86       unsigned priority() const;
87       /**
88        * Set repository priority for solver.
89        * A \c newval_r of \c 0 sets the default priority.
90        * \see \ref priority.
91        */
92       void setPriority( unsigned newval_r );
93
94       typedef std::set<Url>           url_set;
95       typedef url_set::size_type      urls_size_type;
96       typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
97       /**
98        * whether repository urls are available
99        */
100       bool baseUrlsEmpty() const;
101       /**
102        * number of repository urls
103        */
104       urls_size_type baseUrlsSize() const;
105       /**
106        * iterator that points at begin of repository urls
107        */
108       urls_const_iterator baseUrlsBegin() const;
109       /**
110        * iterator that points at end of repository urls
111        */
112       urls_const_iterator baseUrlsEnd() const;
113       /**
114        * Pars pro toto: The first repository url
115        */
116       Url url() const
117       { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
118       /**
119        * A Url under which the metadata are located, or a set of mirrors.
120        *
121        * This can't be empty in order the repository to be valid
122        * unless the download of the mirror list succeeds and it
123        * contains a valid url.
124        *
125        * \deprecated IMO superfluous as we provide begin/end iterator.
126        */
127       std::set<Url> baseUrls() const;
128       /**
129        * Add a base url. \see baseUrls
130        * \param url The base url for the repository.
131        * \note can change keepPackages,so change it after this call
132        *
133        * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
134        * by addBaseUrl().
135        */
136       void addBaseUrl( const Url &url );
137       /**
138        * Clears current base URL list and adds \a url.
139        * \note can change keepPackages,so change it after this call
140        */
141       void setBaseUrl( const Url &url );
142
143       /**
144        * \short Repository path
145        *
146        * Pathname relative to the base Url where the product/repository
147        * is located
148        *
149        * For medias containing more than one product, or repositories not
150        * located at the root of the media it is important to
151        * know the path of the media root relative to the product directory
152        * so a media verifier can be set for that media.
153        *
154        * It is not mandatory, and the default is /
155        *
156        * \note As a repository can have multiple Urls, the path is unique and
157        * the same for all Urls, so it is assumed all the Urls have the
158        * same media layout.
159        *
160        */
161       Pathname path() const;
162       /**
163        * set the product path. \see path()
164        * \param path the path to the product
165        */
166       void setPath( const Pathname &path );
167
168       /**
169        * Url of a file which contains a list of Urls
170        * If empty, the base url will be used.
171        */
172       Url mirrorListUrl() const;
173       /**
174        * Set mirror list url. \see mirrorListUrl
175        * \param url The base url for the list
176        */
177       void setMirrorListUrl( const Url &url );
178
179       /**
180        * Type of repository,
181        *
182        */
183       repo::RepoType type() const;
184       /**
185        * This allows to adjust the \ref  RepoType lazy, from \c NONE to
186        * some probed value, even for const objects.
187        *
188        * This is a NOOP if the current type is not \c NONE.
189        */
190       void setProbedType( const repo::RepoType &t ) const;
191       /**
192        * set the repository type \see type
193        * \param t
194        */
195       void setType( const repo::RepoType &t );
196
197       /**
198        * \short Path where this repo metadata was read from
199        *
200        * \note could be an empty pathname for repo
201        * infos created in memory.
202        */
203       Pathname metadataPath() const;
204       /**
205        * \short set the path where the local metadata is stored
206        *
207        * The path to the metadata of this repository
208        * was defined, or empty if nowhere.
209        *
210        * \param path directory path
211        */
212       void setMetadataPath( const Pathname &path );
213
214       /**
215        * \short Path where this repo packages are cached
216        */
217       Pathname packagesPath() const;
218       /**
219        * \short set the path where the local packages are stored
220        *
221        * \param path directory path
222        */
223       void setPackagesPath( const Pathname &path );
224
225       /**
226        * \short Whether to check or not this repository with gpg
227        *
228        * \note This is a just a hint to the application and can
229        * be ignored.
230        *
231        */
232       bool gpgCheck() const;
233       /**
234        * \short Whether to check or not this repository with gpg
235        *
236        * \param check true (check) or false (dont'check)
237        *
238        * \note This is a just a hint to the application and can
239        * be ignored.
240        *
241        */
242       void setGpgCheck( bool check );
243
244       /**
245        * \short Key to use for gpg checking of this repository
246        *
247        * \param url Url to the key in ASCII armored format
248        *
249        * \note This is a just a hint to the application and can
250        * be ignored.
251        *
252        */
253       Url gpgKeyUrl() const;
254       /**
255        * \short Key to use for gpg checking of this repository
256        *
257        * \param url Url to the key in ASCII armored format
258        *
259        * \note This is a just a hint to the application and can
260        * be ignored.
261        *
262        */
263       void setGpgKeyUrl( const Url &gpgkey );
264
265       /**
266        * \short Whether to keep the packages downloaded from this repository will be kept in local cache
267        */
268       bool keepPackages() const;
269       /**
270        * \short Set if the packaqes downloaded from this repository will be kept in local cache
271        *
272        * If the setting is true, all downloaded packages from this repository will be
273        * copied to the local raw cache.
274        *
275        * \param keep true (keep the downloaded packages) or false (delete them after installation)
276        *
277        */
278       void setKeepPackages( bool keep );
279
280       /**
281        * Gets name of the service to which this repository belongs or empty string
282        * if it has been added manually.
283        */
284       std::string service() const;
285       /**
286        * sets service which added this repository
287        */
288       void setService( const std::string& name );
289
290       /**
291        * Distribution for which is this repository meant.
292        */
293       std::string targetDistribution() const;
294       /**
295        * Sets the distribution for which is this repository meant. This is
296        * an in-memory value only, does not get written to the .repo file upon
297        * saving.
298        */
299       void setTargetDistribution(const std::string & targetDistribution);
300
301     public:
302       /** \name Repository license
303       */
304       //@{
305       /** Whether there is a license associated with the repo. */
306       bool hasLicense() const;
307
308       /** Return the best license for the current (or a specified) locale. */
309       std::string getLicense( const Locale & lang_r = Locale() );
310
311       /** Return the locales the license is available for.
312        * \ref Locale::noCode is included in case of \c license.txt which does
313        * not specify a specific locale.
314       */
315       LocaleSet getLicenseLocales() const;
316       //@}
317     public:
318       /**
319        * Write a human-readable representation of this RepoInfo object
320        * into the \a str stream. Useful for logging.
321        */
322       virtual std::ostream & dumpOn( std::ostream & str ) const;
323
324       /**
325        * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
326        */
327       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
328
329       /**
330        * Write an XML representation of this RepoInfo object.
331        */
332       virtual std::ostream & dumpAsXMLOn(std::ostream & str) const;
333
334       /**
335        * Write an XML representation of this RepoInfo object.
336        *
337        * \param str
338        * \param content this argument is ignored (used in other classed derived
339        *                from RepoInfoBase.
340        */
341       virtual std::ostream & dumpAsXMLOn( std::ostream & str, const std::string & content ) const;
342
343       class Impl;
344     private:
345       /** Pointer to implementation */
346       RWCOW_pointer<Impl> _pimpl;
347   };
348   ///////////////////////////////////////////////////////////////////
349
350   /** \relates RepoInfo */
351   typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
352   /** \relates RepoInfo */
353   typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
354   /** \relates RepoInfo */
355   typedef std::list<RepoInfo> RepoInfoList;
356
357   /** \relates RepoInfo Stream output */
358   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
359
360
361   /////////////////////////////////////////////////////////////////
362 } // namespace zypp
363 ///////////////////////////////////////////////////////////////////
364 #endif // ZYPP2_REPOSITORYINFO_H