summaryrefslogtreecommitdiffstats
path: root/apt-pkg/prettyprinters.cc
blob: 87e78bbde5fc5dfba56c1bc0c91cc30530c98a67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Description								/*{{{*/
/* ######################################################################

   Provide pretty printers for pkgCache structs like PkgIterator

   ##################################################################### */
									/*}}}*/
// Include Files							/*{{{*/
#include <config.h>

#include <apt-pkg/depcache.h>
#include <apt-pkg/prettyprinters.h>

#include <ostream>
#include <string>

									/*}}}*/

std::ostream& operator<<(std::ostream& os, const APT::PrettyPkg& pp)	/*{{{*/
{
   if (pp.Pkg.end() == true)
      return os << "invalid package";

   auto state = (*pp.DepCache)[pp.Pkg];
   std::string const current = (pp.Pkg.CurVersion() == 0 ? "none" : pp.Pkg.CurVersion());
   std::string candidate = state.CandVersion;
   if (candidate.empty())
      candidate = "none";
   std::string install = "none";
   if (state.InstallVer != nullptr)
      install = state.InstVerIter(*pp.DepCache).VerStr();

   os << pp.Pkg.FullName(false) << " < " << current;
   if (current != install && install != "none")
      os << " -> " << install;
   if (install != candidate && current != candidate)
      os << " | " << candidate;
   os << " @";
   switch (pp.Pkg->SelectedState)
   {
      case pkgCache::State::Unknown: os << 'u'; break;
      case pkgCache::State::Install: os << 'i'; break;
      case pkgCache::State::Hold: os << 'h'; break;
      case pkgCache::State::DeInstall: os << 'r'; break;
      case pkgCache::State::Purge: os << 'p'; break;
      default: os << 'X';
   }
   switch (pp.Pkg->InstState)
   {
      case pkgCache::State::Ok: break;
      case pkgCache::State::ReInstReq: os << 'R'; break;
      case pkgCache::State::HoldInst: os << 'H'; break;
      case pkgCache::State::HoldReInstReq: os << "HR"; break;
      default: os << 'X';
   }
   switch (pp.Pkg->CurrentState)
   {
      case pkgCache::State::NotInstalled: os << 'n'; break;
      case pkgCache::State::ConfigFiles: os << 'c'; break;
      case pkgCache::State::HalfInstalled: os << 'H'; break;
      case pkgCache::State::UnPacked: os << 'U'; break;
      case pkgCache::State::HalfConfigured: os << 'F'; break;
      case pkgCache::State::TriggersAwaited: os << 'W'; break;
      case pkgCache::State::TriggersPending: os << 'T'; break;
      case pkgCache::State::Installed: os << 'i'; break;
      default: os << 'X';
   }
   os << ' ';
   if (state.Protect())
      os << "p";
   if (state.ReInstall())
      os << "r";
   if (state.Upgradable())
      os << "u";
   if (state.Marked)
      os << "m";
   if (state.Garbage)
      os << "g";
   if (state.NewInstall())
      os << "N";
   else if (state.Upgrade())
      os << "U";
   else if (state.Downgrade())
      os << "D";
   else if (state.Install())
      os << "I";
   else if (state.Purge())
      os << "P";
   else if (state.Delete())
      os << "R";
   else if (state.Held())
      os << "H";
   else if (state.Keep())
      os << "K";
   if (state.NowBroken())
      os << " Nb";
   else if (state.NowPolicyBroken())
      os << " NPb";
   if (state.InstBroken())
      os << " Ib";
   else if (state.InstPolicyBroken())
      os << " IPb";
   os << " >";
   return os;
}
									/*}}}*/
std::ostream& operator<<(std::ostream& os, const APT::PrettyDep& pd)	/*{{{*/
{
   if (unlikely(pd.Dep.end() == true))
      return os << "invalid dependency";

   pkgCache::PkgIterator P = pd.Dep.ParentPkg();
   pkgCache::PkgIterator T = pd.Dep.TargetPkg();

   os << (P.end() ? "invalid pkg" : P.FullName(false)) << " " << pd.Dep.DepType()
	<< " on " << APT::PrettyPkg(pd.DepCache, T);

   if (pd.Dep->Version != 0)
      os << " (" << pd.Dep.CompType() << " " << pd.Dep.TargetVer() << ")";

   return os;
}
									/*}}}*/