Propagate ZConfig::setTextLocale to pool. (bnc#588850)
[platform/upstream/libzypp.git] / zypp / sat / Pool.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.cc
10  *
11 */
12
13 #include <iostream>
14
15 #include "zypp/base/Easy.h"
16 #include "zypp/base/Logger.h"
17 #include "zypp/base/Gettext.h"
18 #include "zypp/base/Exception.h"
19
20 #include "zypp/AutoDispose.h"
21
22 #include "zypp/sat/detail/PoolImpl.h"
23 #include "zypp/sat/Pool.h"
24 #include "zypp/sat/LookupAttr.h"
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29   ///////////////////////////////////////////////////////////////////
30   namespace sat
31   { /////////////////////////////////////////////////////////////////
32
33     const std::string & Pool::systemRepoAlias()
34     { return detail::PoolImpl::systemRepoAlias(); }
35
36     ::_Pool * Pool::get() const
37     { return myPool().getPool(); }
38
39     Pool::size_type Pool::capacity() const
40     { return myPool()->nsolvables; }
41
42     const SerialNumber & Pool::serial() const
43     { return myPool().serial(); }
44
45     void Pool::prepare() const
46     { return myPool().prepare(); }
47
48     bool Pool::reposEmpty() const
49     { return ! myPool()->nrepos; }
50
51     Pool::size_type Pool::reposSize() const
52     { return myPool()->nrepos; }
53
54     Pool::RepositoryIterator Pool::reposBegin() const
55     { return RepositoryIterator( myPool()->repos ); }
56
57     Pool::RepositoryIterator Pool::reposEnd() const
58     { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
59
60     bool Pool::solvablesEmpty() const
61     {
62       // return myPool()->nsolvables;
63       // nsolvables is the array size including
64       // invalid Solvables.
65       for_( it, reposBegin(), reposEnd() )
66       {
67         if ( ! it->solvablesEmpty() )
68           return false;
69       }
70       return true;
71     }
72
73     Pool::size_type Pool::solvablesSize() const
74     {
75       // Do not return myPool()->nsolvables;
76       // nsolvables is the array size including
77       // invalid Solvables.
78       size_type ret = 0;
79       for_( it, reposBegin(), reposEnd() )
80       {
81         ret += it->solvablesSize();
82       }
83       return ret;
84     }
85
86     Pool::SolvableIterator Pool::solvablesBegin() const
87     { return SolvableIterator( myPool().getFirstId() ); }
88
89     Pool::SolvableIterator Pool::solvablesEnd() const
90     { return SolvableIterator(); }
91
92     Repository Pool::reposInsert( const std::string & alias_r )
93     {
94       Repository ret( reposFind( alias_r ) );
95       if ( ret )
96         return ret;
97
98       ret = Repository( myPool()._createRepo( alias_r ) );
99       if ( ret.isSystemRepo() )
100       {
101         // autoprovide (dummy) RepoInfo
102         RepoInfo info;
103         info.setAlias( alias_r );
104         info.setName( alias_r );
105         info.setAutorefresh( true );
106         info.setEnabled( true );
107         ret.setInfo( info );
108       }
109       return ret;
110     }
111
112     Repository Pool::reposFind( const std::string & alias_r ) const
113     {
114       for_( it, reposBegin(), reposEnd() )
115       {
116         if ( alias_r == it->alias() )
117           return *it;
118       }
119       return Repository();
120     }
121
122     Repository Pool::findSystemRepo() const
123     {
124       return Repository( myPool().systemRepo() );
125     }
126
127     Repository Pool::systemRepo()
128     {
129       if ( myPool().systemRepo() )
130         return Repository( myPool().systemRepo() );
131       return reposInsert( systemRepoAlias() );
132     }
133
134     Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
135     {
136       // Using a temporay repo! (The additional parenthesis are required.)
137       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
138       *tmprepo = reposInsert( alias_r );
139       tmprepo->addSolv( file_r );
140
141       // no exceptions so we keep it:
142       tmprepo.resetDispose();
143       return tmprepo;
144     }
145
146     Repository Pool::addRepoSolv( const Pathname & file_r )
147     { return addRepoSolv( file_r, file_r.basename() ); }
148
149     Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
150     {
151       Repository ret( addRepoSolv( file_r, info_r.alias() ) );
152       ret.setInfo( info_r );
153       return ret;
154     }
155
156     /////////////////////////////////////////////////////////////////
157
158     Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
159     {
160       // Using a temporay repo! (The additional parenthesis are required.)
161       AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
162       *tmprepo = reposInsert( alias_r );
163       tmprepo->addHelix( file_r );
164
165       // no exceptions so we keep it:
166       tmprepo.resetDispose();
167       return tmprepo;
168     }
169
170     Repository Pool::addRepoHelix( const Pathname & file_r )
171     { return addRepoHelix( file_r, file_r.basename() ); }
172
173     Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
174     {
175       Repository ret( addRepoHelix( file_r, info_r.alias() ) );
176       ret.setInfo( info_r );
177       return ret;
178     }
179
180    /////////////////////////////////////////////////////////////////
181
182     void Pool::setTextLocale( const Locale & locale_r )
183     { myPool().setTextLocale( locale_r ); }
184
185     void Pool::setRequestedLocales( const LocaleSet & locales_r )
186     { myPool().setRequestedLocales( locales_r ); }
187
188     bool Pool::addRequestedLocale( const Locale & locale_r )
189     { return myPool().addRequestedLocale( locale_r ); }
190
191     bool Pool::eraseRequestedLocale( const Locale & locale_r )
192     { return myPool().eraseRequestedLocale( locale_r ); }
193
194     const LocaleSet & Pool::getRequestedLocales() const
195     { return myPool().getRequestedLocales(); }
196
197     bool Pool::isRequestedLocale( const Locale & locale_r ) const
198     { return myPool().isRequestedLocale( locale_r ); }
199
200     const LocaleSet & Pool::getAvailableLocales() const
201     {  return myPool().getAvailableLocales(); }
202
203     bool Pool::isAvailableLocale( const Locale & locale_r ) const
204     { return myPool().isAvailableLocale( locale_r ); }
205
206     bool Pool::multiversionEmpty() const                        { return myPool().multiversionList().empty(); }
207     size_t Pool::multiversionSize() const                       { return myPool().multiversionList().size(); }
208     Pool::MultiversionIterator Pool::multiversionBegin() const  { return myPool().multiversionList().begin(); }
209     Pool::MultiversionIterator Pool::multiversionEnd() const    { return myPool().multiversionList().end(); }
210     bool Pool::isMultiversion( IdString ident_r ) const         { return myPool().isMultiversion( ident_r ); }
211
212    /******************************************************************
213     **
214     **  FUNCTION NAME : operator<<
215     **  FUNCTION TYPE : std::ostream &
216     */
217     std::ostream & operator<<( std::ostream & str, const Pool & obj )
218     {
219       return str << "sat::pool(" << obj.serial() << ")["
220           << obj.capacity() << "]{"
221           << obj.reposSize() << "repos|"
222           << obj.solvablesSize() << "slov}";
223     }
224
225     /////////////////////////////////////////////////////////////////
226   } // namespace sat
227   ///////////////////////////////////////////////////////////////////
228   /////////////////////////////////////////////////////////////////
229 } // namespace zypp
230 ///////////////////////////////////////////////////////////////////