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