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