diff options
author | CoolStar <coolstarorganization@gmail.com> | 2018-12-20 15:11:31 -0800 |
---|---|---|
committer | Sam Bingner <sam@bingner.com> | 2019-12-26 15:24:12 -1000 |
commit | 8d1277b777045f45ffae210edea608c27587d7a2 (patch) | |
tree | 7e99593eea9e5e1c3167057f0ca77547c0e1993a /apt-private | |
parent | f500e1fbad17354e04e3c4af7295759dd599925f (diff) |
APT 1.7.0-sileo
Diffstat (limited to 'apt-private')
-rw-r--r-- | apt-private/private-output.cc | 150 |
1 files changed, 142 insertions, 8 deletions
diff --git a/apt-private/private-output.cc b/apt-private/private-output.cc index eb9a34abe..3c7e38c0e 100644 --- a/apt-private/private-output.cc +++ b/apt-private/private-output.cc @@ -328,17 +328,126 @@ void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records, /*{{{*/ Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed Depends: libsasl7 but it is not going to be installed */ -static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now) +static bool ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache::PkgIterator const &Pkg, bool const Now, bool const DisplaySeparator) { if (Now == true) { if ((*Cache)[Pkg].NowBroken() == false) - return; + return false; } else { if ((*Cache)[Pkg].InstBroken() == false) - return; + return false; + } + + bool useJSON = _config->FindB("APT::Format::for-sileo", false); + if (useJSON){ + if (DisplaySeparator) + out << ","; + + // Print out each package and the failed dependencies + out << "\"" << Pkg.FullName(true) << "\":["; + bool First = true; + pkgCache::VerIterator Ver; + + if (Now == true) + Ver = Pkg.CurrentVer(); + else + Ver = (*Cache)[Pkg].InstVerIter(*Cache); + + if (Ver.end() == true) + { + out << "]" << endl; + return true; + } + + for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) + { + // Compute a single dependency element (glob or) + pkgCache::DepIterator Start; + pkgCache::DepIterator End; + D.GlobOr(Start,End); // advances D + + if ((*Cache)->IsImportantDep(End) == false) + continue; + + if (Now == true) + { + if (((*Cache)[End] & pkgDepCache::DepGNow) == pkgDepCache::DepGNow) + continue; + } + else + { + if (((*Cache)[End] & pkgDepCache::DepGInstall) == pkgDepCache::DepGInstall) + continue; + } + + bool FirstOr = true; + while (1) + { + if (!First) + out << ","; + + First = false; + + if (FirstOr == false) + { + out << ","; + } + else + out << "["; + out << "{\"Type\":\"" << End.DepType() << "\""; + FirstOr = false; + + out << ",\"Package\":\"" << Start.TargetPkg().FullName(true) << "\""; + + // Show a quick summary of the version requirements + if (Start.TargetVer() != 0) + out << ",\"VersionSummary\":\"" << Start.CompType() << " " << Start.TargetVer() << "\""; + + /* Show a summary of the target package if possible. In the case + of virtual packages we show nothing */ + pkgCache::PkgIterator Targ = Start.TargetPkg(); + if (Targ->ProvidesList == 0) + { + pkgCache::VerIterator Ver = (*Cache)[Targ].InstVerIter(*Cache); + if (Now == true) + Ver = Targ.CurrentVer(); + + if (Ver.end() == false) + { + if (Now == true) + ioprintf(out,_(",\"Reason\":\"%s is installed\""),Ver.VerStr()); + else + ioprintf(out,_(",\"Reason\":\"%s is to be installed\""),Ver.VerStr()); + } + else + { + if ((*Cache)[Targ].CandidateVerIter(*Cache).end() == true) + { + if (Targ->ProvidesList == 0) + out << _(",\"Reason\":\"it is not installable\""); + else + out << _(",\"Reason\":\"it is a virtual package\""); + } + else + out << (Now?_(",\"Reason\":\"it is not installed\""):_(",\"Reason\":\"it is not going to be installed\"")); + } + } + + out << "}"; + + if (Start == End){ + out << "]"; + break; + } + ++Start; + } + } + out << "]"; + + return true; } // Print out each package and the failed dependencies @@ -355,7 +464,7 @@ static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache if (Ver.end() == true) { out << endl; - return; + return true; } for (pkgCache::DepIterator D = Ver.DependsList(); D.end() == false;) @@ -442,6 +551,7 @@ static void ShowBrokenPackage(ostream &out, pkgCacheFile * const Cache, pkgCache ++Start; } } + return true; } void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) { @@ -449,9 +559,21 @@ void ShowBroken(ostream &out, CacheFile &Cache, bool const Now) return; out << _("The following packages have unmet dependencies:") << endl; + + bool useJSON = _config->FindB("APT::Format::for-sileo", false); + if (useJSON) + out << "{"; + + bool DisplaySeparator = false; + SortedPackageUniverse Universe(Cache); - for (auto const &Pkg: Universe) - ShowBrokenPackage(out, &Cache, Pkg, Now); + for (auto const &Pkg: Universe){ + if (ShowBrokenPackage(out, &Cache, Pkg, Now, DisplaySeparator)) + DisplaySeparator = true; + } + + if (useJSON) + out << "}"; } void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) { @@ -459,9 +581,21 @@ void ShowBroken(ostream &out, pkgCacheFile &Cache, bool const Now) return; out << _("The following packages have unmet dependencies:") << endl; + + bool useJSON = _config->FindB("APT::Format::for-sileo", false); + if (useJSON) + out << "{"; + + bool DisplaySeparator = false; + APT::PackageUniverse Universe(Cache); - for (auto const &Pkg: Universe) - ShowBrokenPackage(out, &Cache, Pkg, Now); + for (auto const &Pkg: Universe){ + if (ShowBrokenPackage(out, &Cache, Pkg, Now, DisplaySeparator)) + DisplaySeparator = true; + } + + if (useJSON) + out << "}"; } /*}}}*/ // ShowNew - Show packages to newly install /*{{{*/ |