]> git.saurik.com Git - apt.git/blame - apt-private/private-show.cc
first version with test
[apt.git] / apt-private / private-show.cc
CommitLineData
ee0167c4 1// Includes /*{{{*/
b9179170
MV
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
23#include <apti18n.h>
24
25#include "private-output.h"
26#include "private-cacheset.h"
ee0167c4 27 /*}}}*/
b9179170
MV
28
29namespace APT {
30 namespace Cmd {
31
32// DisplayRecord - Displays the complete record for the package /*{{{*/
33// ---------------------------------------------------------------------
34bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V,
35 ostream &out)
36{
37 pkgCache *Cache = CacheFile.GetPkgCache();
38 if (unlikely(Cache == NULL))
39 return false;
40
41 // Find an appropriate file
42 pkgCache::VerFileIterator Vf = V.FileList();
43 for (; Vf.end() == false; ++Vf)
44 if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
45 break;
46 if (Vf.end() == true)
47 Vf = V.FileList();
48
49 // Check and load the package list file
50 pkgCache::PkgFileIterator I = Vf.File();
51 if (I.IsOk() == false)
52 return _error->Error(_("Package file %s is out of sync."),I.FileName());
53
54 // Read the record
55 FileFd PkgF;
56 if (PkgF.Open(I.FileName(), FileFd::ReadOnly, FileFd::Extension) == false)
57 return false;
58 pkgTagSection Tags;
59 pkgTagFile TagF(&PkgF);
60
61 TFRewriteData RW[] = {
62 {"Conffiles",0},
63 {"Description",0},
64 {"Description-md5",0},
65 {}
66 };
67 const char *Zero = 0;
68 if (TagF.Jump(Tags, V.FileList()->Offset) == false ||
69 TFRewrite(stdout,Tags,&Zero,RW) == false)
70 {
71 _error->Error("Internal Error, Unable to parse a package record");
72 return false;
73 }
74
75 // write the description
76 pkgRecords Recs(*Cache);
77 pkgCache::DescIterator Desc = V.TranslatedDescription();
78 if (Desc.end() == false)
79 {
80 pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
81 if (strcmp(Desc.LanguageCode(),"") != 0)
82 out << "Description-lang: " << Desc.LanguageCode() << std::endl;
83 out << "Description" << P.LongDesc();
84 }
85
86 // write a final newline (after the description)
87 out << std::endl << std::endl;
88
89 return true;
90}
91 /*}}}*/
ee0167c4 92bool ShowPackage(CommandLine &CmdL) /*{{{*/
b9179170
MV
93{
94 pkgCacheFile CacheFile;
95 CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
96 APT::VersionList::Version const select = APT::VersionList::CANDIDATE;
97 APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper);
98 for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver)
99 if (DisplayRecord(CacheFile, Ver, c1out) == false)
100 return false;
101
102 for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
103 Pkg != helper.virtualPkgs.end(); ++Pkg)
104 {
105 c1out << "Package: " << Pkg.FullName(true) << std::endl;
ad1d6bfb 106 c1out << "State: " << _("not a real package (virtual)") << std::endl;
b9179170
MV
107 // FIXME: show providers, see private-cacheset.h
108 // CacheSetHelperAPTGet::showVirtualPackageErrors()
109 }
110
111 if (verset.empty() == true)
112 {
113 if (helper.virtualPkgs.empty() == true)
114 return _error->Error(_("No packages found"));
115 else
116 _error->Notice(_("No packages found"));
117 }
118
119 return true;
120}
121 /*}}}*/
122} // namespace Cmd
123} // namespace APT