From: Jan Kupec Date: Mon, 16 Jul 2007 15:41:49 +0000 (+0000) Subject: readBoolAnswer() moved from zypper-misc to zypper-callbacks X-Git-Tag: BASE-SuSE-Linux-10_3-Branch~288 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1706a40759302d7b50f2bc288caac74b50d408b4;p=platform%2Fupstream%2Fzypper.git readBoolAnswer() moved from zypper-misc to zypper-callbacks --- diff --git a/src/zypper-callbacks.cc b/src/zypper-callbacks.cc index 15c928e..9f3600b 100644 --- a/src/zypper-callbacks.cc +++ b/src/zypper-callbacks.cc @@ -20,6 +20,8 @@ void display_progress (const string& s, int percent) { cout_v << flush; } +// ---------------------------------------------------------------------------- + void display_tick (const string& s) { static AliveCursor cursor; @@ -27,6 +29,8 @@ void display_tick (const string& s) { cout_v << flush; } +// ---------------------------------------------------------------------------- + void display_done (const string& s) { static AliveCursor cursor; @@ -34,10 +38,14 @@ void display_done (const string& s) { cout_v << flush; } +// ---------------------------------------------------------------------------- + void display_done () { cout_v << endl; } +// ---------------------------------------------------------------------------- + //template //Action ... int read_action_ari (int default_action) { @@ -82,6 +90,36 @@ int read_action_ari (int default_action) { return default_action; } +// ---------------------------------------------------------------------------- + +// return the default value on input failure +// TODO make this locale dependent? +bool read_bool_with_default (bool defval) { + istream & stm = cin; + + string c = ""; + while (stm.good () && c != "y" && c != "Y" && c != "N" && c != "n") + c = zypp::str::getline (stm, zypp::str::TRIM); + + if (c == "y" || c == "Y") + return true; + else if (c == "n" || c == "N") + return false; + else + return defval; +} + +// ---------------------------------------------------------------------------- + +// Read an answer (ynYN) +// Defaults to 'false' +bool readBoolAnswer() +{ + return read_bool_with_default (false); +} + +// ---------------------------------------------------------------------------- + string to_string (zypp::Resolvable::constPtr resolvable) { ostringstream ss; ss << *resolvable; diff --git a/src/zypper-callbacks.h b/src/zypper-callbacks.h index 259b368..099c548 100644 --- a/src/zypper-callbacks.h +++ b/src/zypper-callbacks.h @@ -48,5 +48,15 @@ void display_error (Error error, const std::string& reason) { * is ignored. */ int read_action_ari (int default_action = -1); + +/** + * Prompt for Yes/No answer from stdin. + * + * \todo work with default + * \todo non-interactive mode + * \todo make this localized + */ +bool readBoolAnswer(); + std::string to_string (zypp::Resolvable::constPtr resolvable); #endif diff --git a/src/zypper-keyring-callbacks.h b/src/zypper-keyring-callbacks.h index 342d9e7..69e4e54 100644 --- a/src/zypper-keyring-callbacks.h +++ b/src/zypper-keyring-callbacks.h @@ -20,7 +20,7 @@ #include #include "AliveCursor.h" -#include "zypper-misc.h" +#include "zypper-callbacks.h" /////////////////////////////////////////////////////////////////// namespace zypp { @@ -37,7 +37,6 @@ namespace zypp { return readBoolAnswer(); } -#ifndef LIBZYPP_1xx virtual bool askUserToImportKey( const PublicKey &key ) { if ( geteuid() != 0 ) @@ -46,36 +45,25 @@ namespace zypp { cout << CLEARLN << _("Import key ") << key.id() << _(" to trusted keyring?") << " [y/n]: " << flush; return readBoolAnswer(); } -#endif -#ifdef LIBZYPP_1xx - virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const std::string &/*keyname*/, const std::string &/*fingerprint*/ ) -#else virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id ) -#endif { cout << CLEARLN << file << _(" is signed with an unknown key id: ") << id << ", " << _("continue?") << " [y/n]: " << flush; return readBoolAnswer(); } -#ifdef LIBZYPP_1xx - virtual bool askUserToTrustKey( const std::string &keyid, const std::string &keyname, const std::string &fingerprint) { -#else - virtual bool askUserToTrustKey( const PublicKey &key ) { + virtual bool askUserToTrustKey( const PublicKey &key ) + { const std::string& keyid = key.id(), keyname = key.name(), fingerprint = key.fingerprint(); -#endif cout << CLEARLN << _("Do you want to trust key id ") << keyid << " " << keyname << _(" fingerprint:") << fingerprint << " ? [y/n]: " << flush; return readBoolAnswer(); } -#ifdef LIBZYPP_1xx - virtual bool askUserToAcceptVerificationFailed( const std::string &file, const std::string &keyid, const std::string &keyname, const std::string &fingerprint ) { -#else - virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key ) { + virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key ) + { const std::string& keyid = key.id(), keyname = key.name(), fingerprint = key.fingerprint(); -#endif cout << file << _("Signature verification for ") << file << _(" with public key id ") << keyid << " " << keyname << _(" fingerprint:") << fingerprint << _(" failed, THIS IS RISKY!") << ". " << _("continue?") << " [y/n]: " << endl; return readBoolAnswer(); // TODO do this with format() diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index d65bd9d..a71526f 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -1,8 +1,6 @@ #include #include #include -#include "zypper.h" -#include "zypper-misc.h" #include #include @@ -12,6 +10,10 @@ #include #include +#include "zypper.h" +#include "zypper-misc.h" +#include "zypper-callbacks.h" + using namespace zypp::detail; using namespace std; @@ -33,30 +35,6 @@ void cond_init_target () { } } -// return the default value on input failure -// TODO make this locale dependent? -bool read_bool_with_default (bool defval) { - istream & stm = cin; - - string c = ""; - while (stm.good () && c != "y" && c != "Y" && c != "N" && c != "n") - c = zypp::str::getline (stm, zypp::str::TRIM); - - if (c == "y" || c == "Y") - return true; - else if (c == "n" || c == "N") - return false; - else - return defval; -} - -// Read an answer (ynYN) -// Defaults to 'false' -bool readBoolAnswer() -{ - return read_bool_with_default (false); -} - // converts a user-supplied kind to a zypp kind object // returns an empty one if not recognized ResObject::Kind string_to_kind (const string &skind) diff --git a/src/zypper-misc.h b/src/zypper-misc.h index 7a9daae..9692ba5 100644 --- a/src/zypper-misc.h +++ b/src/zypper-misc.h @@ -21,7 +21,6 @@ */ void cond_init_target(); -bool readBoolAnswer(); zypp::ResObject::Kind string_to_kind (const std::string &skind); void mark_for_install( const zypp::ResObject::Kind &kind, const std::string &name );