arch and basearch working
[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 <iosfwd>
16 #include <list>
17 #include <set>
18 #include "zypp/base/PtrTypes.h"
19 #include "zypp/base/Iterator.h"
20 #include "zypp/base/Deprecated.h"
21
22 #include "zypp/Pathname.h"
23 #include "zypp/Url.h"
24 #include "zypp/repo/RepoType.h"
25 #include "zypp/repo/RepoVariables.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    * \endcode
60    *
61    * \note A RepoInfo is a hint about how
62    * to create a Repository.
63    */
64   class RepoInfo
65   {
66     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
67
68     public:
69     RepoInfo();
70     ~RepoInfo();
71
72     typedef unsigned long NumericId;
73
74     /**
75      * unique identifier for this source. If not specified
76      * It should be generated from the base url.
77      *
78      * Normally, in a .repo file the section name is used
79      * ( [somerepo] )
80      */
81     std::string alias() const;
82
83     /**
84      * A Url under which the metadata are located, or a set of mirrors.
85      *
86      * This can't be empty in order the repository to be valid
87      * unless the download of the mirror list succeeds and it
88      * contains a valid url.
89      *
90      * \deprecated IMO superfluous as we provide begin/end iterator.
91      */
92     ZYPP_DEPRECATED std::set<Url> baseUrls() const;
93
94     /**
95      * \short Repository path
96      *
97      * Pathname relative to the base Url where the product/repository
98      * is located
99      *
100      * For medias containing more than one product, or repositories not
101      * located at the root of the media it is important to
102      * know the path of the media root relative to the product directory
103      * so a media verifier can be set for that media.
104      *
105      * It is not mandatory, and the default is /
106      *
107      * \note As a repository can have multiple Urls, the path is unique and
108      * the same for all Urls, so it is assumed all the Urls have the
109      * same media layout.
110      *
111      */
112     Pathname path() const;
113
114     /**
115      * Url of a file which contains a list of Urls
116      * If empty, the base url will be used.
117      */
118     Url mirrorListUrl() const;
119     
120     typedef std::set<Url> url_set;
121     //typedef url_set::const_iterator urls_const_iterator;
122     typedef url_set::size_type      urls_size_type;
123     typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
124     
125     /**
126      * iterator that points at begin of repository urls
127      */
128     urls_const_iterator baseUrlsBegin() const;
129
130     /**
131      * iterator that points at end of repository urls
132      */
133     urls_const_iterator baseUrlsEnd() const;
134
135     /**
136      * number of repository urls
137      */
138     urls_size_type baseUrlsSize() const;
139
140      /**
141       * whether repository urls are available
142       */
143     bool baseUrlsEmpty() const;
144
145    /**
146      * If enabled is false, then this repository must be ignored as if does
147      * not exists, except when checking for duplicate alias.
148      */
149     bool enabled() const;
150
151     /**
152      * If true, the repostory must be refreshed before creating resolvables
153      * from it
154      */
155     bool autorefresh() const;
156
157     /**
158      * Type of repository,
159      *
160      */
161     repo::RepoType type() const;
162
163     /**
164      * \short Repository short label
165      *
166      * Short label or description of the repository, to be used on
167      * the user interface.
168      * ie: "SUSE Linux 10.2 updates"
169      */
170     std::string name() const;
171
172     /**
173      * \short File where this repo was read from
174      *
175      * \note could be an empty pathname for repo
176      * infos created in memory.
177      */
178      Pathname filepath() const;
179
180      /**
181      * \short Path where this repo metadata was read from
182      *
183      * \note could be an empty pathname for repo
184      * infos created in memory.
185      */
186      Pathname metadataPath() const;
187
188      /**
189      * \short Whether to check or not this repository with gpg
190      *
191      * \note This is a just a hint to the application and can
192      * be ignored.
193      *
194      */
195     bool gpgCheck() const;
196
197     /**
198      * \short Key to use for gpg checking of this repository
199      *
200      * \param url Url to the key in ASCII armored format
201      *
202      * \note This is a just a hint to the application and can
203      * be ignored.
204      *
205      */
206      Url gpgKeyUrl() const;
207
208     /**
209      * Add a base url. \see baseUrls
210      * \param url The base url for the repository.
211      *
212      * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
213      * by addBaseUrl().
214      */
215     RepoInfo & addBaseUrl( const Url &url );
216
217     /**
218      * Clears current base URL list and adds \a url.
219      */
220     RepoInfo & setBaseUrl( const Url &url );
221
222     /**
223      * set the product path. \see path()
224      * \param path the path to the product
225      */
226     RepoInfo & setPath( const Pathname &path );
227
228     /**
229      * Set mirror list url. \see mirrorListUrl
230      * \param url The base url for the list
231      */
232     RepoInfo & setMirrorListUrl( const Url &url );
233
234     /**
235      * enable or disable the repository \see enabled
236      * \param enabled
237      */
238     RepoInfo & setEnabled( bool enabled );
239
240     /**
241      * enable or disable autorefresh \see autorefresh
242      * \param enabled
243      */
244     RepoInfo & setAutorefresh( bool autorefresh );
245
246     /**
247      * set the repository alias \see alias
248      * \param alias
249      */
250     RepoInfo & setAlias( const std::string &alias );
251
252     /**
253      * set the repository type \see type
254      * \param t
255      */
256     RepoInfo & setType( const repo::RepoType &t );
257
258     /**
259      * set the repository name \see name
260      * \param name
261      */
262     RepoInfo & setName( const std::string &name );
263
264     /**
265      * \short set the path to the .repo file
266      *
267      * The path to the .repo file where this repository
268      * was defined, or empty if nowhere.
269      *
270      * \param path File path
271      */
272     RepoInfo & setFilepath( const Pathname &filename );
273
274     /**
275      * \short set the path where the local metadata is stored
276      *
277      * The path to the metadata of this repository
278      * was defined, or empty if nowhere.
279      *
280      * \param path directory path
281      */
282     RepoInfo & setMetadataPath( const Pathname &path );
283
284     /**
285      * \short Whether to check or not this repository with gpg
286      *
287      * \param check true (check) or false (dont'check)
288      *
289      * \note This is a just a hint to the application and can
290      * be ignored.
291      *
292      */
293     RepoInfo & setGpgCheck( bool check );
294
295     /**
296      * \short Key to use for gpg checking of this repository
297      *
298      * \param url Url to the key in ASCII armored format
299      *
300      * \note This is a just a hint to the application and can
301      * be ignored.
302      *
303      */
304     RepoInfo & setGpgKeyUrl( const Url &gpgkey );
305
306     /**
307      * Write a human-readable representation of this RepoInfo object
308      * into the \a str stream. Useful for logging.
309      */
310     std::ostream & dumpOn( std::ostream & str ) const;
311
312     /**
313      * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
314      */
315     std::ostream & dumpRepoOn( std::ostream & str ) const;
316
317     class Impl;
318   private:
319     /** Pointer to implementation */
320     RWCOW_pointer<Impl> _pimpl;
321   };
322   ///////////////////////////////////////////////////////////////////
323
324   /** \relates RepoInfo Stream output */
325   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
326
327   typedef std::list<RepoInfo> RepoInfoList;
328
329   /////////////////////////////////////////////////////////////////
330 } // namespace zypp
331 ///////////////////////////////////////////////////////////////////
332 #endif // ZYPP2_REPOSITORYINFO_H