From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3166 invoked by alias); 24 Jul 2013 20:51:53 -0000 Mailing-List: contact cygwin-apps-help@cygwin.com; run by ezmlm Precedence: bulk Sender: cygwin-apps-owner@cygwin.com List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Mail-Followup-To: cygwin-apps@cygwin.com Received: (qmail 3103 invoked by uid 89); 24 Jul 2013 20:51:53 -0000 X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL,BAYES_50,KHOP_THREADED,RCVD_IN_DNSWL_NONE,RDNS_NONE,SPF_PASS autolearn=no version=3.3.1 Received: from Unknown (HELO mail-in-06.arcor-online.net) (151.189.21.46) by sourceware.org (qpsmtpd/0.84/v0.84-167-ge50287c) with ESMTP; Wed, 24 Jul 2013 20:51:51 +0000 Received: from mail-in-20-z2.arcor-online.net (mail-in-20-z2.arcor-online.net [151.189.8.85]) by mx.arcor.de (Postfix) with ESMTP id 3415910BA4D for ; Wed, 24 Jul 2013 22:51:43 +0200 (CEST) Received: from mail-in-01.arcor-online.net (mail-in-01.arcor-online.net [151.189.21.41]) by mail-in-20-z2.arcor-online.net (Postfix) with ESMTP id 2B4D7834009; Wed, 24 Jul 2013 22:51:43 +0200 (CEST) Received: from Rainer.invalid (pD9EB0A73.dip0.t-ipconnect.de [217.235.10.115]) (Authenticated sender: stromeko@arcor.de) by mail-in-01.arcor-online.net (Postfix) with ESMTPSA id 727001A; Wed, 24 Jul 2013 22:51:42 +0200 (CEST) X-DKIM: Sendmail DKIM Filter v2.8.2 mail-in-01.arcor-online.net 727001A From: Achim Gratz To: Achim Gratz Cc: cygwin-apps@cygwin.com Subject: Re: [PATCH 2/4 setup] package re-/de-installation from CLI Date: Wed, 24 Jul 2013 20:51:00 -0000 References: <87a9lexyk8.fsf@Rainer.invalid> <20130724115129.GT9689@calimero.vinschen.de> Message-ID: <87k3kfadgi.fsf@Rainer.invalid> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Virus-Found: No X-SW-Source: 2013-07/txt/msg00295.txt.bz2 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Allow-deletion-of-packages-and-categories-from-CLI-r.patch Content-length: 7995 >From baab3c913d87a06b62dd14c442a15dc8c2aa9361 Mon Sep 17 00:00:00 2001 From: Achim Gratz Date: Wed, 24 Jul 2013 22:00:36 +0200 Subject: [PATCH 2/4] Allow deletion of packages and categories from CLI, re-implement install from CLI * choose.h (hasManualSelections): Declare new variable. * choose.cc (OnInit): Re-implement package handling depending on options given on CLI using package actions instead of package_meta low-level functions. When no CLI package or category options have been given, upgrade installed packages. Do not check for updates when packages are to be added or removed from the CLI, but this behaviour can be requested with --upgrade-also. A package that is requested to be removed and also added at the same time gets re-installed or upgraded (when version curr != installed). Uninstalled packages in categories "Base" or "Misc" are always selected for installation; installed packages in these categories are not eligible for deletion and will be reinstalled or upgraded instead. * package_meta.h (ismanuallyDeleted): Declare new method. * package_meta.cc (DeletePackageOption): Add new CLI option -x/--remove-packages, packages listed here are considered candidates for deletion. (DeleteCategoryOption): Add new CLI option -c/--remove-categories, packages belonging to categories listed here are considered candidates for deletion. (hasManualSelections): Additional boolean to record if any manual installations or deletions have been requested. (packagemeta::isManuallyDeleted): Implement along the same lines as isManuallyWanted, but for deletion candidates. --- choose.cc | 43 ++++++++++++++++++++----------------------- choose.h | 1 + package_meta.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ package_meta.h | 2 ++ 4 files changed, 78 insertions(+), 23 deletions(-) diff --git a/choose.cc b/choose.cc index 4e0bcd4..fd75790 100644 --- a/choose.cc +++ b/choose.cc @@ -239,31 +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; + 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/choose.h b/choose.h index b24aefc..9dc5882 100644 --- a/choose.h +++ b/choose.h @@ -21,6 +21,7 @@ #include "package_meta.h" #include "PickView.h" +extern bool hasManualSelections; class ChooserPage:public PropertyPage { diff --git a/package_meta.cc b/package_meta.cc index ee4cb45..ed7a9bf 100644 --- a/package_meta.cc +++ b/package_meta.cc @@ -51,8 +51,11 @@ using namespace std; using namespace std; +static StringArrayOption DeletePackageOption ('x', "remove-packages", "Specify packages to uninstall"); +static StringArrayOption DeleteCategoryOption ('c', "remove-categories", "Specify categories to uninstall"); static StringArrayOption PackageOption ('P', "packages", "Specify packages to install"); static StringArrayOption CategoryOption ('C', "categories", "Specify entire categories to install"); +bool hasManualSelections = 0; /*****************/ @@ -275,7 +278,9 @@ bool packagemeta::isManuallyWanted() const { static bool parsed_yet = false; static std::set parsed_names; + hasManualSelections |= parsed_names.size (); static std::set parsed_categories; + hasManualSelections |= parsed_categories.size (); bool bReturn = false; /* First time through, we parse all the names out from the @@ -319,6 +324,56 @@ bool packagemeta::isManuallyWanted() const return bReturn; } +bool packagemeta::isManuallyDeleted() const +{ + static bool parsed_yet = false; + static std::set parsed_delete; + hasManualSelections |= parsed_delete.size (); + static std::set 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 delete_options = DeletePackageOption; + vector categories_options = DeleteCategoryOption; + for (vector::iterator n = delete_options.begin (); + n != delete_options.end (); ++n) + { + parseNames (parsed_delete, *n); + } + for (vector::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::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/package_meta.h b/package_meta.h index 64a77d9..2da4a65 100644 --- a/package_meta.h +++ b/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.3.1 --=-=-= Content-Type: text/plain Content-length: 176 Achim. -- +<[Q+ Matrix-12 WAVE#46+305 Neuron microQkb Andromeda XTk Blofeld]>+ Samples for the Waldorf Blofeld: http://Synth.Stromeko.net/Downloads.html#BlofeldSamplesExtra --=-=-=--