honor option to disable pulses for the testcases
[ntk/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;
85d7c0eb
MV
40 pkgDepCache *depCache = CacheFile.GetDepCache();
41 if (unlikely(depCache == NULL))
42 return false;
b9179170
MV
43
44 // Find an appropriate file
45 pkgCache::VerFileIterator Vf = V.FileList();
46 for (; Vf.end() == false; ++Vf)
47 if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
48 break;
49 if (Vf.end() == true)
50 Vf = V.FileList();
51
52 // Check and load the package list file
53 pkgCache::PkgFileIterator I = Vf.File();
54 if (I.IsOk() == false)
55 return _error->Error(_("Package file %s is out of sync."),I.FileName());
56
1179953a
MV
57 // find matching sources.list metaindex
58 pkgSourceList *SrcList = CacheFile.GetSourceList();
59 pkgIndexFile *Index;
60 if (SrcList->FindIndex(I, Index) == false &&
61 _system->FindIndex(I, Index) == false)
62 return _error->Error("Can not find indexfile for Package %s (%s)",
63 V.ParentPkg().Name(), V.VerStr());
64 std::string source_index_file = Index->Describe(true);
65
b9179170
MV
66 // Read the record
67 FileFd PkgF;
68 if (PkgF.Open(I.FileName(), FileFd::ReadOnly, FileFd::Extension) == false)
69 return false;
70 pkgTagSection Tags;
71 pkgTagFile TagF(&PkgF);
9e51c0b6
MV
72
73 if (TagF.Jump(Tags, V.FileList()->Offset) == false)
74 return _error->Error("Internal Error, Unable to parse a package record");
75
76 // make size nice
77 std::string installed_size;
78 if (Tags.FindI("Installed-Size") > 0)
17622532 79 strprintf(installed_size, "%sB", SizeToStr(Tags.FindI("Installed-Size")*1024).c_str());
9e51c0b6
MV
80 else
81 installed_size = _("unknown");
82 std::string package_size;
83 if (Tags.FindI("Size") > 0)
17622532 84 strprintf(package_size, "%sB", SizeToStr(Tags.FindI("Size")).c_str());
9e51c0b6
MV
85 else
86 package_size = _("unknown");
87
85d7c0eb
MV
88 pkgDepCache::StateCache &state = (*depCache)[V.ParentPkg()];
89 bool is_installed = V.ParentPkg().CurrentVer() == V;
90 const char *manual_installed;
91 if (is_installed)
92 manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no";
93 else
94 manual_installed = 0;
17622532
MV
95
96 // FIXME: add verbose that does not do the removal of the tags?
b9179170 97 TFRewriteData RW[] = {
17622532
MV
98 // delete, apt-cache show has this info and most users do not care
99 {"MD5sum", 0},
100 {"SHA1", 0},
101 {"SHA256", 0},
102 {"Filename", 0},
103 {"Multi-Arch", 0},
104 {"Architecture", 0},
b9179170 105 {"Conffiles",0},
17622532 106 // we use the translated description
b9179170
MV
107 {"Description",0},
108 {"Description-md5",0},
1179953a 109 // improve
9e51c0b6
MV
110 {"Installed-Size", installed_size.c_str(), 0},
111 {"Size", package_size.c_str(), "Download-Size"},
1179953a
MV
112 // add
113 {"APT-Manual-Installed", manual_installed, 0},
114 {"APT-Sources", source_index_file.c_str(), 0},
b9179170
MV
115 {}
116 };
85d7c0eb 117
9e51c0b6
MV
118 if(TFRewrite(stdout, Tags, NULL, RW) == false)
119 return _error->Error("Internal Error, Unable to parse a package record");
b9179170
MV
120
121 // write the description
122 pkgRecords Recs(*Cache);
2a79257e 123 // FIXME: show (optionally) all available translations(?)
b9179170
MV
124 pkgCache::DescIterator Desc = V.TranslatedDescription();
125 if (Desc.end() == false)
126 {
127 pkgRecords::Parser &P = Recs.Lookup(Desc.FileList());
2a79257e 128 out << "Description: " << P.LongDesc();
b9179170
MV
129 }
130
131 // write a final newline (after the description)
132 out << std::endl << std::endl;
133
134 return true;
135}
136 /*}}}*/
ee0167c4 137bool ShowPackage(CommandLine &CmdL) /*{{{*/
b9179170
MV
138{
139 pkgCacheFile CacheFile;
140 CacheSetHelperVirtuals helper(true, GlobalError::NOTICE);
06293aa7
MV
141 APT::VersionList::Version const select = _config->FindB("APT::Cache::AllVersions", false) ?
142 APT::VersionList::ALL : APT::VersionList::CANDIDATE;
b9179170
MV
143 APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper);
144 for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver)
145 if (DisplayRecord(CacheFile, Ver, c1out) == false)
146 return false;
147
06293aa7
MV
148 if (select == APT::VersionList::CANDIDATE)
149 {
150 APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionList::ALL, helper);
151 if (verset_all.size() > verset.size())
152 _error->Notice(ngettext("There is %lu additional record. Please use the '-a' switch to see it", "There are %lu additional records. Please use the '-a' switch to see them.", verset_all.size() - verset.size()), verset_all.size() - verset.size());
153 }
154
b9179170
MV
155 for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin();
156 Pkg != helper.virtualPkgs.end(); ++Pkg)
157 {
158 c1out << "Package: " << Pkg.FullName(true) << std::endl;
ad1d6bfb 159 c1out << "State: " << _("not a real package (virtual)") << std::endl;
b9179170
MV
160 // FIXME: show providers, see private-cacheset.h
161 // CacheSetHelperAPTGet::showVirtualPackageErrors()
162 }
163
164 if (verset.empty() == true)
165 {
166 if (helper.virtualPkgs.empty() == true)
167 return _error->Error(_("No packages found"));
168 else
169 _error->Notice(_("No packages found"));
170 }
171
172 return true;
173}
174 /*}}}*/
175} // namespace Cmd
176} // namespace APT