private-show.cc 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <apt-pkg/error.h>
  2. #include <apt-pkg/cachefile.h>
  3. #include <apt-pkg/cachefilter.h>
  4. #include <apt-pkg/cacheset.h>
  5. #include <apt-pkg/init.h>
  6. #include <apt-pkg/progress.h>
  7. #include <apt-pkg/sourcelist.h>
  8. #include <apt-pkg/cmndline.h>
  9. #include <apt-pkg/strutl.h>
  10. #include <apt-pkg/fileutl.h>
  11. #include <apt-pkg/pkgrecords.h>
  12. #include <apt-pkg/srcrecords.h>
  13. #include <apt-pkg/version.h>
  14. #include <apt-pkg/policy.h>
  15. #include <apt-pkg/tagfile.h>
  16. #include <apt-pkg/algorithms.h>
  17. #include <apt-pkg/sptr.h>
  18. #include <apt-pkg/pkgsystem.h>
  19. #include <apt-pkg/indexfile.h>
  20. #include <apt-pkg/metaindex.h>
  21. #include <apti18n.h>
  22. #include "private-output.h"
  23. #include "private-cacheset.h"
  24. namespace APT {
  25. namespace Cmd {
  26. // DisplayRecord - Displays the complete record for the package /*{{{*/
  27. // ---------------------------------------------------------------------
  28. bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V,
  29. ostream &out)
  30. {
  31. pkgCache *Cache = CacheFile.GetPkgCache();
  32. if (unlikely(Cache == NULL))
  33. return false;
  34. // Find an appropriate file
  35. pkgCache::VerFileIterator Vf = V.FileList();
  36. for (; Vf.end() == false; ++Vf)
  37. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
  38. break;
  39. if (Vf.end() == true)
  40. Vf = V.FileList();
  41. // Check and load the package list file
  42. pkgCache::PkgFileIterator I = Vf.File();
  43. if (I.IsOk() == false)
  44. return _error->Error(_("Package file %s is out of sync."),I.FileName());
  45. // Read the record
  46. FileFd PkgF;
  47. if (PkgF.Open(I.FileName(), FileFd::ReadOnly, FileFd::Extension) == false)
  48. return false;
  49. pkgTagSection Tags;
  50. pkgTagFile TagF(&PkgF);
  51. TFRewriteData RW[] = {
  52. {"Conffiles",0},
  53. {"Description",0},
  54. {"Description-md5",0},
  55. {}
  56. };
  57. const char *Zero = 0;
  58. if (TagF.Jump(Tags, V.FileList()->Offset) == false ||
  59. TFRewrite(stdout,Tags,&Zero,RW) == false)
  60. {
  61. _error->Error("Internal Error, Unable to parse a package record");
  62. return false;
  63. }
  64. // write the description
  65. pkgRecords Recs(*Cache);
  66. pkgCache::DescIterator Desc = V.TranslatedDescription();
  67. if (Desc.end() == false)
  68. {
  69. pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
  70. if (strcmp(Desc.LanguageCode(),"") != 0)
  71. out << "Description-lang: " << Desc.LanguageCode() << std::endl;
  72. out << "Description" << P.LongDesc();
  73. }
  74. // write a final newline (after the description)
  75. out << std::endl << std::endl;
  76. return true;
  77. }
  78. /*}}}*/
  79. bool ShowPackage(CommandLine &CmdL)
  80. {
  81. pkgCacheFile CacheFile;
  82. CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
  83. APT::VersionList::Version const select = APT::VersionList::CANDIDATE;
  84. APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper);
  85. for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver)
  86. if (DisplayRecord(CacheFile, Ver, c1out) == false)
  87. return false;
  88. for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
  89. Pkg != helper.virtualPkgs.end(); ++Pkg)
  90. {
  91. c1out << "Package: " << Pkg.FullName(true) << std::endl;
  92. c1out << "State: " << _("not a real pacakge (virtual)") << std::endl;
  93. // FIXME: show providers, see private-cacheset.h
  94. // CacheSetHelperAPTGet::showVirtualPackageErrors()
  95. }
  96. if (verset.empty() == true)
  97. {
  98. if (helper.virtualPkgs.empty() == true)
  99. return _error->Error(_("No packages found"));
  100. else
  101. _error->Notice(_("No packages found"));
  102. }
  103. return true;
  104. }
  105. /*}}}*/
  106. } // namespace Cmd
  107. } // namespace APT