]>
git.saurik.com Git - apt.git/blob - apt-private/private-show.cc
244347421eb9ff9eb813a22fff7e21f6f71f7214
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"
32 // DisplayRecord - Displays the complete record for the package /*{{{*/
33 // ---------------------------------------------------------------------
34 bool DisplayRecord ( pkgCacheFile
& CacheFile
, pkgCache :: VerIterator V
,
37 pkgCache
* Cache
= CacheFile
. GetPkgCache ();
38 if ( unlikely ( Cache
== NULL
))
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 )
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 ());
56 if ( PkgF
. Open ( I
. FileName (), FileFd :: ReadOnly
, FileFd :: Extension
) == false )
59 pkgTagFile
TagF (& PkgF
);
61 if ( TagF
. Jump ( Tags
, V
. FileList ()-> Offset
) == false )
62 return _error
-> Error ( "Internal Error, Unable to parse a package record" );
65 std :: string installed_size
;
66 if ( Tags
. FindI ( "Installed-Size" ) > 0 )
67 installed_size
= SizeToStr ( Tags
. FindI ( "Installed-Size" )* 1024 );
69 installed_size
= _ ( "unknown" );
70 std :: string package_size
;
71 if ( Tags
. FindI ( "Size" ) > 0 )
72 package_size
= SizeToStr ( Tags
. FindI ( "Size" ));
74 package_size
= _ ( "unknown" );
76 std :: string suite
= GetArchiveSuite ( CacheFile
, V
);
77 TFRewriteData RW
[] = {
80 { "Description-md5" , 0 },
81 { "Installed-Size" , installed_size
. c_str (), 0 },
82 { "Size" , package_size
. c_str (), "Download-Size" },
83 { "Archive-Origin" , suite
. c_str (), 0 },
86 if ( TFRewrite ( stdout
, Tags
, NULL
, RW
) == false )
87 return _error
-> Error ( "Internal Error, Unable to parse a package record" );
89 // write the description
90 pkgRecords
Recs (* Cache
);
91 // FIXME: show (optionally) all available translations(?)
92 pkgCache :: DescIterator Desc
= V
. TranslatedDescription ();
93 if ( Desc
. end () == false )
95 pkgRecords :: Parser
& P
= Recs
. Lookup ( Desc
. FileList ());
96 out
<< "Description: " << P
. LongDesc ();
99 // write a final newline (after the description)
100 out
<< std :: endl
<< std :: endl
;
105 bool ShowPackage ( CommandLine
& CmdL
) /*{{{*/
107 pkgCacheFile CacheFile
;
108 CacheSetHelperVirtuals
helper ( true , GlobalError :: NOTICE
);
109 APT :: VersionList :: Version
const select
= _config
-> FindB ( "APT::Cache::AllVersions" , false ) ?
110 APT :: VersionList :: ALL
: APT :: VersionList :: CANDIDATE
;
111 APT :: VersionList
const verset
= APT :: VersionList :: FromCommandLine ( CacheFile
, CmdL
. FileList
+ 1 , select
, helper
);
112 for ( APT :: VersionList :: const_iterator Ver
= verset
. begin (); Ver
!= verset
. end (); ++ Ver
)
113 if ( DisplayRecord ( CacheFile
, Ver
, c1out
) == false )
116 if ( select
== APT :: VersionList :: CANDIDATE
)
118 APT :: VersionList
const verset_all
= APT :: VersionList :: FromCommandLine ( CacheFile
, CmdL
. FileList
+ 1 , APT :: VersionList :: ALL
, helper
);
119 if ( verset_all
. size () > verset
. size ())
120 _error
-> Notice ( ngettext ( "There is %l u additional record. Please use the '-a' switch to see it" , "There are %l u additional records. Please use the '-a' switch to see them." , verset_all
. size () - verset
. size ()), verset_all
. size () - verset
. size ());
123 for ( APT :: PackageSet :: const_iterator Pkg
= helper
. virtualPkgs
. begin ();
124 Pkg
!= helper
. virtualPkgs
. end (); ++ Pkg
)
126 c1out
<< "Package: " << Pkg
. FullName ( true ) << std :: endl
;
127 c1out
<< "State: " << _ ( "not a real package (virtual)" ) << std :: endl
;
128 // FIXME: show providers, see private-cacheset.h
129 // CacheSetHelperAPTGet::showVirtualPackageErrors()
132 if ( verset
. empty () == true )
134 if ( helper
. virtualPkgs
. empty () == true )
135 return _error
-> Error ( _ ( "No packages found" ));
137 _error
-> Notice ( _ ( "No packages found" ));