]>
git.saurik.com Git - apt.git/blob - apt-private/private-show.cc
94f944af19bf245cb3831a5b19c075d06f4b0941
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>
25 #include "private-output.h"
26 #include "private-cacheset.h"
27 #include "private-show.h"
33 // DisplayRecord - Displays the complete record for the package /*{{{*/
34 // ---------------------------------------------------------------------
35 static bool DisplayRecord ( pkgCacheFile
& CacheFile
, pkgCache :: VerIterator V
,
38 pkgCache
* Cache
= CacheFile
. GetPkgCache ();
39 if ( unlikely ( Cache
== NULL
))
41 pkgDepCache
* depCache
= CacheFile
. GetDepCache ();
42 if ( unlikely ( depCache
== NULL
))
45 // Find an appropriate file
46 pkgCache :: VerFileIterator Vf
= V
. FileList ();
47 for (; Vf
. end () == false ; ++ Vf
)
48 if (( Vf
. File ()-> Flags
& pkgCache :: Flag :: NotSource
) == 0 )
53 // Check and load the package list file
54 pkgCache :: PkgFileIterator I
= Vf
. File ();
55 if ( I
. IsOk () == false )
56 return _error
-> Error ( _ ( "Package file %s is out of sync." ), I
. FileName ());
58 // find matching sources.list metaindex
59 pkgSourceList
* SrcList
= CacheFile
. GetSourceList ();
61 if ( SrcList
-> FindIndex ( I
, Index
) == false &&
62 _system
-> FindIndex ( I
, Index
) == false )
63 return _error
-> Error ( "Can not find indexfile for Package %s ( %s )" ,
64 V
. ParentPkg (). Name (), V
. VerStr ());
65 std :: string source_index_file
= Index
-> Describe ( true );
69 if ( PkgF
. Open ( I
. FileName (), FileFd :: ReadOnly
, FileFd :: Extension
) == false )
72 pkgTagFile
TagF (& PkgF
);
74 if ( TagF
. Jump ( Tags
, V
. FileList ()-> Offset
) == false )
75 return _error
-> Error ( "Internal Error, Unable to parse a package record" );
78 std :: string installed_size
;
79 if ( Tags
. FindI ( "Installed-Size" ) > 0 )
80 strprintf ( installed_size
, " %s B" , SizeToStr ( Tags
. FindI ( "Installed-Size" )* 1024 ). c_str ());
82 installed_size
= _ ( "unknown" );
83 std :: string package_size
;
84 if ( Tags
. FindI ( "Size" ) > 0 )
85 strprintf ( package_size
, " %s B" , SizeToStr ( Tags
. FindI ( "Size" )). c_str ());
87 package_size
= _ ( "unknown" );
89 pkgDepCache :: StateCache
& state
= (* depCache
)[ V
. ParentPkg ()];
90 bool is_installed
= V
. ParentPkg (). CurrentVer () == V
;
91 const char * manual_installed
;
93 manual_installed
= !( state
. Flags
& pkgCache :: Flag :: Auto
) ? "yes" : "no" ;
97 // FIXME: add verbose that does not do the removal of the tags?
98 TFRewriteData RW
[] = {
99 // delete, apt-cache show has this info and most users do not care
100 { "MD5sum" , NULL
, NULL
},
101 { "SHA1" , NULL
, NULL
},
102 { "SHA256" , NULL
, NULL
},
103 { "Filename" , NULL
, NULL
},
104 { "Multi-Arch" , NULL
, NULL
},
105 { "Architecture" , NULL
, NULL
},
106 { "Conffiles" , NULL
, NULL
},
107 // we use the translated description
108 { "Description" , NULL
, NULL
},
109 { "Description-md5" , NULL
, NULL
},
111 { "Installed-Size" , installed_size
. c_str (), NULL
},
112 { "Size" , package_size
. c_str (), "Download-Size" },
114 { "APT-Manual-Installed" , manual_installed
, NULL
},
115 { "APT-Sources" , source_index_file
. c_str (), NULL
},
119 if ( TFRewrite ( stdout
, Tags
, NULL
, RW
) == false )
120 return _error
-> Error ( "Internal Error, Unable to parse a package record" );
122 // write the description
123 pkgRecords
Recs (* Cache
);
124 // FIXME: show (optionally) all available translations(?)
125 pkgCache :: DescIterator Desc
= V
. TranslatedDescription ();
126 if ( Desc
. end () == false )
128 pkgRecords :: Parser
& P
= Recs
. Lookup ( Desc
. FileList ());
129 out
<< "Description: " << P
. LongDesc ();
132 // write a final newline (after the description)
133 out
<< std :: endl
<< std :: endl
;
138 bool ShowPackage ( CommandLine
& CmdL
) /*{{{*/
140 pkgCacheFile CacheFile
;
141 CacheSetHelperVirtuals
helper ( true , GlobalError :: NOTICE
);
142 APT :: VersionList :: Version
const select
= _config
-> FindB ( "APT::Cache::AllVersions" , false ) ?
143 APT :: VersionList :: ALL
: APT :: VersionList :: CANDIDATE
;
144 APT :: VersionList
const verset
= APT :: VersionList :: FromCommandLine ( CacheFile
, CmdL
. FileList
+ 1 , select
, helper
);
145 for ( APT :: VersionList :: const_iterator Ver
= verset
. begin (); Ver
!= verset
. end (); ++ Ver
)
146 if ( DisplayRecord ( CacheFile
, Ver
, c1out
) == false )
149 if ( select
== APT :: VersionList :: CANDIDATE
)
151 APT :: VersionList
const verset_all
= APT :: VersionList :: FromCommandLine ( CacheFile
, CmdL
. FileList
+ 1 , APT :: VersionList :: ALL
, helper
);
152 int const records
= verset_all
. size () - verset
. size ();
154 _error
-> Notice ( P_ ( "There is %i additional record. Please use the '-a' switch to see it" , "There are %i additional records. Please use the '-a' switch to see them." , records
), records
);
157 for ( APT :: PackageSet :: const_iterator Pkg
= helper
. virtualPkgs
. begin ();
158 Pkg
!= helper
. virtualPkgs
. end (); ++ Pkg
)
160 c1out
<< "Package: " << Pkg
. FullName ( true ) << std :: endl
;
161 c1out
<< "State: " << _ ( "not a real package (virtual)" ) << std :: endl
;
162 // FIXME: show providers, see private-cacheset.h
163 // CacheSetHelperAPTGet::showVirtualPackageErrors()
166 if ( verset
. empty () == true )
168 if ( helper
. virtualPkgs
. empty () == true )
169 return _error
-> Error ( _ ( "No packages found" ));
171 _error
-> Notice ( _ ( "No packages found" ));