added disk usage data to PackageImplIf interface, provide this info from
[platform/upstream/libzypp.git] / zypp / detail / PackageImplIf.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/detail/PackageImplIf.cc
10  *
11 */
12 #include "zypp/detail/PackageImplIf.h"
13 #include <iostream>
14
15 using namespace std;
16
17 ///////////////////////////////////////////////////////////////////
18 namespace zypp
19 { /////////////////////////////////////////////////////////////////
20   ///////////////////////////////////////////////////////////////////
21   namespace detail
22   { /////////////////////////////////////////////////////////////////
23
24     /////////////////////////////////////////////////////////////////
25     // Default implementation of PackageImplIf attributes,
26     // as far as resonable.
27     /////////////////////////////////////////////////////////////////
28
29       Date PackageImplIf::buildtime() const
30       { return Date(); }
31
32       std::string PackageImplIf::buildhost() const
33       { return std::string(); }
34
35       Date PackageImplIf::installtime() const
36       { return Date(); }
37
38       std::string PackageImplIf::distribution() const
39       { return std::string(); }
40
41       Vendor PackageImplIf::vendor() const
42       { return Vendor(); }
43
44       Label PackageImplIf::license() const
45       { return Label(); }
46
47       std::string PackageImplIf::packager() const
48       { return std::string(); }
49
50       PackageGroup PackageImplIf::group() const
51       { return PackageGroup(); }
52
53       Changelog PackageImplIf::changelog() const
54       { return Changelog(); }
55
56       std::string PackageImplIf::url() const
57       { return std::string(); }
58
59       std::string PackageImplIf::os() const
60       { return std::string(); }
61
62       std::list<std::string> PackageImplIf::prein() const
63       { return std::list<std::string>(); }
64
65       std::list<std::string> PackageImplIf::postin() const
66       { return std::list<std::string>(); }
67
68       std::list<std::string> PackageImplIf::preun() const
69       { return std::list<std::string>(); }
70
71       std::list<std::string> PackageImplIf::postun() const
72       { return std::list<std::string>(); }
73
74       ByteCount PackageImplIf::sourcesize() const
75       { return ByteCount(); }
76
77       ByteCount PackageImplIf::archivesize() const
78       { return ByteCount(); }
79
80       std::list<std::string> PackageImplIf::authors() const
81       { return std::list<std::string>(); }
82
83       std::list<std::string> PackageImplIf::filenames() const
84       { return std::list<std::string>(); }
85
86       License PackageImplIf::licenseToConfirm() const
87       { return License(); }
88
89       // disk usage class methods
90
91       std::ostream & operator<<( std::ostream & str, const PackageImplIf::DiskUsage::Entry & obj )
92       {
93         return str << obj.path << '\t' << obj._size << "; files " << obj.files;
94       }
95
96       PackageImplIf::DiskUsage::Entry PackageImplIf::DiskUsage::extract( const std::string & dirname_r )
97       {
98         Entry ret( dirname_r );
99       
100         iterator fst = begin();
101         for ( ; fst != end() && !fst->isBelow( ret ); ++fst )
102           ; // seek 1st equal or below
103       
104         if ( fst != end() ) {
105           iterator lst = fst;
106           for ( ; lst != end() && lst->isBelow( ret ); ++lst ) {
107             // collect while below
108             ret += *lst;
109           }
110           // remove
111           _dirs.erase( fst, lst );
112         }
113       
114         return ret;
115       }
116
117       std::ostream & operator<<( std::ostream & str, const PackageImplIf::DiskUsage & obj )
118       {
119         str << "Package Disk Usage {" << endl;
120         for ( PackageImplIf::DiskUsage::EntrySet::const_iterator it = obj._dirs.begin(); it != obj._dirs.end(); ++it ) {
121           str << "   " << *it << endl;
122         }
123         return str << "}";
124       }
125
126     /////////////////////////////////////////////////////////////////
127   } // namespace detail
128   ///////////////////////////////////////////////////////////////////
129   /////////////////////////////////////////////////////////////////
130 } // namespace zypp
131 ///////////////////////////////////////////////////////////////////