Package keywords are IdStrings, so don't use ordinary string comparison.
[platform/upstream/libzypp.git] / zypp / Package.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/Package.cc
10  *
11 */
12 #include "zypp/base/Logger.h"
13 #include "zypp/base/String.h"
14 #include "zypp/Package.h"
15 #include "zypp/sat/LookupAttr.h"
16 #include "zypp/ZYppFactory.h"
17 #include "zypp/target/rpm/RpmDb.h"
18 #include "zypp/target/rpm/RpmHeader.h"
19
20 using namespace std;
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   IMPL_PTR_TYPE(Package);
27
28   ///////////////////////////////////////////////////////////////////
29   //
30   //    METHOD NAME : Package::Package
31   //    METHOD TYPE : Ctor
32   //
33   Package::Package( const sat::Solvable & solvable_r )
34   : ResObject( solvable_r )
35   {}
36
37   ///////////////////////////////////////////////////////////////////
38   //
39   //    METHOD NAME : Package::~Package
40   //    METHOD TYPE : Dtor
41   //
42   Package::~Package()
43   {}
44
45   VendorSupportOption Package::vendorSupport() const
46   {
47     static const IdString support_unsupported( "support_unsupported" );
48     static const IdString support_acc( "support_acc" );
49     static const IdString support_l1( "support_l1" );
50     static const IdString support_l2( "support_l2" );
51     static const IdString support_l3( "support_l3" );
52
53     Keywords kw( keywords() );
54     for_( it, kw.begin(), kw.end() )
55     {
56       if ( *it == support_unsupported )
57         return VendorSupportUnsupported;
58       if ( *it == support_acc )
59         return VendorSupportACC;
60       if ( *it == support_l1 )
61         return VendorSupportLevel1;
62       if ( *it == support_l2 )
63         return VendorSupportLevel2;
64       if ( *it == support_l3 )
65         return VendorSupportLevel3;
66     }
67     return VendorSupportUnknown;
68   }
69
70   bool Package::maybeUnsupported() const
71   {
72       if ( ( vendorSupport() == VendorSupportUnknown ) ||
73            ( vendorSupport() == VendorSupportACC ) ||
74            ( vendorSupport() == VendorSupportUnsupported ) )
75           return true;
76       return false;
77   }
78
79   Changelog Package::changelog() const
80   {
81       Target_Ptr target( getZYpp()->getTarget() );
82       if ( ! target )
83       {
84         ERR << "Target not initialized. Changelog is not available." << std::endl;
85         return Changelog();
86       }
87
88       if ( repository().isSystemRepo() )
89       {
90           target::rpm::RpmHeader::constPtr header;
91           target->rpmDb().getData(name(), header);
92           return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
93       }
94       WAR << "changelog is not available for uninstalled packages" << std::endl;
95       return Changelog();
96   }
97
98   std::string Package::buildhost() const
99   { return lookupStrAttribute( sat::SolvAttr::buildhost ); }
100
101   std::string Package::distribution() const
102   { return lookupStrAttribute( sat::SolvAttr::distribution ); }
103
104   std::string Package::license() const
105   { return lookupStrAttribute( sat::SolvAttr::license ); }
106
107   std::string Package::packager() const
108   { return lookupStrAttribute( sat::SolvAttr::packager ); }
109
110   std::string Package::group() const
111   { return lookupStrAttribute( sat::SolvAttr::group ); }
112
113   Package::Keywords Package::keywords() const
114   { return Keywords( sat::SolvAttr::keywords, satSolvable() ); }
115
116   std::string Package::url() const
117   { return lookupStrAttribute( sat::SolvAttr::url ); }
118
119   ByteCount Package::sourcesize() const
120   { return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
121
122   std::list<std::string> Package::authors() const
123   {
124     std::list<std::string> ret;
125     str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
126     return ret;
127   }
128
129   Package::FileList Package::filelist() const
130   { return FileList( sat::SolvAttr::filelist, satSolvable() ); }
131
132   CheckSum Package::checksum() const
133   { return lookupCheckSumAttribute( sat::SolvAttr::checksum ); }
134
135   OnMediaLocation Package::location() const
136   { return lookupLocation(); }
137
138   std::string Package::sourcePkgName() const
139   {
140     // no id means same as package
141     sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourcename ) );
142     return id ? IdString( id ).asString() : name();
143   }
144
145   Edition Package::sourcePkgEdition() const
146   {
147    // no id means same as package
148     sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourceevr ) );
149     return id ? Edition( id ) : edition();
150   }
151
152   std::string Package::sourcePkgType() const
153   { return lookupStrAttribute( sat::SolvAttr::sourcearch ); }
154
155   std::string Package::sourcePkgLongName() const
156   { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
157
158
159   /////////////////////////////////////////////////////////////////
160 } // namespace zypp
161 ///////////////////////////////////////////////////////////////////