apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

private-depends.cc
Go to the documentation of this file.
1 // Include Files /*{{{*/
2 #include <config.h>
3 
4 #include <apt-pkg/algorithms.h>
5 #include <apt-pkg/cachefile.h>
6 #include <apt-pkg/cacheset.h>
7 #include <apt-pkg/cmndline.h>
8 #include <apt-pkg/configuration.h>
9 #include <apt-pkg/error.h>
10 #include <apt-pkg/pkgcache.h>
11 
14 
15 #include <iostream>
16 #include <string>
17 #include <vector>
18 
19 #include <stddef.h>
20 
21 #include <apti18n.h>
22  /*}}}*/
23 
24 // ShowDepends - Helper for printing out a dependency tree /*{{{*/
25 static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
26 {
28  pkgCache * const Cache = CacheFile.GetPkgCache();
29  if (unlikely(Cache == nullptr || CacheFile.GetDepCache() == nullptr))
30  return false;
31 
32  CacheSetHelperVirtuals helper(false);
34  if (verset.empty() == true && helper.virtualPkgs.empty() == true)
35  return _error->Error(_("No packages found"));
36  std::vector<bool> Shown(Cache->Head().PackageCount);
37 
38  bool const Recurse = _config->FindB("APT::Cache::RecurseDepends", false);
39  bool const Installed = _config->FindB("APT::Cache::Installed", false);
40  bool const Important = _config->FindB("APT::Cache::Important", false);
41  bool const ShowDepType = _config->FindB("APT::Cache::ShowDependencyType", RevDepends == false);
42  bool const ShowVersion = _config->FindB("APT::Cache::ShowVersion", false);
43  bool const ShowPreDepends = _config->FindB("APT::Cache::ShowPre-Depends", true);
44  bool const ShowDepends = _config->FindB("APT::Cache::ShowDepends", true);
45  bool const ShowRecommends = _config->FindB("APT::Cache::ShowRecommends", Important == false);
46  bool const ShowSuggests = _config->FindB("APT::Cache::ShowSuggests", Important == false);
47  bool const ShowReplaces = _config->FindB("APT::Cache::ShowReplaces", Important == false);
48  bool const ShowConflicts = _config->FindB("APT::Cache::ShowConflicts", Important == false);
49  bool const ShowBreaks = _config->FindB("APT::Cache::ShowBreaks", Important == false);
50  bool const ShowEnhances = _config->FindB("APT::Cache::ShowEnhances", Important == false);
51  bool const ShowOnlyFirstOr = _config->FindB("APT::Cache::ShowOnlyFirstOr", false);
52  bool const ShowImplicit = _config->FindB("APT::Cache::ShowImplicit", false);
53 
54  while (verset.empty() != true)
55  {
56  pkgCache::VerIterator Ver = *verset.begin();
57  verset.erase(verset.begin());
58  pkgCache::PkgIterator Pkg = Ver.ParentPkg();
59  Shown[Pkg->ID] = true;
60 
61  std::cout << Pkg.FullName(true) << std::endl;
62 
63  if (RevDepends == true)
64  std::cout << "Reverse Depends:" << std::endl;
65  for (pkgCache::DepIterator D = RevDepends ? Pkg.RevDependsList() : Ver.DependsList();
66  D.end() == false; ++D)
67  {
68  switch (D->Type) {
69  case pkgCache::Dep::PreDepends: if (!ShowPreDepends) continue; break;
70  case pkgCache::Dep::Depends: if (!ShowDepends) continue; break;
71  case pkgCache::Dep::Recommends: if (!ShowRecommends) continue; break;
72  case pkgCache::Dep::Suggests: if (!ShowSuggests) continue; break;
73  case pkgCache::Dep::Replaces: if (!ShowReplaces) continue; break;
74  case pkgCache::Dep::Conflicts: if (!ShowConflicts) continue; break;
75  case pkgCache::Dep::DpkgBreaks: if (!ShowBreaks) continue; break;
76  case pkgCache::Dep::Enhances: if (!ShowEnhances) continue; break;
77  }
78  if (ShowImplicit == false && D.IsImplicit())
79  continue;
80 
81  pkgCache::PkgIterator Trg = RevDepends ? D.ParentPkg() : D.TargetPkg();
82 
83  if((Installed && Trg->CurrentVer != 0) || !Installed)
84  {
85 
86  if ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or && ShowOnlyFirstOr == false)
87  std::cout << " |";
88  else
89  std::cout << " ";
90 
91  // Show the package
92  if (ShowDepType == true)
93  std::cout << D.DepType() << ": ";
94  if (Trg->VersionList == 0)
95  std::cout << "<" << Trg.FullName(true) << ">";
96  else
97  std::cout << Trg.FullName(true);
98  if (ShowVersion == true && D->Version != 0)
99  std::cout << " (" << pkgCache::CompTypeDeb(D->CompareOp) << ' ' << D.TargetVer() << ')';
100  std::cout << std::endl;
101 
102  if (Recurse == true && Shown[Trg->ID] == false)
103  {
104  Shown[Trg->ID] = true;
106  }
107 
108  // Display all solutions
109  std::unique_ptr<pkgCache::Version *[]> List(D.AllTargets());
110  pkgPrioSortList(*Cache,List.get());
111  for (pkgCache::Version **I = List.get(); *I != 0; I++)
112  {
113  pkgCache::VerIterator V(*Cache,*I);
114  if (V != Cache->VerP + V.ParentPkg()->VersionList ||
115  V->ParentPkg == D->Package)
116  continue;
117  std::cout << " " << V.ParentPkg().FullName(true) << std::endl;
118 
119  if (Recurse == true && Shown[V.ParentPkg()->ID] == false)
120  {
121  Shown[V.ParentPkg()->ID] = true;
123  }
124  }
125 
126  }
127 
128  if (ShowOnlyFirstOr == true)
129  while ((D->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) ++D;
130  }
131  }
132 
134  Pkg != helper.virtualPkgs.end(); ++Pkg)
135  std::cout << '<' << Pkg.FullName(true) << '>' << std::endl;
136 
137  return true;
138 }
139  /*}}}*/
140 // Depends - Print out a dependency tree /*{{{*/
141 bool Depends(CommandLine &CmdL)
142 {
143  return ShowDepends(CmdL, false);
144 }
145  /*}}}*/
146 // RDepends - Print out a reverse dependency tree /*{{{*/
148 {
149  return ShowDepends(CmdL, true);
150 }
151  /*}}}*/
static bool std::string const metaIndex const *const pkgAcqMetaClearSig *const pkgAcquire::Item *const I
void pkgPrioSortList(pkgCache &Cache, pkgCache::Version **List)
Definition: algorithms.cc:1448
bool empty() const APT_OVERRIDE
Definition: cacheset.h:361
const_iterator begin() const
Definition: cacheset.h:371
const_iterator end() const
Definition: cacheset.h:372
bool empty() const APT_OVERRIDE
Definition: cacheset.h:815
static VersionContainer FromPackage(pkgCacheFile &Cache, pkgCache::PkgIterator const &P, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper)
returns all versions specified for the package
Definition: cacheset.h:907
const_iterator begin() const
Definition: cacheset.h:825
static VersionContainer FromCommandLine(pkgCacheFile &Cache, const char **cmdline, CacheSetHelper::VerSelector const fallback, CacheSetHelper &helper)
returns all versions specified on the commandline
Definition: cacheset.h:870
bool insert(pkgCache::VerIterator const &V) APT_OVERRIDE
Definition: cacheset.h:812
iterator erase(iterator pos)
Definition: cacheset.h:822
APT::PackageSet virtualPkgs
const char ** FileList
Definition: cmndline.h:78
bool FindB(const char *Name, bool const &Default=false) const
pkgDepCache * GetDepCache()
Definition: cachefile.h:74
pkgCache * GetPkgCache()
Definition: cachefile.h:73
static const char * CompTypeDeb(unsigned char Comp) APT_PURE
Definition: pkgcache.cc:317
Configuration * _config
pkgCache - Structure definitions for the cache file
bool RDepends(CommandLine &CmdL)
static bool ShowDepends(CommandLine &CmdL, bool const RevDepends)
bool Depends(CommandLine &CmdL)
map_pointer< pkgCache::Package > & Package
information for a single version of a package
Definition: pkgcache.h:625