private-show.cc 3.7 KB

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