From c3b851268e6e900be2bf0bd715435db9010fd591 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Thu, 31 Mar 2011 15:10:13 +0200 Subject: =?UTF-8?q?rename=20edspwriter=20to=20straight=20edsp=20in=20tople?= =?UTF-8?q?vel=20as=20it=20does=20more=20than=20just=20writing=20stuff?= =?UTF-8?q?=E2=80=A6=20it=20also=20reads=20and=20can=20work=20for=20both:?= =?UTF-8?q?=20-=20APT=20talking=20to=20an=20external=20solver=20-=20an=20e?= =?UTF-8?q?xternal=20solver=20(understanding=20EDSP)=20talking=20to=20APT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apt-pkg/algorithms.cc | 8 +-- apt-pkg/edsp.cc | 160 +++++++++++++++++++++++++++++++++++++++++++++ apt-pkg/edsp.h | 32 +++++++++ apt-pkg/edsp/edspwriter.cc | 160 --------------------------------------------- apt-pkg/edsp/edspwriter.h | 32 --------- apt-pkg/makefile | 9 ++- 6 files changed, 200 insertions(+), 201 deletions(-) create mode 100644 apt-pkg/edsp.cc create mode 100644 apt-pkg/edsp.h delete mode 100644 apt-pkg/edsp/edspwriter.cc delete mode 100644 apt-pkg/edsp/edspwriter.h diff --git a/apt-pkg/algorithms.cc b/apt-pkg/algorithms.cc index b55ff2897..00f558420 100644 --- a/apt-pkg/algorithms.cc +++ b/apt-pkg/algorithms.cc @@ -20,7 +20,7 @@ #include #include #include -#include +#include #include #include @@ -743,15 +743,15 @@ bool pkgProblemResolver::Resolve(bool BrokenFix) if (solver != "internal") { FILE* output = fopen("/tmp/scenario.log", "w"); - edspWriter::WriteScenario(Cache, output); + EDSP::WriteScenario(Cache, output); fclose(output); output = fopen("/tmp/request.log", "w"); - edspWriter::WriteRequest(Cache, output); + EDSP::WriteRequest(Cache, output); fclose(output); if (ResolveInternal(BrokenFix) == false) return false; output = fopen("/tmp/solution.log", "w"); - edspWriter::WriteSolution(Cache, output); + EDSP::WriteSolution(Cache, output); fclose(output); return true; } diff --git a/apt-pkg/edsp.cc b/apt-pkg/edsp.cc new file mode 100644 index 000000000..1af5aed53 --- /dev/null +++ b/apt-pkg/edsp.cc @@ -0,0 +1,160 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + Set of methods to help writing and reading everything needed for EDSP + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include +#include +#include + +#include +#include + +#include + /*}}}*/ + +// EDSP::WriteScenario - to the given file descriptor /*{{{*/ +bool EDSP::WriteScenario(pkgDepCache &Cache, FILE* output) +{ + // we could use pkgCache::DepType and ::Priority, but these would be lokalized stringsā€¦ + const char * const PrioMap[] = {0, "important", "required", "standard", + "optional", "extra"}; + const char * const DepMap[] = {"", "Depends", "PreDepends", "Suggests", + "Recommends" , "Conflicts", "Replaces", + "Obsoletes", "Breaks", "Enhances"}; + + for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) + { + for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) + { + fprintf(output, "Package: %s\n", Pkg.Name()); + fprintf(output, "Architecture: %s\n", Ver.Arch()); + fprintf(output, "Version: %s\n", Ver.VerStr()); + if (Pkg.CurrentVer() == Ver) + fprintf(output, "Installed: yes\n"); + if (Pkg->SelectedState == pkgCache::State::Hold) + fprintf(output, "Hold: yes\n"); + fprintf(output, "APT-ID: %u\n", Ver->ID); + fprintf(output, "Priority: %s\n", PrioMap[Ver->Priority]); + if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) + fprintf(output, "Essential: yes\n"); + fprintf(output, "Section: %s\n", Ver.Section()); + if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed) + fprintf(output, "Multi-Arch: allowed\n"); + else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign) + fprintf(output, "Multi-Arch: foreign\n"); + else if (Ver->MultiArch == pkgCache::Version::Same) + fprintf(output, "Multi-Arch: same\n"); + signed short Pin = std::numeric_limits::min(); + for (pkgCache::VerFileIterator File = Ver.FileList(); File.end() == false; ++File) { + signed short const p = Cache.GetPolicy().GetPriority(File.File()); + if (Pin < p) + Pin = p; + } + fprintf(output, "APT-Pin: %d\n", Pin); + if (Cache.GetCandidateVer(Pkg) == Ver) + fprintf(output, "APT-Candidate: yes\n"); + if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto) + fprintf(output, "APT-Automatic: yes\n"); + std::string dependencies[pkgCache::Dep::Enhances + 1]; + bool orGroup = false; + for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) + { + // Ignore implicit dependencies for multiarch here + if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0) + continue; + if (orGroup == false) + dependencies[Dep->Type].append(", "); + dependencies[Dep->Type].append(Dep.TargetPkg().Name()); + if (Dep->Version != 0) + dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")"); + if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) + { + dependencies[Dep->Type].append(" | "); + orGroup = true; + } + else + orGroup = false; + } + for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i) + if (dependencies[i].empty() == false) + fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2); + string provides; + for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv) + { + // Ignore implicit provides for multiarch here + if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0) + continue; + provides.append(", ").append(Prv.Name()); + } + if (provides.empty() == false) + fprintf(output, "Provides: %s\n", provides.c_str()+2); + + + fprintf(output, "\n"); + } + } + return true; +} + /*}}}*/ +// EDSP::WriteRequest - to the given file descriptor /*{{{*/ +bool EDSP::WriteRequest(pkgDepCache &Cache, FILE* output) +{ + string del, inst, upgrade; + for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) + { + string* req; + if (Cache[Pkg].Delete() == true) + req = &del; + else if (Cache[Pkg].NewInstall() == true) + req = &inst; + else if (Cache[Pkg].Upgrade() == true) + req = &upgrade; + else + continue; + req->append(", ").append(Pkg.FullName()); + } + if (del.empty() == false) + fprintf(output, "Remove: %s\n", del.c_str()+2); + if (inst.empty() == false) + fprintf(output, "Install: %s\n", inst.c_str()+2); + if (upgrade.empty() == false) + fprintf(output, "Upgrade: %s\n", upgrade.c_str()+2); + + return true; +} + /*}}}*/ +bool EDSP::ReadResponse(FILE* input, pkgDepCache &Cache) { return false; } + +bool EDSP::ReadRequest(FILE* input, std::list &install, + std::list &remove) +{ return false; } +bool EDSP::ApplyRequest(std::list const &install, + std::list const &remove, + pkgDepCache &Cache) +{ return false; } +// EDSP::WriteSolution - to the given file descriptor /*{{{*/ +bool EDSP::WriteSolution(pkgDepCache &Cache, FILE* output) +{ + bool const Debug = _config->FindB("Debug::EDSPWriter::WriteSolution", false); + for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) + { + if (Cache[Pkg].Delete() == true) + fprintf(output, "Remove: %d\n", Cache.GetCandidateVer(Pkg)->ID); + else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true) + fprintf(output, "Install: %d\n", Cache.GetCandidateVer(Pkg)->ID); + else + continue; + if (Debug == true) + fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Cache.GetCandidateVer(Pkg).VerStr()); + fprintf(output, "\n"); + } + + return true; +} + /*}}}*/ +bool EDSP::WriteError(std::string const &message, FILE* output) { return false; } diff --git a/apt-pkg/edsp.h b/apt-pkg/edsp.h new file mode 100644 index 000000000..ef137b8f6 --- /dev/null +++ b/apt-pkg/edsp.h @@ -0,0 +1,32 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ###################################################################### + Set of methods to help writing and reading everything needed for EDSP + ##################################################################### */ + /*}}}*/ +#ifndef PKGLIB_EDSP_H +#define PKGLIB_EDSP_H + +#include + +#include + +class EDSP /*{{{*/ +{ +public: + bool static WriteRequest(pkgDepCache &Cache, FILE* output); + bool static WriteScenario(pkgDepCache &Cache, FILE* output); + bool static ReadResponse(FILE* input, pkgDepCache &Cache); + + // ReadScenario is provided by the listparser infrastructure + bool static ReadRequest(FILE* input, std::list &install, + std::list &remove); + bool static ApplyRequest(std::list const &install, + std::list const &remove, + pkgDepCache &Cache); + bool static WriteSolution(pkgDepCache &Cache, FILE* output); + bool static WriteError(std::string const &message, FILE* output); + +}; + /*}}}*/ +#endif diff --git a/apt-pkg/edsp/edspwriter.cc b/apt-pkg/edsp/edspwriter.cc deleted file mode 100644 index 2f6bde5a1..000000000 --- a/apt-pkg/edsp/edspwriter.cc +++ /dev/null @@ -1,160 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### - Set of methods to help writing and reading everything needed for EDSP - ##################################################################### */ - /*}}}*/ -// Include Files /*{{{*/ -#include -#include -#include -#include -#include - -#include -#include - -#include - /*}}}*/ - -// edspWriter::WriteScenario - to the given file descriptor /*{{{*/ -bool edspWriter::WriteScenario(pkgDepCache &Cache, FILE* output) -{ - // we could use pkgCache::DepType and ::Priority, but these would be lokalized stringsā€¦ - const char * const PrioMap[] = {0, "important", "required", "standard", - "optional", "extra"}; - const char * const DepMap[] = {"", "Depends", "PreDepends", "Suggests", - "Recommends" , "Conflicts", "Replaces", - "Obsoletes", "Breaks", "Enhances"}; - - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) - { - for (pkgCache::VerIterator Ver = Pkg.VersionList(); Ver.end() == false; ++Ver) - { - fprintf(output, "Package: %s\n", Pkg.Name()); - fprintf(output, "Architecture: %s\n", Ver.Arch()); - fprintf(output, "Version: %s\n", Ver.VerStr()); - if (Pkg.CurrentVer() == Ver) - fprintf(output, "Installed: yes\n"); - if (Pkg->SelectedState == pkgCache::State::Hold) - fprintf(output, "Hold: yes\n"); - fprintf(output, "APT-ID: %u\n", Ver->ID); - fprintf(output, "Priority: %s\n", PrioMap[Ver->Priority]); - if ((Pkg->Flags & pkgCache::Flag::Essential) == pkgCache::Flag::Essential) - fprintf(output, "Essential: yes\n"); - fprintf(output, "Section: %s\n", Ver.Section()); - if (Ver->MultiArch == pkgCache::Version::Allowed || Ver->MultiArch == pkgCache::Version::AllAllowed) - fprintf(output, "Multi-Arch: allowed\n"); - else if (Ver->MultiArch == pkgCache::Version::Foreign || Ver->MultiArch == pkgCache::Version::AllForeign) - fprintf(output, "Multi-Arch: foreign\n"); - else if (Ver->MultiArch == pkgCache::Version::Same) - fprintf(output, "Multi-Arch: same\n"); - signed short Pin = std::numeric_limits::min(); - for (pkgCache::VerFileIterator File = Ver.FileList(); File.end() == false; ++File) { - signed short const p = Cache.GetPolicy().GetPriority(File.File()); - if (Pin < p) - Pin = p; - } - fprintf(output, "APT-Pin: %d\n", Pin); - if (Cache.GetCandidateVer(Pkg) == Ver) - fprintf(output, "APT-Candidate: yes\n"); - if ((Cache[Pkg].Flags & pkgCache::Flag::Auto) == pkgCache::Flag::Auto) - fprintf(output, "APT-Automatic: yes\n"); - std::string dependencies[pkgCache::Dep::Enhances + 1]; - bool orGroup = false; - for (pkgCache::DepIterator Dep = Ver.DependsList(); Dep.end() == false; ++Dep) - { - // Ignore implicit dependencies for multiarch here - if (strcmp(Pkg.Arch(), Dep.TargetPkg().Arch()) != 0) - continue; - if (orGroup == false) - dependencies[Dep->Type].append(", "); - dependencies[Dep->Type].append(Dep.TargetPkg().Name()); - if (Dep->Version != 0) - dependencies[Dep->Type].append(" (").append(pkgCache::CompTypeDeb(Dep->CompareOp)).append(" ").append(Dep.TargetVer()).append(")"); - if ((Dep->CompareOp & pkgCache::Dep::Or) == pkgCache::Dep::Or) - { - dependencies[Dep->Type].append(" | "); - orGroup = true; - } - else - orGroup = false; - } - for (int i = 1; i < pkgCache::Dep::Enhances + 1; ++i) - if (dependencies[i].empty() == false) - fprintf(output, "%s: %s\n", DepMap[i], dependencies[i].c_str()+2); - string provides; - for (pkgCache::PrvIterator Prv = Ver.ProvidesList(); Prv.end() == false; ++Prv) - { - // Ignore implicit provides for multiarch here - if (strcmp(Pkg.Arch(), Prv.ParentPkg().Arch()) != 0 || strcmp(Pkg.Name(),Prv.Name()) == 0) - continue; - provides.append(", ").append(Prv.Name()); - } - if (provides.empty() == false) - fprintf(output, "Provides: %s\n", provides.c_str()+2); - - - fprintf(output, "\n"); - } - } - return true; -} - /*}}}*/ -// edspWriter::WriteRequest - to the given file descriptor /*{{{*/ -bool edspWriter::WriteRequest(pkgDepCache &Cache, FILE* output) -{ - string del, inst, upgrade; - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) - { - string* req; - if (Cache[Pkg].Delete() == true) - req = &del; - else if (Cache[Pkg].NewInstall() == true) - req = &inst; - else if (Cache[Pkg].Upgrade() == true) - req = &upgrade; - else - continue; - req->append(", ").append(Pkg.FullName()); - } - if (del.empty() == false) - fprintf(output, "Remove: %s\n", del.c_str()+2); - if (inst.empty() == false) - fprintf(output, "Install: %s\n", inst.c_str()+2); - if (upgrade.empty() == false) - fprintf(output, "Upgrade: %s\n", upgrade.c_str()+2); - - return true; -} - /*}}}*/ -bool edspWriter::ReadResponse(FILE* input, pkgDepCache &Cache) { return false; } - -bool edspWriter::ReadRequest(FILE* input, std::list &install, - std::list &remove) -{ return false; } -bool edspWriter::ApplyRequest(std::list const &install, - std::list const &remove, - pkgDepCache &Cache) -{ return false; } -// edspWriter::WriteSolution - to the given file descriptor /*{{{*/ -bool edspWriter::WriteSolution(pkgDepCache &Cache, FILE* output) -{ - bool const Debug = _config->FindB("Debug::EDSPWriter::WriteSolution", false); - for (pkgCache::PkgIterator Pkg = Cache.PkgBegin(); Pkg.end() == false; ++Pkg) - { - if (Cache[Pkg].Delete() == true) - fprintf(output, "Remove: %d\n", Cache.GetCandidateVer(Pkg)->ID); - else if (Cache[Pkg].NewInstall() == true || Cache[Pkg].Upgrade() == true) - fprintf(output, "Install: %d\n", Cache.GetCandidateVer(Pkg)->ID); - else - continue; - if (Debug == true) - fprintf(output, "Package: %s\nVersion: %s\n", Pkg.FullName().c_str(), Cache.GetCandidateVer(Pkg).VerStr()); - fprintf(output, "\n"); - } - - return true; -} - /*}}}*/ -bool edspWriter::WriteError(std::string const &message, FILE* output) { return false; } diff --git a/apt-pkg/edsp/edspwriter.h b/apt-pkg/edsp/edspwriter.h deleted file mode 100644 index c5eed788f..000000000 --- a/apt-pkg/edsp/edspwriter.h +++ /dev/null @@ -1,32 +0,0 @@ -// -*- mode: cpp; mode: fold -*- -// Description /*{{{*/ -/* ###################################################################### - Set of methods to help writing and reading everything needed for EDSP - ##################################################################### */ - /*}}}*/ -#ifndef PKGLIB_EDSPWRITER_H -#define PKGLIB_EDSPWRITER_H - -#include - -#include - -class edspWriter /*{{{*/ -{ -public: - bool static WriteRequest(pkgDepCache &Cache, FILE* output); - bool static WriteScenario(pkgDepCache &Cache, FILE* output); - bool static ReadResponse(FILE* input, pkgDepCache &Cache); - - // ReadScenario is provided by the listparser infrastructure - bool static ReadRequest(FILE* input, std::list &install, - std::list &remove); - bool static ApplyRequest(std::list const &install, - std::list const &remove, - pkgDepCache &Cache); - bool static WriteSolution(pkgDepCache &Cache, FILE* output); - bool static WriteError(std::string const &message, FILE* output); - -}; - /*}}}*/ -#endif diff --git a/apt-pkg/makefile b/apt-pkg/makefile index a7880e81c..e6bcf8524 100644 --- a/apt-pkg/makefile +++ b/apt-pkg/makefile @@ -35,7 +35,7 @@ SOURCE+= pkgcache.cc version.cc depcache.cc \ srcrecords.cc cachefile.cc versionmatch.cc policy.cc \ pkgsystem.cc indexfile.cc pkgcachegen.cc acquire-item.cc \ indexrecords.cc vendor.cc vendorlist.cc cdrom.cc indexcopy.cc \ - aptconfiguration.cc cachefilter.cc cacheset.cc + aptconfiguration.cc cachefilter.cc cacheset.cc edsp.cc HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \ orderlist.h sourcelist.h packagemanager.h tagfile.h \ init.h pkgcache.h version.h progress.h pkgrecords.h \ @@ -43,7 +43,7 @@ HEADERS+= algorithms.h depcache.h pkgcachegen.h cacheiterators.h \ clean.h srcrecords.h cachefile.h versionmatch.h policy.h \ pkgsystem.h indexfile.h metaindex.h indexrecords.h vendor.h \ vendorlist.h cdrom.h indexcopy.h aptconfiguration.h \ - cachefilter.h cacheset.h + cachefilter.h cacheset.h edsp.h # Source code for the debian specific components # In theory the deb headers do not need to be exported.. @@ -54,9 +54,8 @@ HEADERS+= debversion.h debsrcrecords.h dpkgpm.h debrecords.h \ deblistparser.h debsystem.h debindexfile.h debmetaindex.h # Source code for the APT resolver interface specific components -SOURCE+= edsp/edsplistparser.cc edsp/edspindexfile.cc edsp/edspsystem.cc \ - edsp/edspwriter.cc -HEADERS+= edsplistparser.h edspindexfile.h edspsystem.h edspwriter.h +SOURCE+= edsp/edsplistparser.cc edsp/edspindexfile.cc edsp/edspsystem.cc +HEADERS+= edsplistparser.h edspindexfile.h edspsystem.h HEADERS := $(addprefix apt-pkg/,$(HEADERS)) -- cgit v1.2.3