]> git.saurik.com Git - apt.git/blame - apt-pkg/prettyprinters.cc
Merge branch 'cmake'
[apt.git] / apt-pkg / prettyprinters.cc
CommitLineData
84573326
DK
1// Description /*{{{*/
2/* ######################################################################
3
4 Provide pretty printers for pkgCache structs like PkgIterator
5
6 ##################################################################### */
7 /*}}}*/
8// Include Files /*{{{*/
9#include <config.h>
10
11#include <apt-pkg/depcache.h>
12#include <apt-pkg/prettyprinters.h>
13
14#include <ostream>
15#include <string>
16
17 /*}}}*/
18
19std::ostream& operator<<(std::ostream& os, const APT::PrettyPkg& pp) /*{{{*/
20{
21 if (pp.Pkg.end() == true)
22 return os << "invalid package";
23
d622baee
DK
24 auto state = (*pp.DepCache)[pp.Pkg];
25 std::string const current = (pp.Pkg.CurVersion() == 0 ? "none" : pp.Pkg.CurVersion());
26 std::string candidate = state.CandVersion;
27 if (candidate.empty())
28 candidate = "none";
29 std::string install = "none";
30 if (state.InstallVer != nullptr)
31 install = state.InstVerIter(*pp.DepCache).VerStr();
32
33 os << pp.Pkg.FullName(false) << " < " << current;
34 if (current != install && install != "none")
35 os << " -> " << install;
36 if (install != candidate && current != candidate)
37 os << " | " << candidate;
38 os << " @";
39 switch (pp.Pkg->SelectedState)
40 {
41 case pkgCache::State::Unknown: os << 'u'; break;
42 case pkgCache::State::Install: os << 'i'; break;
43 case pkgCache::State::Hold: os << 'h'; break;
44 case pkgCache::State::DeInstall: os << 'r'; break;
45 case pkgCache::State::Purge: os << 'p'; break;
46 default: os << 'X';
47 }
48 switch (pp.Pkg->InstState)
49 {
50 case pkgCache::State::Ok: break;
51 case pkgCache::State::ReInstReq: os << 'R'; break;
52 case pkgCache::State::HoldInst: os << 'H'; break;
53 case pkgCache::State::HoldReInstReq: os << "HR"; break;
54 default: os << 'X';
55 }
56 switch (pp.Pkg->CurrentState)
57 {
58 case pkgCache::State::NotInstalled: os << 'n'; break;
59 case pkgCache::State::ConfigFiles: os << 'c'; break;
60 case pkgCache::State::HalfInstalled: os << 'H'; break;
61 case pkgCache::State::UnPacked: os << 'U'; break;
62 case pkgCache::State::HalfConfigured: os << 'F'; break;
63 case pkgCache::State::TriggersAwaited: os << 'W'; break;
64 case pkgCache::State::TriggersPending: os << 'T'; break;
65 case pkgCache::State::Installed: os << 'i'; break;
66 default: os << 'X';
67 }
68 os << ' ';
69 if (state.Protect())
70 os << "p";
71 if (state.ReInstall())
72 os << "r";
73 if (state.Upgradable())
74 os << "u";
75 if (state.Marked)
76 os << "m";
77 if (state.Garbage)
78 os << "g";
79 if (state.NewInstall())
80 os << "N";
81 else if (state.Upgrade())
82 os << "U";
83 else if (state.Downgrade())
84 os << "D";
85 else if (state.Install())
86 os << "I";
87 else if (state.Purge())
88 os << "P";
89 else if (state.Delete())
90 os << "R";
91 else if (state.Held())
92 os << "H";
93 else if (state.Keep())
94 os << "K";
95 if (state.NowBroken())
96 os << " Nb";
97 else if (state.NowPolicyBroken())
98 os << " NPb";
99 if (state.InstBroken())
100 os << " Ib";
101 else if (state.InstPolicyBroken())
102 os << " IPb";
103 os << " >";
84573326
DK
104 return os;
105}
106 /*}}}*/
107std::ostream& operator<<(std::ostream& os, const APT::PrettyDep& pd) /*{{{*/
108{
109 if (unlikely(pd.Dep.end() == true))
110 return os << "invalid dependency";
111
112 pkgCache::PkgIterator P = pd.Dep.ParentPkg();
113 pkgCache::PkgIterator T = pd.Dep.TargetPkg();
114
115 os << (P.end() ? "invalid pkg" : P.FullName(false)) << " " << pd.Dep.DepType()
116 << " on " << APT::PrettyPkg(pd.DepCache, T);
117
118 if (pd.Dep->Version != 0)
119 os << " (" << pd.Dep.CompType() << " " << pd.Dep.TargetVer() << ")";
120
121 return os;
122}
123 /*}}}*/