- RepoInfoBase added for common SericeInfo and RepoInfo stuff
[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/repo/RepoType.h"
23 #include "zypp/repo/RepoVariables.h"
24
25 #include "zypp/repo/RepoInfoBase.h"
26
27 ///////////////////////////////////////////////////////////////////
28 namespace zypp
29 { /////////////////////////////////////////////////////////////////
30
31   ///////////////////////////////////////////////////////////////////
32   //
33   //    CLASS NAME : RepoInfo
34   //
35   /**
36    * \short What is known about a repository
37    *
38    * The class RepoInfo represents everything that
39    * is known about a software repository.
40    *
41    * It can be used to store information about known
42    * sources.
43    *
44    * This class tries to be compatible with the
45    * concept of a .repo file used by YUM and
46    * also available in the openSUSE build service.
47    * See <tt>man yum.conf</tt>.
48    *
49    * Example file
50    *
51    * \code
52    * [ruby]
53    * name=Ruby repository (openSUSE_10.2)
54    * type=rpm-md
55    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
56    * gpgcheck=1
57    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
58    * enabled=1
59    * priority=10
60    * \endcode
61    *
62    * \note A RepoInfo is a hint about how
63    * to create a Repository.
64    */
65   class RepoInfo : public repo::RepoInfoBase
66   {
67     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
68
69     public:
70     static unsigned defaultPrioity();
71
72     public:
73     RepoInfo();
74     ~RepoInfo();
75
76     /**
77      * Repository priority for solver.
78      * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
79      */
80     unsigned priority() const;
81     /**
82      * The default priority (\c 99).
83      */
84     static unsigned defaultPriority();
85     /**
86      * Set repository priority for solver.
87      * A \c newval_r of \c 0 sets the default priority.
88      * \see \ref priority.
89      */
90     RepoInfo & setPriority( unsigned newval_r );
91
92     /**
93      * A Url under which the metadata are located, or a set of mirrors.
94      *
95      * This can't be empty in order the repository to be valid
96      * unless the download of the mirror list succeeds and it
97      * contains a valid url.
98      *
99      * \deprecated IMO superfluous as we provide begin/end iterator.
100      */
101     ZYPP_DEPRECATED std::set<Url> baseUrls() const;
102
103     /**
104      * \short Repository path
105      *
106      * Pathname relative to the base Url where the product/repository
107      * is located
108      *
109      * For medias containing more than one product, or repositories not
110      * located at the root of the media it is important to
111      * know the path of the media root relative to the product directory
112      * so a media verifier can be set for that media.
113      *
114      * It is not mandatory, and the default is /
115      *
116      * \note As a repository can have multiple Urls, the path is unique and
117      * the same for all Urls, so it is assumed all the Urls have the
118      * same media layout.
119      *
120      */
121     Pathname path() const;
122
123     /**
124      * Url of a file which contains a list of Urls
125      * If empty, the base url will be used.
126      */
127     Url mirrorListUrl() const;
128
129     typedef std::set<Url> url_set;
130     //typedef url_set::const_iterator urls_const_iterator;
131     typedef url_set::size_type      urls_size_type;
132     typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
133
134     /**
135      * iterator that points at begin of repository urls
136      */
137     urls_const_iterator baseUrlsBegin() const;
138
139     /**
140      * iterator that points at end of repository urls
141      */
142     urls_const_iterator baseUrlsEnd() const;
143
144     /**
145      * number of repository urls
146      */
147     urls_size_type baseUrlsSize() const;
148
149      /**
150       * whether repository urls are available
151       */
152     bool baseUrlsEmpty() const;
153
154     /**
155      * Type of repository,
156      *
157      */
158     repo::RepoType type() const;
159
160     /**
161      * \short Path where this repo metadata was read from
162      *
163      * \note could be an empty pathname for repo
164      * infos created in memory.
165      */
166      Pathname metadataPath() const;
167
168     /**
169      * \short Path where this repo packages are cached
170      */
171      Pathname packagesPath() const;
172
173     /**
174      * \short Whether to check or not this repository with gpg
175      *
176      * \note This is a just a hint to the application and can
177      * be ignored.
178      *
179      */
180     bool gpgCheck() const;
181
182     /**
183      * \short Key to use for gpg checking of this repository
184      *
185      * \param url Url to the key in ASCII armored format
186      *
187      * \note This is a just a hint to the application and can
188      * be ignored.
189      *
190      */
191      Url gpgKeyUrl() const;
192
193     /**
194      * \short Whether to keep the packages downloaded from this repository will be kept in local cache
195      */
196     bool keepPackages() const;
197
198     /**
199      * Gets name of the service to which this repository belongs or empty string
200      * if it has been added manually.
201      */
202     std::string service() const;
203
204     public:
205     /**
206      * Add a base url. \see baseUrls
207      * \param url The base url for the repository.
208      * \note can change keepPackages,so change it after this call
209      *
210      * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
211      * by addBaseUrl().
212      */
213     RepoInfo & addBaseUrl( const Url &url );
214
215     /**
216      * Clears current base URL list and adds \a url.
217      * \note can change keepPackages,so change it after this call
218      */
219     RepoInfo & setBaseUrl( const Url &url );
220
221     /**
222      * set the product path. \see path()
223      * \param path the path to the product
224      */
225     RepoInfo & setPath( const Pathname &path );
226
227     /**
228      * Set mirror list url. \see mirrorListUrl
229      * \param url The base url for the list
230      */
231     RepoInfo & setMirrorListUrl( const Url &url );
232
233     /**
234      * set the repository type \see type
235      * \param t
236      */
237     RepoInfo & setType( const repo::RepoType &t );
238
239     /**
240      * This allows to adjust the \ref  RepoType lazy, from \c NONE to
241      * some probed value, even for const objects.
242      *
243      * This is a NOOP if the current type is not \c NONE.
244      */
245     void setProbedType( const repo::RepoType &t ) const;
246
247     /**
248      * \short set the path where the local metadata is stored
249      *
250      * The path to the metadata of this repository
251      * was defined, or empty if nowhere.
252      *
253      * \param path directory path
254      */
255     RepoInfo & setMetadataPath( const Pathname &path );
256
257     /**
258      * \short set the path where the local packages are stored
259      *
260      * \param path directory path
261      */
262     RepoInfo & setPackagesPath( const Pathname &path );
263
264     /**
265      * \short Whether to check or not this repository with gpg
266      *
267      * \param check true (check) or false (dont'check)
268      *
269      * \note This is a just a hint to the application and can
270      * be ignored.
271      *
272      */
273     RepoInfo & setGpgCheck( bool check );
274
275     /**
276      * \short Key to use for gpg checking of this repository
277      *
278      * \param url Url to the key in ASCII armored format
279      *
280      * \note This is a just a hint to the application and can
281      * be ignored.
282      *
283      */
284     RepoInfo & setGpgKeyUrl( const Url &gpgkey );
285
286     /**
287      * \short Set if the packaqes downloaded from this repository will be kept in local cache
288      *
289      * If the setting is true, all downloaded packages from this repository will be
290      * copied to the local raw cache.
291      *
292      * \param keep true (keep the downloaded packages) or false (delete them after installation)
293      *
294      */
295     RepoInfo & setKeepPackages( bool keep );
296
297     /**
298      * sets service which added this repository
299      */
300     RepoInfo & setService( const std::string& name );
301
302     /**
303      * Write a human-readable representation of this RepoInfo object
304      * into the \a str stream. Useful for logging.
305      */
306     virtual std::ostream & dumpOn( std::ostream & str ) const;
307
308     /**
309      * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
310      */
311     virtual std::ostream & dumpRepoOn( std::ostream & str ) const;
312
313     class Impl;
314   private:
315     /** Pointer to implementation */
316     RWCOW_pointer<Impl> _pimpl;
317   };
318   ///////////////////////////////////////////////////////////////////
319
320   /** \relates RepoInfo Stream output */
321   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
322
323   inline bool operator<( const RepoInfo& lhs, const RepoInfo & rhs )
324   { return lhs.alias() < rhs.alias(); }
325
326   typedef std::list<RepoInfo> RepoInfoList;
327
328   /////////////////////////////////////////////////////////////////
329 } // namespace zypp
330 ///////////////////////////////////////////////////////////////////
331 #endif // ZYPP2_REPOSITORYINFO_H