This is the mail archive of the cygwin-apps mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH 1/3] setup: implement CLI options


>From c06d2094f372ef1426b723231397532c69866390 Mon Sep 17 00:00:00 2001
From: Achim Gratz
Date: Tue, 12 Feb 2013 16:33:40 +0100
Subject: [PATCH 1/3] Allow delete and reinstall from CLI, re-implement install
 from CLI

	* package_meta.h (DeletePackageOption): Add new CLI option
	-p/--remove-packages, packages specified are candidates for
	deletion.
	(DeleteCategoryOption): Add new CLI option -c/--remove-categories
	all packages in the category specified are candidates for
	deletion.
	(isManuallyDeleted): Add new method to check if a particular
	package is requested to be deleted from the CLI.
	(hasManualSelections): Additional boolean to record if any manual
	installations or deletions have been requested from the CLI.
	* choose.cc (hasManualSelections): Declare extern, import from
	package_meta.cc.
	(createListview): remove superflous and detrimental default trust
	setting.  This has already been set correctly in OnInit.
	(OnInit): Re-implement package handling depending on options given
	on CLI using package actions instead of low-level functions.  When
	no CLI package or category options have been given, upgrade
	installed packages.  Do not upgrade existing packages when
	packages are added or removed from the CLI.  A package that is
	requested to be removed and also added at the same time gets
	re-installed or upgraded as package accessibility dictates.
	Uninstalled packages in categories "Base" or "Misc" are always
	selected for installation; already installed packages in these
	categories are not eligible for deletion and will be reinstalled
	or upgraded instead.
	* package_db.h (addCommandLinePackages): Remove unused method.
---
 setup/choose.cc       | 50 +++++++++++++++++++---------------------------
 setup/choose.h        |  1 +
 setup/package_db.cc   | 17 ----------------
 setup/package_db.h    |  1 -
 setup/package_meta.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 setup/package_meta.h  |  2 ++
 6 files changed, 78 insertions(+), 48 deletions(-)

diff --git a/setup/choose.cc b/setup/choose.cc
index cf917cd..0f260f7 100755
--- a/setup/choose.cc
+++ b/setup/choose.cc
@@ -148,11 +148,6 @@ ChooserPage::createListview ()
     log (LOG_BABBLE) << "Failed to set View button caption %ld" <<
 	 GetLastError () << endLog;
 
-  for (packagedb::packagecollection::iterator i = db.packages.begin(); i != db.packages.end(); i++)
-    {
-      i->second->set_requirements(chooser->deftrust);
-    }
-
   /* FIXME: do we need to init the desired fields ? */
   static int ta[] = { IDC_CHOOSE_KEEP, IDC_CHOOSE_CURR, IDC_CHOOSE_EXP, 0 };
   rbset (GetHWND (), ta, IDC_CHOOSE_CURR);
@@ -244,33 +239,28 @@ ChooserPage::OnInit ()
   packagedb db;
   db.setExistence ();
   db.fillMissingCategory ();
-  bool bCommandLineAddedPackages = db.addCommandLinePackages();
 
-  // in unattended mode, if packages were selected on the command line using the --packages
-  // or --categories options, just install those selected packages and don't upgrade all others
-  // (we always install all packages in the Base or Misc categories; packages selected on the
-  // command line are added to the Base category)
-  if ((unattended_mode == unattended) && (bCommandLineAddedPackages))
-    {
-      for (packagedb::packagecollection::iterator i = db.packages.begin ();
-           i != db.packages.end (); ++i)
-        {
-          packagemeta & pkg = *(i->second);
-          if (pkg.installed)
-            {
-              pkg.desired = pkg.installed;
-            }
-          else if (pkg.categories.find ("Base") != pkg.categories.end ()
-                   || pkg.categories.find ("Misc") != pkg.categories.end ())
-            {
-              pkg.desired = pkg.trustp(TRUST_CURR);
-              pkg.desired.pick(TRUE, &pkg);
-            }
-        }
-    }
-  else
+  for (packagedb::packagecollection::iterator i = db.packages.begin ();
+       i != db.packages.end (); ++i)
     {
-      db.defaultTrust (TRUST_CURR);
+      packagemeta & pkg = *(i->second);
+      bool wanted    = pkg.isManuallyWanted();
+      bool deleted   = pkg.isManuallyDeleted();
+      bool basemisc  = (pkg.categories.find ("Base") != pkg.categories.end ()
+		     || pkg.categories.find ("Misc") != pkg.categories.end ());
+      bool current   = pkg.curr;
+      bool upgrade   =  wanted  || (!pkg.installed && basemisc) || !hasManualSelections;
+      bool install   =   wanted  && !deleted && !pkg.installed;
+      bool reinstall =  ((wanted  || basemisc ) && deleted) && pkg.installed.accessible ();
+      bool uninstall = !(wanted  || basemisc ) && deleted;
+      if (install)
+	pkg.set_action( packagemeta::Install_action, pkg.curr );
+      else if (reinstall)
+	pkg.set_action( packagemeta::Reinstall_action, pkg.curr );
+      else if (uninstall)
+	pkg.set_action( packagemeta::Uninstall_action, packageversion() );
+      else
+	pkg.set_action( packagemeta::Default_action, ((upgrade && current) ? pkg.curr : pkg.installed) );
     }
 
   ClearBusy ();
diff --git a/setup/choose.h b/setup/choose.h
index b24aefc..9dc5882 100755
--- a/setup/choose.h
+++ b/setup/choose.h
@@ -21,6 +21,7 @@
 #include "package_meta.h"
 #include "PickView.h"
 
+extern bool hasManualSelections;
 
 class ChooserPage:public PropertyPage
 {
diff --git a/setup/package_db.cc b/setup/package_db.cc
index 1da931c..3578033 100755
--- a/setup/package_db.cc
+++ b/setup/package_db.cc
@@ -422,23 +422,6 @@ packagedb::fillMissingCategory ()
     }
 }
 
-bool
-packagedb::addCommandLinePackages ()
-{
-  bool bReturn = false;
-
-  for (packagedb::packagecollection::iterator i = packages.begin(); i != packages.end(); i++)
-    {
-      if (i->second->isManuallyWanted())
-        {
-          i->second->addToCategoryBase();
-          bReturn = true;
-        }
-    }
-
-  return bReturn;
-}
-
 void
 packagedb::defaultTrust (trusts trust)
 {
diff --git a/setup/package_db.h b/setup/package_db.h
index 63753aa..bc828a1 100755
--- a/setup/package_db.h
+++ b/setup/package_db.h
@@ -70,7 +70,6 @@ public:
   PackageDBConnectedIterator connectedBegin();
   PackageDBConnectedIterator connectedEnd();
   void fillMissingCategory();
-  bool addCommandLinePackages();
   void defaultTrust (trusts trust);
   void markUnVisited();
   void setExistence();
diff --git a/setup/package_meta.cc b/setup/package_meta.cc
index d044eff..c4d9b34 100755
--- a/setup/package_meta.cc
+++ b/setup/package_meta.cc
@@ -51,8 +51,11 @@ using namespace std;
 
 using namespace std;
 
+static StringArrayOption DeletePackageOption ('p', "remove-packages", "Specify packages to uninstall");
 static StringArrayOption PackageOption ('P', "packages", "Specify packages to install");
+static StringArrayOption DeleteCategoryOption ('c', "remove-categories", "Specify categories to uninstall");
 static StringArrayOption CategoryOption ('C', "categories", "Specify entire categories to install");
+bool hasManualSelections = 0;
 
 /*****************/
 
@@ -308,7 +311,9 @@ bool packagemeta::isManuallyWanted() const
 {
   static bool parsed_yet = false;
   static std::set<string> parsed_names;
+  hasManualSelections |= parsed_names.size ();
   static std::set<string> parsed_categories;
+  hasManualSelections |= parsed_categories.size ();
   bool bReturn = false;
 
   /* First time through, we parse all the names out from the 
@@ -352,6 +357,56 @@ bool packagemeta::isManuallyWanted() const
   return bReturn;
 }
 
+bool packagemeta::isManuallyDeleted() const
+{
+  static bool parsed_yet = false;
+  static std::set<string> parsed_delete;
+  hasManualSelections |= parsed_delete.size ();
+  static std::set<string> parsed_delete_categories;
+  hasManualSelections |= parsed_delete_categories.size ();
+  bool bReturn = false;
+
+  /* First time through, we parse all the names out from the
+    option string and store them away in an STL set.  */
+  if (!parsed_yet)
+  {
+    vector<string> delete_options   = DeletePackageOption;
+    vector<string> categories_options = DeleteCategoryOption;
+    for (vector<string>::iterator n = delete_options.begin ();
+		n != delete_options.end (); ++n)
+      {
+	parseNames (parsed_delete, *n);
+      }
+    for (vector<string>::iterator n = categories_options.begin ();
+		n != categories_options.end (); ++n)
+      {
+	parseNames (parsed_delete_categories, *n);
+      }
+    parsed_yet = true;
+  }
+
+  /* Once we've already parsed the option string, just do
+    a lookup in the cache of already-parsed names.  */
+  bReturn = parsed_delete.find(name) != parsed_delete.end();
+
+  /* If we didn't select the package manually, did we select any
+     of the categories it is in? */
+  if (!bReturn && parsed_delete_categories.size ())
+    {
+      std::set<std::string, casecompare_lt_op>::iterator curcat;
+      for (curcat = categories.begin (); curcat != categories.end (); curcat++)
+	if (parsed_delete_categories.find (*curcat) != parsed_delete_categories.end ())
+	  {
+	    log (LOG_PLAIN) << "Found category " << *curcat << " in package " << name << endLog;
+	    bReturn = true;
+	  }
+    }
+
+  if (bReturn)
+    log (LOG_PLAIN) << "Deleted manual package " << name << endLog;
+  return bReturn;
+}
+
 const std::string
 packagemeta::SDesc () const
 {
diff --git a/setup/package_meta.h b/setup/package_meta.h
index 64a77d9..2da4a65 100755
--- a/setup/package_meta.h
+++ b/setup/package_meta.h
@@ -106,6 +106,8 @@ public:
   std::string installed_from;
   /* true if package was selected on command-line. */
   bool isManuallyWanted() const;
+  /* true if package was deleted on command-line. */
+  bool isManuallyDeleted() const;
   /* SDesc is global in theory, across all package versions. 
      LDesc is not: it can be different per version */
   const std::string SDesc () const;
-- 
1.8.1.2


Achim.
-- 
+<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+

Factory and User Sound Singles for Waldorf Q+, Q and microQ:
http://Synth.Stromeko.net/Downloads.html#WaldorfSounds

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]