From 9e51c0b6a3a1a36336820eda11bcfd5534d9d80c Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 22 Jan 2014 17:18:26 +0100 Subject: "apt show" show user friendly size info The size/installed-size is displayed via SizeToStr() and Size is rewriten to "Download-Size" to make clear what size is refered to here. --- apt-pkg/tagfile.cc | 84 +++++++++++++++++++------------------- apt-private/private-show.cc | 28 +++++++++---- test/integration/test-apt-cli-show | 3 +- 3 files changed, 65 insertions(+), 50 deletions(-) diff --git a/apt-pkg/tagfile.cc b/apt-pkg/tagfile.cc index bef3c76ba..b92b2c15a 100644 --- a/apt-pkg/tagfile.cc +++ b/apt-pkg/tagfile.cc @@ -567,52 +567,54 @@ bool TFRewrite(FILE *Output,pkgTagSection const &Tags,const char *Order[], } // Write all all of the tags, in order. - for (unsigned int I = 0; Order[I] != 0; I++) + if (Order != NULL) { - bool Rewritten = false; - - // See if this is a field that needs to be rewritten - for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++) + for (unsigned int I = 0; Order[I] != 0; I++) { - if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0) - { - Visited[J] |= 2; - if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0) - { - if (isspace(Rewrite[J].Rewrite[0])) - fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); - else - fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); - } - - Rewritten = true; - break; - } - } + bool Rewritten = false; + + // See if this is a field that needs to be rewritten + for (unsigned int J = 0; Rewrite != 0 && Rewrite[J].Tag != 0; J++) + { + if (strcasecmp(Rewrite[J].Tag,Order[I]) == 0) + { + Visited[J] |= 2; + if (Rewrite[J].Rewrite != 0 && Rewrite[J].Rewrite[0] != 0) + { + if (isspace(Rewrite[J].Rewrite[0])) + fprintf(Output,"%s:%s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); + else + fprintf(Output,"%s: %s\n",Rewrite[J].NewTag,Rewrite[J].Rewrite); + } + Rewritten = true; + break; + } + } - // See if it is in the fragment - unsigned Pos; - if (Tags.Find(Order[I],Pos) == false) - continue; - Visited[Pos] |= 1; - - if (Rewritten == true) - continue; + // See if it is in the fragment + unsigned Pos; + if (Tags.Find(Order[I],Pos) == false) + continue; + Visited[Pos] |= 1; + + if (Rewritten == true) + continue; - /* Write out this element, taking a moment to rewrite the tag - in case of changes of case. */ - const char *Start; - const char *Stop; - Tags.Get(Start,Stop,Pos); + /* Write out this element, taking a moment to rewrite the tag + in case of changes of case. */ + const char *Start; + const char *Stop; + Tags.Get(Start,Stop,Pos); - if (fputs(Order[I],Output) < 0) - return _error->Errno("fputs","IO Error to output"); - Start += strlen(Order[I]); - if (fwrite(Start,Stop - Start,1,Output) != 1) - return _error->Errno("fwrite","IO Error to output"); - if (Stop[-1] != '\n') - fprintf(Output,"\n"); - } + if (fputs(Order[I],Output) < 0) + return _error->Errno("fputs","IO Error to output"); + Start += strlen(Order[I]); + if (fwrite(Start,Stop - Start,1,Output) != 1) + return _error->Errno("fwrite","IO Error to output"); + if (Stop[-1] != '\n') + fprintf(Output,"\n"); + } + } // Now write all the old tags that were missed. for (unsigned int I = 0; I != Tags.Count(); I++) diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 0aa42ecce..32a49cc5c 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -57,20 +57,32 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, return false; pkgTagSection Tags; pkgTagFile TagF(&PkgF); - + + if (TagF.Jump(Tags, V.FileList()->Offset) == false) + return _error->Error("Internal Error, Unable to parse a package record"); + + // make size nice + std::string installed_size; + if (Tags.FindI("Installed-Size") > 0) + installed_size = SizeToStr(Tags.FindI("Installed-Size")*1024); + else + installed_size = _("unknown"); + std::string package_size; + if (Tags.FindI("Size") > 0) + package_size = SizeToStr(Tags.FindI("Size")); + else + package_size = _("unknown"); + TFRewriteData RW[] = { {"Conffiles",0}, {"Description",0}, {"Description-md5",0}, + {"Installed-Size", installed_size.c_str(), 0}, + {"Size", package_size.c_str(), "Download-Size"}, {} }; - const char *Zero = 0; - if (TagF.Jump(Tags, V.FileList()->Offset) == false || - TFRewrite(stdout,Tags,&Zero,RW) == false) - { - _error->Error("Internal Error, Unable to parse a package record"); - return false; - } + if(TFRewrite(stdout, Tags, NULL, RW) == false) + return _error->Error("Internal Error, Unable to parse a package record"); // write the description pkgRecords Recs(*Cache); diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show index 0ab3d2e56..bbb2de7ef 100755 --- a/test/integration/test-apt-cli-show +++ b/test/integration/test-apt-cli-show @@ -19,11 +19,12 @@ APTARCHIVE=$(readlink -f ./aptarchive) testequal "Package: foo Priority: optional Section: other -Installed-Size: 42 +Installed-Size: 43.0 k Maintainer: Joe Sixpack Architecture: all Version: 1.0 Filename: pool/main/foo/foo_1.0_all.deb +Download-Size: unknown Description: Some description That has multiple lines " apt show foo -- cgit v1.2.3 From 06293aa79b46efdec96910b2f678ce1cbdecc86d Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 23 Jan 2014 07:52:23 +0100 Subject: Show only the candidate with "apt show" Display only the candidate version with "apt show pkg" but show a notice that there is more to see. --- apt-private/private-cmndline.cc | 4 ++++ apt-private/private-show.cc | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apt-private/private-cmndline.cc b/apt-private/private-cmndline.cc index cbb40d42e..2b6c710d6 100644 --- a/apt-private/private-cmndline.cc +++ b/apt-private/private-cmndline.cc @@ -235,6 +235,10 @@ bool addArgumentsAPT(std::vector &Args, char const * const Cm // FIXME: find a better term addArg(0,"dist","APT::Cmd::Dist-Upgrade", CommandLine::Boolean); } + else if (CmdMatches("show")) + { + addArg('a', "all-versions", "APT::Cache::AllVersions", 0); + } else if (addArgumentsAPTGet(Args, Cmd) || addArgumentsAPTCache(Args, Cmd)) { // we have no (supported) command-name overlaps so far, so we call diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 32a49cc5c..9a8386167 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -104,12 +104,20 @@ bool ShowPackage(CommandLine &CmdL) /*{{{*/ { pkgCacheFile CacheFile; CacheSetHelperVirtuals helper(true, GlobalError::NOTICE); - APT::VersionList::Version const select = APT::VersionList::CANDIDATE; + APT::VersionList::Version const select = _config->FindB("APT::Cache::AllVersions", false) ? + APT::VersionList::ALL : APT::VersionList::CANDIDATE; APT::VersionList const verset = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, select, helper); for (APT::VersionList::const_iterator Ver = verset.begin(); Ver != verset.end(); ++Ver) if (DisplayRecord(CacheFile, Ver, c1out) == false) return false; + if (select == APT::VersionList::CANDIDATE) + { + APT::VersionList const verset_all = APT::VersionList::FromCommandLine(CacheFile, CmdL.FileList + 1, APT::VersionList::ALL, helper); + if (verset_all.size() > verset.size()) + _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()); + } + for (APT::PackageSet::const_iterator Pkg = helper.virtualPkgs.begin(); Pkg != helper.virtualPkgs.end(); ++Pkg) { -- cgit v1.2.3 From 0c8b6001694bb0ddf9eb6bc4936151592e1a07fa Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Thu, 23 Jan 2014 08:12:02 +0100 Subject: include "Archive-Origin" in the apt show output --- apt-private/private-output.h | 6 +++++- apt-private/private-show.cc | 2 ++ test/integration/test-apt-cli-show | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apt-private/private-output.h b/apt-private/private-output.h index c3c76bb92..ba04ee221 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -28,7 +28,7 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, bool include_summary=true); - +// helper to describe global state bool ShowList(std::ostream &out, std::string Title, std::string List, std::string VersionsList); void ShowBroken(std::ostream &out,CacheFile &Cache,bool Now); @@ -43,6 +43,10 @@ bool ShowEssential(std::ostream &out,CacheFile &Cache); void Stats(std::ostream &out, pkgDepCache &Dep); +// helpers to display single package data +std::string +GetArchiveSuite(pkgCacheFile &CacheFile, pkgCache::VerIterator ver); + // prompting bool YnPrompt(bool Default=true); bool AnalPrompt(const char *Text); diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 9a8386167..244347421 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -73,12 +73,14 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, else package_size = _("unknown"); + std::string suite = GetArchiveSuite(CacheFile, V); TFRewriteData RW[] = { {"Conffiles",0}, {"Description",0}, {"Description-md5",0}, {"Installed-Size", installed_size.c_str(), 0}, {"Size", package_size.c_str(), "Download-Size"}, + {"Archive-Origin", suite.c_str(), 0}, {} }; if(TFRewrite(stdout, Tags, NULL, RW) == false) diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show index bbb2de7ef..ba56e3260 100755 --- a/test/integration/test-apt-cli-show +++ b/test/integration/test-apt-cli-show @@ -25,6 +25,7 @@ Architecture: all Version: 1.0 Filename: pool/main/foo/foo_1.0_all.deb Download-Size: unknown +Archive-Origin: unstable Description: Some description That has multiple lines " apt show foo -- cgit v1.2.3 From 85d7c0eb60efd0de13ad331676b6227f52bed6c6 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 24 Jan 2014 21:03:49 +0100 Subject: Show "Manual-Installed: {yes|no}" in apt show --- apt-private/private-show.cc | 12 ++++++++++++ test/integration/test-apt-cli-show | 5 ++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index 244347421..cee132843 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -37,6 +37,9 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, pkgCache *Cache = CacheFile.GetPkgCache(); if (unlikely(Cache == NULL)) return false; + pkgDepCache *depCache = CacheFile.GetDepCache(); + if (unlikely(depCache == NULL)) + return false; // Find an appropriate file pkgCache::VerFileIterator Vf = V.FileList(); @@ -73,6 +76,13 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, else package_size = _("unknown"); + pkgDepCache::StateCache &state = (*depCache)[V.ParentPkg()]; + bool is_installed = V.ParentPkg().CurrentVer() == V; + const char *manual_installed; + if (is_installed) + manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no"; + else + manual_installed = 0; std::string suite = GetArchiveSuite(CacheFile, V); TFRewriteData RW[] = { {"Conffiles",0}, @@ -81,8 +91,10 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, {"Installed-Size", installed_size.c_str(), 0}, {"Size", package_size.c_str(), "Download-Size"}, {"Archive-Origin", suite.c_str(), 0}, + {"Manual-Installed", manual_installed, 0}, {} }; + if(TFRewrite(stdout, Tags, NULL, RW) == false) return _error->Error("Internal Error, Unable to parse a package record"); diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show index ba56e3260..11a93f268 100755 --- a/test/integration/test-apt-cli-show +++ b/test/integration/test-apt-cli-show @@ -10,12 +10,14 @@ configarchitecture "i386" DESCR='Some description That has multiple lines' insertpackage 'unstable' 'foo' 'all' '1.0' '' '' "$DESCR" +insertinstalledpackage 'foo' 'all' '1.0' setupaptarchive APTARCHIVE=$(readlink -f ./aptarchive) # note that we do not display Description-md5 with the "apt" cmd +# and also show some additional fields that are calculated testequal "Package: foo Priority: optional Section: other @@ -25,7 +27,8 @@ Architecture: all Version: 1.0 Filename: pool/main/foo/foo_1.0_all.deb Download-Size: unknown -Archive-Origin: unstable +Archive-Origin: unstable,now +Manual-Installed: yes Description: Some description That has multiple lines " apt show foo -- cgit v1.2.3 From 1179953a0bbf82ba22a2692586ce4f1936b2bdc9 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 24 Jan 2014 21:17:07 +0100 Subject: show APT-Sources in apt show --- apt-private/private-output.h | 4 ---- apt-private/private-show.cc | 17 ++++++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/apt-private/private-output.h b/apt-private/private-output.h index ba04ee221..2a2a69458 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -43,10 +43,6 @@ bool ShowEssential(std::ostream &out,CacheFile &Cache); void Stats(std::ostream &out, pkgDepCache &Dep); -// helpers to display single package data -std::string -GetArchiveSuite(pkgCacheFile &CacheFile, pkgCache::VerIterator ver); - // prompting bool YnPrompt(bool Default=true); bool AnalPrompt(const char *Text); diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index cee132843..ba8b266ee 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -54,6 +54,15 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, if (I.IsOk() == false) return _error->Error(_("Package file %s is out of sync."),I.FileName()); + // find matching sources.list metaindex + pkgSourceList *SrcList = CacheFile.GetSourceList(); + pkgIndexFile *Index; + if (SrcList->FindIndex(I, Index) == false && + _system->FindIndex(I, Index) == false) + return _error->Error("Can not find indexfile for Package %s (%s)", + V.ParentPkg().Name(), V.VerStr()); + std::string source_index_file = Index->Describe(true); + // Read the record FileFd PkgF; if (PkgF.Open(I.FileName(), FileFd::ReadOnly, FileFd::Extension) == false) @@ -83,15 +92,17 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no"; else manual_installed = 0; - std::string suite = GetArchiveSuite(CacheFile, V); TFRewriteData RW[] = { + // delete {"Conffiles",0}, {"Description",0}, {"Description-md5",0}, + // improve {"Installed-Size", installed_size.c_str(), 0}, {"Size", package_size.c_str(), "Download-Size"}, - {"Archive-Origin", suite.c_str(), 0}, - {"Manual-Installed", manual_installed, 0}, + // add + {"APT-Manual-Installed", manual_installed, 0}, + {"APT-Sources", source_index_file.c_str(), 0}, {} }; -- cgit v1.2.3 From 17622532ce19a1bcebfebdfc9ec20a7e3df9dbff Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Fri, 24 Jan 2014 22:20:28 +0100 Subject: hide more from apt show Hide the Hashes,Filename,Multi-Arch,Architecture by default from "apt show". The information is still available via apt-cache show. Also improve the output of the Size- --- apt-private/private-show.cc | 15 ++++++++++++--- test/integration/test-apt-cli-show | 8 +++----- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apt-private/private-show.cc b/apt-private/private-show.cc index ba8b266ee..60d951316 100644 --- a/apt-private/private-show.cc +++ b/apt-private/private-show.cc @@ -76,12 +76,12 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, // make size nice std::string installed_size; if (Tags.FindI("Installed-Size") > 0) - installed_size = SizeToStr(Tags.FindI("Installed-Size")*1024); + strprintf(installed_size, "%sB", SizeToStr(Tags.FindI("Installed-Size")*1024).c_str()); else installed_size = _("unknown"); std::string package_size; if (Tags.FindI("Size") > 0) - package_size = SizeToStr(Tags.FindI("Size")); + strprintf(package_size, "%sB", SizeToStr(Tags.FindI("Size")).c_str()); else package_size = _("unknown"); @@ -92,9 +92,18 @@ bool DisplayRecord(pkgCacheFile &CacheFile, pkgCache::VerIterator V, manual_installed = !(state.Flags & pkgCache::Flag::Auto) ? "yes" : "no"; else manual_installed = 0; + + // FIXME: add verbose that does not do the removal of the tags? TFRewriteData RW[] = { - // delete + // delete, apt-cache show has this info and most users do not care + {"MD5sum", 0}, + {"SHA1", 0}, + {"SHA256", 0}, + {"Filename", 0}, + {"Multi-Arch", 0}, + {"Architecture", 0}, {"Conffiles",0}, + // we use the translated description {"Description",0}, {"Description-md5",0}, // improve diff --git a/test/integration/test-apt-cli-show b/test/integration/test-apt-cli-show index 11a93f268..91cc9a3c0 100755 --- a/test/integration/test-apt-cli-show +++ b/test/integration/test-apt-cli-show @@ -21,14 +21,12 @@ APTARCHIVE=$(readlink -f ./aptarchive) testequal "Package: foo Priority: optional Section: other -Installed-Size: 43.0 k +Installed-Size: 43.0 kB Maintainer: Joe Sixpack -Architecture: all Version: 1.0 -Filename: pool/main/foo/foo_1.0_all.deb Download-Size: unknown -Archive-Origin: unstable,now -Manual-Installed: yes +APT-Manual-Installed: yes +APT-Sources: file:$APTARCHIVE/ unstable/main i386 Packages Description: Some description That has multiple lines " apt show foo -- cgit v1.2.3