Merge branch 'master' of gitorious.org:opensuse/libzypp
[platform/upstream/libzypp.git] / zypp / ZConfig.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ZConfig.h
10  *
11 */
12 #ifndef ZYPP_ZCONFIG_H
13 #define ZYPP_ZCONFIG_H
14
15 #include <iosfwd>
16 #include <set>
17 #include <string>
18
19 #include "zypp/base/Deprecated.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/PtrTypes.h"
22
23 #include "zypp/Arch.h"
24 #include "zypp/Locale.h"
25 #include "zypp/Pathname.h"
26 #include "zypp/IdString.h"
27
28 #include "zypp/DownloadMode.h"
29 #include "zypp/target/rpm/RpmFlags.h"
30
31 ///////////////////////////////////////////////////////////////////
32 namespace zypp
33 { /////////////////////////////////////////////////////////////////
34
35   ///////////////////////////////////////////////////////////////////
36   //
37   //    CLASS NAME : ZConfig
38   //
39   /** Interim helper class to collect global options and settings.
40    * Use it to avoid hardcoded values and calls to getZYpp() just
41    * to retrieve some value like architecture, languages or tmppath.
42    *
43    * It reads /etc/zypp/zypp.conf, the filename can be overridden by
44    * setting the ZYPP_CONF environment variable to a different file.
45    *
46    * Note, if you add settings to this file, please follow the following
47    * convention:
48    *
49    * namespace.settingname
50    *
51    * should become
52    *
53    * namespace_settingName()
54    *
55    * \ingroup Singleton
56   */
57   class ZConfig : private base::NonCopyable
58   {
59     public:
60
61       /** Singleton ctor */
62       static ZConfig & instance();
63
64       /** Print some detail about the current libzypp version.*/
65       std::ostream & about( std::ostream & str ) const;
66
67     public:
68
69       /** The target root directory.
70        * Returns an empty path if no target is set.
71        */
72       Pathname systemRoot() const;
73
74     public:
75
76       /** The autodetected system architecture. */
77       static Arch defaultSystemArchitecture();
78
79       /** The system architecture zypp uses. */
80       Arch systemArchitecture() const;
81
82       /** Override the zypp system architecture.
83        * This is useful for test scenarious. <b>But be warned</b>, zypp does
84        * not expect the system architecture to change at runtime. So
85        * set it at the verry beginning before you acess any other
86        * zypp component.
87       */
88       void setSystemArchitecture( const Arch & arch_r );
89
90       /** Reset the zypp system architecture to the default. */
91       void resetSystemArchitecture()
92       { setSystemArchitecture( defaultSystemArchitecture() ); }
93
94     public:
95       /** The autodetected prefered locale for translated texts.
96        */
97       static Locale defaultTextLocale();
98
99       /** The locale for translated texts zypp uses.
100        */
101       Locale textLocale() const;
102
103       /** Set the prefered locale for translated texts. */
104       void setTextLocale( const Locale & locale_r );
105
106       /** Reset the locale for translated texts to the default. */
107       void resetTextLocale()
108       { setTextLocale( defaultTextLocale() ); }
109
110     public:
111       /**
112        * Path where the caches are kept (/var/cache/zypp)
113        * \ingroup g_ZC_REPOCACHE
114        */
115       Pathname repoCachePath() const;
116
117      /**
118        * Path where the repo metadata is downloaded and kept (repoCachePath()/raw).
119         * \ingroup g_ZC_REPOCACHE
120       */
121       Pathname repoMetadataPath() const;
122
123      /**
124        * Path where the repo solv files are created and kept (repoCachePath()/solv).
125         * \ingroup g_ZC_REPOCACHE
126       */
127       Pathname repoSolvfilesPath() const;
128
129       /**
130        * Path where the repo packages are downloaded and kept (repoCachePath()/packages).
131         * \ingroup g_ZC_REPOCACHE
132       */
133       Pathname repoPackagesPath() const;
134
135       /**
136        * Path where the configfiles are kept (/etc/zypp).
137        * \ingroup g_ZC_CONFIGFILES
138        */
139       Pathname configPath() const;
140
141       /**
142        * Path where the known repositories .repo files are kept (configPath()/repos.d).
143        * \ingroup g_ZC_CONFIGFILES
144        */
145       Pathname knownReposPath() const;
146
147       /**
148        * Path where the known services .service files are kept (configPath()/services.d).
149        * \ingroup g_ZC_CONFIGFILES
150        */
151       Pathname knownServicesPath() const;
152
153       /**
154        * Whether repository urls should be probed.
155        / config option
156        * repo.add.probe
157        */
158       bool repo_add_probe() const;
159
160       /**
161        * Amount of time in minutes that must pass before another refresh.
162        */
163       unsigned repo_refresh_delay() const;
164
165       /**
166        * Whether to use repository alias or name in user messages (progress,
167        * exceptions, ...).
168        * True: use alias, false: use name.
169        */
170       bool repoLabelIsAlias() const;
171
172       /**
173        * Whether to use repository alias or name in user messages (progress,
174        * exceptions, ...). Console applications might prefer to use and display
175        * the shorter alias instead of full repository name.
176        *
177        * Default: false; i.e. repo label is 'name'
178        */
179       void repoLabelIsAlias( bool yesno_r );
180
181       /**
182        * Maximum number of concurrent connections for a single transfer
183        */
184       long download_max_concurrent_connections() const;
185
186       /**
187        * Minimum download speed (bytes per second)
188        * until the connection is dropped
189        */
190       long download_min_download_speed() const;
191
192       /**
193        * Maximum download speed (bytes per second)
194        */
195       long download_max_download_speed() const;
196
197       /**
198        * Maximum silent tries
199        */
200       long download_max_silent_tries() const;
201
202
203       /** Whether to consider using a deltarpm when downloading a package.
204        * Config option <tt>download.use_deltarpm (true)</tt>
205        */
206       bool download_use_deltarpm() const;
207
208       /** Whether to consider using a deltarpm even when rpm is local.
209        * This requires \ref download_use_deltarpm being \c true.
210        * Config option <tt>download.use_deltarpm.always (false)</tt>
211        */
212       bool download_use_deltarpm_always() const;
213
214       /**
215        * Hint which media to prefer when installing packages (download vs. CD).
216        * \see class \ref media::MediaPriority
217        */
218       bool download_media_prefer_download() const;
219       /** \overload */
220       bool download_media_prefer_volatile() const
221       { return ! download_media_prefer_download(); }
222       /**
223        * Set \ref download_media_prefer_download to a specific value.
224        */
225       void set_download_media_prefer_download( bool yesno_r );
226       /**
227        * Set \ref download_media_prefer_download to the configfiles default.
228        */
229       void set_default_download_media_prefer_download();
230
231       /**
232        * Commit download policy to use as default.
233        */
234       DownloadMode commit_downloadMode() const;
235
236       /**
237        * Directory for equivalent vendor definitions  (configPath()/vendors.d)
238        * \ingroup g_ZC_CONFIGFILES
239        */
240       Pathname vendorPath() const;
241
242       /**
243        * Solver regards required packages,patterns,... only
244        */
245       bool solver_onlyRequires() const;
246
247       /**
248        * File in which dependencies described which has to be
249        * fulfilled for a running system.
250        */
251       Pathname solver_checkSystemFile() const;
252
253       /**
254        * Whether vendor check is by default enabled.
255        */
256       bool solver_allowVendorChange() const;
257
258       /**
259        * Whether removing a package should also remove no longer needed requirements.
260        */
261       bool solver_cleandepsOnRemove() const;
262
263       /**
264        * When committing a dist upgrade (e.g. <tt>zypper dup</tt>)
265        * a solver testcase is written. It is needed in bugreports,
266        * in case something went wrong. This returns the number of
267        * testcases to keep on the system. Old cases will be deleted,
268        * as new ones are created. Use \c 0 to write no testcase at all.
269        */
270       unsigned solver_upgradeTestcasesToKeep() const;
271
272       /** Whether dist upgrade should remove a products dropped packages (true).
273        *
274        * A new product may suggest a list of old and no longer supported
275        * packages (dropped packages). Performing a dist upgrade the solver
276        * may try to delete them, even if they do not cause any dependency
277        * problem.
278        *
279        * Turning this option off, the solver will not try to remove those
280        * packages unless they actually do cause dependency trouble. At any
281        * time you may use zypper to detect orphaned packages, and do the
282        * cleanup manually. Or simply leave them installed as long as you don't
283        * need the disk space.
284        */
285       bool solverUpgradeRemoveDroppedPackages() const;
286       /** Set \ref solverUpgradeRemoveDroppedPackages to \a val_r. */
287       void setSolverUpgradeRemoveDroppedPackages( bool val_r );
288       /** Reset \ref solverUpgradeRemoveDroppedPackages to the \c zypp.conf default. */
289       void resetSolverUpgradeRemoveDroppedPackages();
290
291       /** \name Packages which can be installed in different versions at the same time.
292        * This returns the config file values (\c names or \c provides:...). For the corresponding
293        * packages use e.g \ref sat::Pool::multiversionBegin, or \ref sat::Solbale::multiversionInstall
294        * (\ref ui::Selectable::multiversionInstall).
295        */
296       //@{
297       const std::set<std::string> & multiversionSpec() const;
298       void addMultiversionSpec( const std::string & name_r );
299       void removeMultiversionSpec( const std::string & name_r );
300       //@}
301
302       /**
303        * Path where zypp can find or create lock file (configPath()/locks)
304        * \ingroup g_ZC_CONFIGFILES
305        */
306       Pathname locksFile() const;
307
308       /**
309        * Whether locks file should be read and applied after start (true)
310        */
311       bool apply_locks_file() const;
312
313       /**
314        * Path where the update items are kept (/var/adm)
315        */
316       Pathname update_dataPath() const;
317
318      /**
319       * Path where the repo metadata is downloaded and kept (update_dataPath()/).
320       * \ingroup g_ZC_REPOCACHE
321       */
322       Pathname update_scriptsPath() const;
323
324      /**
325       * Path where the repo solv files are created and kept (update_dataPath()/solv).
326       * \ingroup g_ZC_REPOCACHE
327       */
328       Pathname update_messagesPath() const;
329
330       /** \name Command to be invoked to send update messages. */
331       //@{
332       /** Command definition for sending update messages.*/
333       std::string updateMessagesNotify() const;
334       /** Set a new command definition (see update.messages.notify in zypp.conf). */
335       void setUpdateMessagesNotify( const std::string & val_r );
336       /** Reset to the zypp.conf default. */
337       void resetUpdateMessagesNotify();
338      //@}
339
340       /** \name Options for package installation */
341       //@{
342       /** The default \ref target::rpm::RpmInstFlags for \ref ZYppCommitPolicy.
343        * Or-combination of \ref target::rpm::RpmInstFlag.
344        * \code
345        * ZConfig.instance().rpmInstallFlags().testFlag( target::rpm::RPMINST_EXCLUDEDOCS );
346        * \endcode
347        */
348       target::rpm::RpmInstFlags rpmInstallFlags() const;
349       //@}
350
351       /**
352        * Path where ZYpp install history is logged. Defaults to
353        * /var/log/zypp/history.
354        *
355        * \see http://en.opensuse.org/Libzypp/Package_History
356        */
357       Pathname historyLogFile() const;
358
359       /**
360        * Defaults to /etc/zypp/credentials.d
361        */
362       Pathname credentialsGlobalDir() const;
363
364       /**
365        * Defaults to /etc/zypp/credentials.cat
366        */
367       Pathname credentialsGlobalFile() const;
368
369       /** Package telling the "product version" on systems not using /etc/product.d/baseproduct.
370        *
371        * On RHEL, Fedora and others the "product version" is determined by the first package
372        * providing 'redhat-release'. This value is not hardcoded in YUM and can be configured
373        * with the $distroverpkg variable.
374        *
375        * Defaults to 'redhat-release'.
376        */
377       std::string distroverpkg() const;
378
379       /** \name Plugins */
380       //@{
381       /**
382        * Defaults to \c /usr/lib/zypp/plugins
383        */
384       Pathname pluginsDir() const;
385
386       /**
387        * Defaults to \ref pluginsDir()/media
388        */
389       Pathname mediaPluginsDir() const;
390
391        /**
392         * Defaults to \ref pluginsDir()/services
393         */
394        Pathname servicePluginsDir() const;
395       //@}
396     public:
397       class Impl;
398       /** Dtor */
399       ~ZConfig();
400     private:
401       friend class Impl;
402       /** Default ctor. */
403       ZConfig();
404       /** Pointer to implementation */
405       RW_pointer<Impl, rw_pointer::Scoped<Impl> > _pimpl;
406   };
407   ///////////////////////////////////////////////////////////////////
408
409   /////////////////////////////////////////////////////////////////
410 } // namespace zypp
411 ///////////////////////////////////////////////////////////////////
412 #endif // ZYPP_ZCONFIG_H