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