prettyprinters.cc 3.6 KB

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