[Aptitude-svn-commit] r3900 - in branches/aptitude-0.3/aptitude: . src/cmdline

Daniel Burrows dburrows at costa.debian.org
Wed Aug 17 22:23:21 UTC 2005


Author: dburrows
Date: Wed Aug 17 22:23:17 2005
New Revision: 3900

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/src/cmdline/cmdline_resolver.cc
Log:
Add support for rejecting/accepting versions from the command-line.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Wed Aug 17 22:23:17 2005
@@ -1,5 +1,10 @@
 2005-08-17  Daniel Burrows  <dburrows at debian.org>
 
+	* src/cmdline/cmdline_resolver.cc:
+
+	  Add support for rejecting/accepting versions from the
+	  command-line.
+
 	* src/solution_fragment.cc:
 
 	  Silly compilation fix.

Modified: branches/aptitude-0.3/aptitude/src/cmdline/cmdline_resolver.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/cmdline/cmdline_resolver.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/cmdline/cmdline_resolver.cc	Wed Aug 17 22:23:17 2005
@@ -33,13 +33,16 @@
 #include <generic/config_signal.h>
 #include <generic/problemresolver/exceptions.h>
 #include <generic/problemresolver/solution.h>
+#include <generic/util.h>
 
 #include <vscreen/fragment.h>
 
 #include <apt-pkg/error.h>
+#include <apt-pkg/strutl.h>
 
 #include <iostream>
 #include <fstream>
+#include <sstream>
 
 using namespace std;
 
@@ -175,6 +178,155 @@
   delete f;
 }
 
+// Given several versions with the same VerStr, choose one to output.
+static pkgCache::VerIterator choose_version(const vector<pkgCache::VerIterator> &choices)
+{
+  assert(!choices.empty());
+
+  if(choices.size() == 1)
+    return choices.front();
+
+  cout << ssprintf(_("The version %s is available in the following archives:"), choices.front().VerStr()) << endl;
+
+  for(vector<pkgCache::VerIterator>::size_type i = 0;
+      i < choices.size(); ++i)
+    cout << ssprintf(" (%d) %s", i+1, archives_text(choices[i]).c_str()) << endl;
+
+  while(1)
+    {
+      string response = prompt_string(ssprintf(_("Select the version of %s that should be used: "), choices.front().ParentPkg().Name()));
+
+      int i;
+      istringstream in(response);
+      in >> ws >> i >> ws;
+
+      if(!in || !in.eof() || i < 1 || i > choices.size())
+	cerr << ssprintf(_("Invalid response.  Please enter an integer between 1 and %d."), choices.size()) << endl;
+      else
+	return choices[i];
+    }
+}
+
+static void reject_or_mandate_version(const string &s,
+				      bool is_reject)
+{
+  istringstream in(s);
+
+  in >> ws;
+
+  if(in.eof())
+    {
+      cerr << ssprintf(_("Expected at least one package/version pair following '%c'"),
+			 is_reject ? 'R' : 'A') << endl;
+      return;
+    }
+
+  string pkgname;
+  string vername;
+
+  while(!in.eof())
+    {
+      in >> pkgname >> ws;
+
+      if(in.eof())
+	{
+	  cerr << ssprintf(_("Expected a version after \"%s\""), pkgname.c_str()) << endl;
+	  return;
+	}
+
+      in >> vername >> ws;
+
+      pkgCache::PkgIterator pkg((*apt_cache_file)->FindPkg(pkgname));
+
+      if(pkg.end())
+	{
+	  cerr << ssprintf(_("No such package \"%s\""), pkgname.c_str()) << endl;
+	  continue;
+	}
+
+      aptitude_universe::version ver(pkg,
+				     pkgCache::VerIterator(*apt_cache_file),
+				     *apt_cache_file);
+      if(stringcasecmp(vername, "UNINST") != 0)
+	{
+	  vector<pkgCache::VerIterator> found;
+	  for(pkgCache::VerIterator vi = pkg.VersionList(); !vi.end(); ++vi)
+	    if(vi.VerStr() == vername)
+	      found.push_back(vi);
+
+	  if(found.empty())
+	    {
+	      cerr << ssprintf(_("%s has no version named \"%s\""),
+			       pkgname.c_str(), vername.c_str()) << endl;
+	      continue;
+	    }
+
+	  ver = aptitude_universe::version(pkg, choose_version(found),
+					   *apt_cache_file);
+
+	  assert(!ver.get_ver().end());
+	  assert(ver.get_pkg() == ver.get_ver().ParentPkg());
+	}
+
+      if(is_reject)
+	{
+	  if((*apt_cache_file)->resolver_is_rejected(ver))
+	    {
+	      if(ver.get_ver().end())
+		cout << ssprintf(_("Allowing the removal of %s"),
+				 pkgname.c_str()) << endl;
+	      else
+		cout << ssprintf(_("Allowing the installation of %s version %s (%s)"),
+				 pkg.Name(),
+				 ver.get_ver().VerStr(),
+				 archives_text(ver.get_ver()).c_str()) << endl;
+
+	      (*apt_cache_file)->resolver_unreject_version(ver);
+	    }
+	  else
+	    {
+	      if(ver.get_ver().end())
+		cout << ssprintf(_("Rejecting the removal of %s"),
+				 pkgname.c_str()) << endl;
+	      else
+		cout << ssprintf(_("Rejecting the installation of %s version %s (%s)"),
+				 pkg.Name(),
+				 ver.get_ver().VerStr(),
+				 archives_text(ver.get_ver()).c_str()) << endl;
+
+	      (*apt_cache_file)->resolver_reject_version(ver);
+	    }
+	}
+      else
+	{
+	  if((*apt_cache_file)->resolver_is_mandatory(ver))
+	    {
+	      if(ver.get_ver().end())
+		cout << ssprintf(_("No longer requiring the removal of %s"),
+				 pkgname.c_str()) << endl;
+	      else
+		cout << ssprintf(_("No longer requiring the installation of %s version %s (%s)"),
+				 pkg.Name(), ver.get_ver().VerStr(),
+				 archives_text(ver.get_ver()).c_str()) << endl;
+
+	      (*apt_cache_file)->resolver_unmandate_version(ver);
+	    }
+	  else
+	    {
+	      if(ver.get_ver().end())
+		cout << ssprintf(_("Requiring the removal of %s"),
+				 pkgname.c_str()) << endl;
+	      else
+		cout << ssprintf(_("Requiring the installation of %s version %s (%s)"),
+				 pkg.Name(), ver.get_ver().VerStr(),
+				 archives_text(ver.get_ver()).c_str()) << endl;
+
+	      (*apt_cache_file)->resolver_unmandate_version(ver);
+	    }
+	}
+    }
+}
+
 bool cmdline_resolve_deps(pkgset &to_install,
 			  pkgset &to_hold,
 			  pkgset &to_remove,
@@ -259,6 +411,12 @@
 		      delete f;
 		      break;
 		    }
+		  case 'R':
+		    reject_or_mandate_version(string(response, 1), true);
+		    break;
+		  case 'A':
+		    reject_or_mandate_version(string(response, 1), true);
+		    break;
 		  case '.':
 		    (*apt_cache_file)->next_solution();
 		    break;



More information about the Aptitude-svn-commit mailing list