From 4128c84679e54e2afda7913946facaf9c52cd3eb Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Fri, 1 Apr 2011 16:14:24 +0200 Subject: add a small wrapper to use the internal apt solver as an external one --- cmdline/apt-internal-solver.cc | 129 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 cmdline/apt-internal-solver.cc (limited to 'cmdline/apt-internal-solver.cc') diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc new file mode 100644 index 000000000..83d79e42a --- /dev/null +++ b/cmdline/apt-internal-solver.cc @@ -0,0 +1,129 @@ +// -*- mode: cpp; mode: fold -*- +// Description /*{{{*/ +/* ##################################################################### + + cover around the internal solver to be able to run it like an external + + ##################################################################### */ + /*}}}*/ +// Include Files /*{{{*/ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + /*}}}*/ + +// ShowHelp - Show a help screen /*{{{*/ +// --------------------------------------------------------------------- +/* */ +bool ShowHelp(CommandLine &CmdL) { + ioprintf(std::cout,_("%s %s for %s compiled on %s %s\n"),PACKAGE,VERSION, + COMMON_ARCH,__DATE__,__TIME__); + + std::cout << + _("Usage: apt-internal-resolver\n" + "\n" + "apt-internal-resolver is an interface to use the current internal\n" + "like an external resolver for the APT family for debugging or alike\n" + "\n" + "Options:\n" + " -h This help text.\n" + " -q Loggable output - no progress indicator\n" + " -c=? Read this configuration file\n" + " -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp\n" + "apt.conf(5) manual pages for more information and options.\n" + " This APT has Super Cow Powers.\n"); + return true; +} + /*}}}*/ +int main(int argc,const char *argv[]) /*{{{*/ +{ + CommandLine::Args Args[] = { + {'h',"help","help",0}, + {'v',"version","version",0}, + {'q',"quiet","quiet",CommandLine::IntLevel}, + {'q',"silent","quiet",CommandLine::IntLevel}, + {0,0,0,0}}; + + CommandLine CmdL(Args,_config); + if (pkgInitConfig(*_config) == false || + CmdL.Parse(argc,argv) == false) { + _error->DumpErrors(); + return 2; + } + + // See if the help should be shown + if (_config->FindB("help") == true || + _config->FindB("version") == true) { + ShowHelp(CmdL); + return 1; + } + + // Deal with stdout not being a tty + if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) + _config->Set("quiet","1"); + + if (_config->FindI("quiet", 0) < 1) + _config->Set("Debug::EDSP::WriteSolution", true); + + _config->Set("APT::Solver::Name", "internal"); + _config->Set("edsp::scenario", "stdin"); + int input = STDIN_FILENO; + FILE* output = stdout; + SetNonBlock(input, false); + + if (pkgInitSystem(*_config,_system) == false) { + std::cerr << "System could not be initialized!" << std::endl; + return 1; + } + + if (WaitFd(input, false, 5) == false) + std::cerr << "WAIT timed out in the resolver" << std::endl; + + std::list install, remove; + bool upgrade, distUpgrade, autoRemove; + if (EDSP::ReadRequest(input, install, remove, upgrade, distUpgrade, autoRemove) == false) { + std::cerr << "Parsing the request failed!" << std::endl; + return 2; + } + + pkgCacheFile CacheFile; + CacheFile.Open(NULL, false); + + if (EDSP::ApplyRequest(install, remove, CacheFile) == false) { + std::cerr << "Failed to apply request to depcache!" << std::endl; + return 3; + } + for (std::list::const_iterator i = install.begin(); + i != install.end(); ++i) + CacheFile->MarkInstall(CacheFile->FindPkg(*i), true); + + pkgProblemResolver Fix(CacheFile); + if (Fix.Resolve() == false) { + EDSP::WriteError("An error occured", output); + return 0; + } + + if (EDSP::WriteSolution(CacheFile, output) == false) { + std::cerr << "Failed to output the solution!" << std::endl; + return 4; + } + + bool const Errors = _error->PendingError(); + if (_config->FindI("quiet",0) > 0) + _error->DumpErrors(); + else + _error->DumpErrors(GlobalError::DEBUG); + return Errors == true ? 100 : 0; +} + /*}}}*/ -- cgit v1.2.3 From d9933172b31e21862b660c182f7c747802dbaa73 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 19 Apr 2011 11:52:47 +0200 Subject: set hint flags for the problem resolver according to request --- cmdline/apt-internal-solver.cc | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'cmdline/apt-internal-solver.cc') diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index 83d79e42a..83a671a96 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -104,11 +104,28 @@ int main(int argc,const char *argv[]) /*{{{*/ std::cerr << "Failed to apply request to depcache!" << std::endl; return 3; } + + pkgProblemResolver Fix(CacheFile); + for (std::list::const_iterator i = remove.begin(); + i != remove.end(); ++i) { + pkgCache::PkgIterator P = CacheFile->FindPkg(*i); + Fix.Clear(P); + Fix.Protect(P); + Fix.Remove(P); + } + + for (std::list::const_iterator i = install.begin(); + i != install.end(); ++i) { + pkgCache::PkgIterator P = CacheFile->FindPkg(*i); + Fix.Clear(P); + Fix.Protect(P); + } + for (std::list::const_iterator i = install.begin(); i != install.end(); ++i) CacheFile->MarkInstall(CacheFile->FindPkg(*i), true); - pkgProblemResolver Fix(CacheFile); + if (Fix.Resolve() == false) { EDSP::WriteError("An error occured", output); return 0; -- cgit v1.2.3 From 904be3525223633721dc7b5bff22ae7d8db8cb95 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 25 Apr 2011 15:59:45 +0200 Subject: add scenario command to output a complete or limited scenario --- cmdline/apt-internal-solver.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'cmdline/apt-internal-solver.cc') diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index 83a671a96..68489e213 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -53,6 +53,8 @@ int main(int argc,const char *argv[]) /*{{{*/ {'v',"version","version",0}, {'q',"quiet","quiet",CommandLine::IntLevel}, {'q',"silent","quiet",CommandLine::IntLevel}, + {'c',"config-file",0,CommandLine::ConfigFile}, + {'o',"option",0,CommandLine::ArbItem}, {0,0,0,0}}; CommandLine CmdL(Args,_config); @@ -69,6 +71,25 @@ int main(int argc,const char *argv[]) /*{{{*/ return 1; } + if (CmdL.FileList[0] != 0 && strcmp(CmdL.FileList[0], "scenario") == 0) + { + if (pkgInitSystem(*_config,_system) == false) { + std::cerr << "System could not be initialized!" << std::endl; + return 1; + } + pkgCacheFile CacheFile; + CacheFile.Open(NULL, false); + APT::PackageSet pkgset = APT::PackageSet::FromCommandLine(CacheFile, CmdL.FileList + 1); + FILE* output = stdout; + if (pkgset.empty() == true) + EDSP::WriteScenario(CacheFile, output); + else + EDSP::WriteLimitedScenario(CacheFile, output, pkgset); + fclose(output); + _error->DumpErrors(std::cerr); + return 0; + } + // Deal with stdout not being a tty if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1) _config->Set("quiet","1"); @@ -138,9 +159,9 @@ int main(int argc,const char *argv[]) /*{{{*/ bool const Errors = _error->PendingError(); if (_config->FindI("quiet",0) > 0) - _error->DumpErrors(); + _error->DumpErrors(std::cerr); else - _error->DumpErrors(GlobalError::DEBUG); + _error->DumpErrors(std::cerr, GlobalError::DEBUG); return Errors == true ? 100 : 0; } /*}}}*/ -- cgit v1.2.3 From e876223c704d8cac6246b4aff4bf683fb8b053e3 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Mon, 2 May 2011 11:51:44 +0200 Subject: implement optional Progress report in EDSP --- cmdline/apt-internal-solver.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'cmdline/apt-internal-solver.cc') diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index 68489e213..0aa218d52 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -103,11 +103,15 @@ int main(int argc,const char *argv[]) /*{{{*/ FILE* output = stdout; SetNonBlock(input, false); + EDSP::WriteProgress(0, "Start up solver…", output); + if (pkgInitSystem(*_config,_system) == false) { std::cerr << "System could not be initialized!" << std::endl; return 1; } + EDSP::WriteProgress(1, "Read request…", output); + if (WaitFd(input, false, 5) == false) std::cerr << "WAIT timed out in the resolver" << std::endl; @@ -118,9 +122,13 @@ int main(int argc,const char *argv[]) /*{{{*/ return 2; } + EDSP::WriteProgress(5, "Read scenario…", output); + pkgCacheFile CacheFile; CacheFile.Open(NULL, false); + EDSP::WriteProgress(50, "Apply request on scenario…", output); + if (EDSP::ApplyRequest(install, remove, CacheFile) == false) { std::cerr << "Failed to apply request to depcache!" << std::endl; return 3; @@ -146,17 +154,22 @@ int main(int argc,const char *argv[]) /*{{{*/ i != install.end(); ++i) CacheFile->MarkInstall(CacheFile->FindPkg(*i), true); + EDSP::WriteProgress(60, "Call problemresolver on current scenario…", output); if (Fix.Resolve() == false) { EDSP::WriteError("An error occured", output); return 0; } + EDSP::WriteProgress(95, "Write solution…", output); + if (EDSP::WriteSolution(CacheFile, output) == false) { std::cerr << "Failed to output the solution!" << std::endl; return 4; } + EDSP::WriteProgress(100, "Done", output); + bool const Errors = _error->PendingError(); if (_config->FindI("quiet",0) > 0) _error->DumpErrors(std::cerr); -- cgit v1.2.3 From 80699703b6015a8fe7707302f365020f9782cf2c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Tue, 3 May 2011 10:38:49 +0200 Subject: work on requests with the correct upgrade/dist-upgrade/else resolver --- cmdline/apt-internal-solver.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'cmdline/apt-internal-solver.cc') diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index 0aa218d52..df6a6f569 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -156,7 +156,17 @@ int main(int argc,const char *argv[]) /*{{{*/ EDSP::WriteProgress(60, "Call problemresolver on current scenario…", output); - if (Fix.Resolve() == false) { + if (upgrade == true) { + if (pkgAllUpgrade(CacheFile) == false) { + EDSP::WriteError("An upgrade error occured", output); + return 0; + } + } else if (distUpgrade == true) { + if (pkgDistUpgrade(CacheFile) == false) { + EDSP::WriteError("An dist-upgrade error occured", output); + return 0; + } + } else if (Fix.Resolve() == false) { EDSP::WriteError("An error occured", output); return 0; } -- cgit v1.2.3 From ebfeeaedf5bc357170cae971c0f6a1458ff65f65 Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 7 May 2011 15:49:51 +0200 Subject: implement correct error reporting --- cmdline/apt-internal-solver.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cmdline/apt-internal-solver.cc') diff --git a/cmdline/apt-internal-solver.cc b/cmdline/apt-internal-solver.cc index df6a6f569..ad00a0e23 100644 --- a/cmdline/apt-internal-solver.cc +++ b/cmdline/apt-internal-solver.cc @@ -158,16 +158,16 @@ int main(int argc,const char *argv[]) /*{{{*/ if (upgrade == true) { if (pkgAllUpgrade(CacheFile) == false) { - EDSP::WriteError("An upgrade error occured", output); + EDSP::WriteError("ERR_UNSOLVABLE_UPGRADE", "An upgrade error occured", output); return 0; } } else if (distUpgrade == true) { if (pkgDistUpgrade(CacheFile) == false) { - EDSP::WriteError("An dist-upgrade error occured", output); + EDSP::WriteError("ERR_UNSOLVABLE_DIST_UPGRADE", "An dist-upgrade error occured", output); return 0; } } else if (Fix.Resolve() == false) { - EDSP::WriteError("An error occured", output); + EDSP::WriteError("ERR_UNSOLVABLE", "An error occured", output); return 0; } -- cgit v1.2.3