libzypp  10.5.0
Package.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
00005 |                          / /__ | | | | | |                           |
00006 |                         /_____||_| |_| |_|                           |
00007 |                                                                      |
00008 \---------------------------------------------------------------------*/
00012 #include "zypp/base/Logger.h"
00013 #include "zypp/base/String.h"
00014 #include "zypp/Package.h"
00015 #include "zypp/sat/LookupAttr.h"
00016 #include "zypp/ZYppFactory.h"
00017 #include "zypp/target/rpm/RpmDb.h"
00018 #include "zypp/target/rpm/RpmHeader.h"
00019 
00020 using namespace std;
00021 
00023 namespace zypp
00024 { 
00025 
00026   IMPL_PTR_TYPE(Package);
00027 
00029   //
00030   //    METHOD NAME : Package::Package
00031   //    METHOD TYPE : Ctor
00032   //
00033   Package::Package( const sat::Solvable & solvable_r )
00034   : ResObject( solvable_r )
00035   {}
00036 
00038   //
00039   //    METHOD NAME : Package::~Package
00040   //    METHOD TYPE : Dtor
00041   //
00042   Package::~Package()
00043   {}
00044 
00045   VendorSupportOption Package::vendorSupport() const
00046   {
00047     static const IdString support_unsupported( "support_unsupported" );
00048     static const IdString support_acc( "support_acc" );
00049     static const IdString support_l1( "support_l1" );
00050     static const IdString support_l2( "support_l2" );
00051     static const IdString support_l3( "support_l3" );
00052 
00053     Keywords kw( keywords() );
00054     for_( it, kw.begin(), kw.end() )
00055     {
00056       if ( *it == support_unsupported )
00057         return VendorSupportUnsupported;
00058       if ( *it == support_acc )
00059         return VendorSupportACC;
00060       if ( *it == support_l1 )
00061         return VendorSupportLevel1;
00062       if ( *it == support_l2 )
00063         return VendorSupportLevel2;
00064       if ( *it == support_l3 )
00065         return VendorSupportLevel3;
00066     }
00067     return VendorSupportUnknown;
00068   }
00069 
00070   bool Package::maybeUnsupported() const
00071   {
00072       if ( ( vendorSupport() == VendorSupportUnknown ) ||
00073            ( vendorSupport() == VendorSupportACC ) ||
00074            ( vendorSupport() == VendorSupportUnsupported ) )
00075           return true;
00076       return false;
00077   }
00078 
00079   Changelog Package::changelog() const
00080   {
00081       Target_Ptr target( getZYpp()->getTarget() );
00082       if ( ! target )
00083       {
00084         ERR << "Target not initialized. Changelog is not available." << std::endl;
00085         return Changelog();
00086       }
00087 
00088       if ( repository().isSystemRepo() )
00089       {
00090           target::rpm::RpmHeader::constPtr header;
00091           target->rpmDb().getData(name(), header);
00092           return header ? header->tag_changelog() : Changelog(); // might be deleted behind our back (bnc #530595)
00093       }
00094       WAR << "changelog is not available for uninstalled packages" << std::endl;
00095       return Changelog();
00096   }
00097 
00098   std::string Package::buildhost() const
00099   { return lookupStrAttribute( sat::SolvAttr::buildhost ); }
00100 
00101   std::string Package::distribution() const
00102   { return lookupStrAttribute( sat::SolvAttr::distribution ); }
00103 
00104   std::string Package::license() const
00105   { return lookupStrAttribute( sat::SolvAttr::license ); }
00106 
00107   std::string Package::packager() const
00108   { return lookupStrAttribute( sat::SolvAttr::packager ); }
00109 
00110   std::string Package::group() const
00111   { return lookupStrAttribute( sat::SolvAttr::group ); }
00112 
00113   Package::Keywords Package::keywords() const
00114   { return Keywords( sat::SolvAttr::keywords, satSolvable() ); }
00115 
00116   std::string Package::url() const
00117   { return lookupStrAttribute( sat::SolvAttr::url ); }
00118 
00119   ByteCount Package::sourcesize() const
00120   { return lookupNumAttribute( sat::SolvAttr::sourcesize ); }
00121 
00122   std::list<std::string> Package::authors() const
00123   {
00124     std::list<std::string> ret;
00125     str::split( lookupStrAttribute( sat::SolvAttr::authors ), std::back_inserter(ret), "\n" );
00126     return ret;
00127   }
00128 
00129   Package::FileList Package::filelist() const
00130   { return FileList( sat::SolvAttr::filelist, satSolvable() ); }
00131 
00132   CheckSum Package::checksum() const
00133   { return lookupCheckSumAttribute( sat::SolvAttr::checksum ); }
00134 
00135   OnMediaLocation Package::location() const
00136   { return lookupLocation(); }
00137 
00138   std::string Package::sourcePkgName() const
00139   {
00140     // no id means same as package
00141     sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourcename ) );
00142     return id ? IdString( id ).asString() : name();
00143   }
00144 
00145   Edition Package::sourcePkgEdition() const
00146   {
00147    // no id means same as package
00148     sat::detail::IdType id( lookupIdAttribute( sat::SolvAttr::sourceevr ) );
00149     return id ? Edition( id ) : edition();
00150   }
00151 
00152   std::string Package::sourcePkgType() const
00153   { return lookupStrAttribute( sat::SolvAttr::sourcearch ); }
00154 
00155   std::string Package::sourcePkgLongName() const
00156   { return str::form( "%s-%s.%s", sourcePkgName().c_str(), sourcePkgEdition().c_str(), sourcePkgType().c_str() ); }
00157 
00158 
00160 } // namespace zypp