+ Package::maybeUnsupported
[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       Keywords kw(keywords());
48       
49       for_( it, kw.begin(), kw.end() )
50       {
51           if ( *it == "support_unsupported")
52               return VendorSupportUnsupported;
53           if ( *it == "support_acc")
54               return VendorSupportACC;
55           
56           if ( *it == "support_l1")
57               return VendorSupportLevel1;
58           if ( *it == "support_l2")
59               return VendorSupportLevel2;
60           if ( *it == "support_l3")
61               return VendorSupportLevel3;
62       }
63       return VendorSupportUnknown;
64   }  
65
66   bool Package::maybeUnsupported() const
67   {
68       return ( vendorSupport() & ( VendorSupportACC | VendorSupportUnsupported | VendorSupportUnknown )  == ( VendorSupportACC | VendorSupportUnsupported | VendorSupportUnknown ) );
69   }
70
71
72   Changelog Package::changelog() const
73   {
74       Target_Ptr target;
75       try
76       {
77           target = getZYpp()->target();
78       }
79       catch ( const Exception &e )
80       {
81            ERR << "Target not initialized. Changelog is not available." << std::endl;
82            return Changelog();
83       }
84
85
86       if ( repository().isSystemRepo() )
87       {
88           target::rpm::RpmHeader::constPtr header;
89           target->rpmDb().getData(name(), header);
90           return header->tag_changelog();
91       }
92       WAR << "changelog is not available for uninstalled packages" << std::endl;
93       return Changelog();
94   }
95
96   std::string Package::buildhost() const
97   { return lookupStrAttribute( sat::SolvAttr::buildhost ); }
98
99   std::string Package::distribution() const
100   { return lookupStrAttribute( sat::SolvAttr::distribution ); }
101
102   std::string Package::license() const
103   { return lookupStrAttribute( sat::SolvAttr::license ); }
104
105   std::string Package::packager() const
106   { return lookupStrAttribute( sat::SolvAttr::packager ); }
107
108   std::string Package::group() const
109   { return lookupStrAttribute( sat::SolvAttr::group ); }
110
111   Package::Keywords Package::keywords() const
112   { return Keywords( sat::SolvAttr::keywords, satSolvable() ); }
113
114   std::string Package::url() const
115   { return lookupStrAttribute( sat::SolvAttr::url ); }
116
117   ByteCount Package::sourcesize() const
118   { return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
119
120   std::list<std::string> Package::authors() const
121   {
122     std::list<std::string> ret;
123     str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
124     return ret;
125   }
126
127   std::list<std::string> Package::filenames() const
128   {
129     std::list<std::string> files;
130     sat::LookupAttr q( sat::SolvAttr::filelist, *this );
131     for_( it, q.begin(), q.end() )
132     {
133         files.push_back(it.asString());
134     }
135     return files;
136   }
137
138   CheckSum Package::checksum() const
139   { return lookupCheckSumAttribute( sat::SolvAttr::checksum ); }
140
141   OnMediaLocation Package::location() const
142   { return lookupLocation(); }
143
144   std::string Package::sourcePkgName() const
145   {
146    // no id means same as package
147     sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourcename ) );
148     id = lookupIdAttribute(sat::SolvAttr::sourcearch);
149     return id ? IdString( id ).asString() : name();
150   }
151
152   Edition Package::sourcePkgEdition() const
153   {
154    // no id means same as package
155     sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourceevr ) );
156     return id ? Edition( id ) : edition();
157   }
158
159   /////////////////////////////////////////////////////////////////
160 } // namespace zypp
161 ///////////////////////////////////////////////////////////////////