Author: jkupec
Date: Fri Mar 14 09:45:14 2008
New Revision: 9145
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9145&view=rev
Log:
- PromptOptions introduced
Added:
trunk/zypper/src/zypper-prompt.cc
trunk/zypper/src/zypper-prompt.h
Removed:
trunk/zypper/src/zypper-callbacks.cc
trunk/zypper/src/zypper-callbacks.h
Modified:
trunk/zypper/src/CMakeLists.txt
trunk/zypper/src/output/Out.h
trunk/zypper/src/output/OutNormal.cc
trunk/zypper/src/output/OutNormal.h
trunk/zypper/src/output/OutXML.cc
trunk/zypper/src/output/OutXML.h
trunk/zypper/src/zypper-keyring-callbacks.h
trunk/zypper/src/zypper-media-callbacks.h
trunk/zypper/src/zypper-misc.cc
trunk/zypper/src/zypper-repo-callbacks.h
trunk/zypper/src/zypper-repos.cc
trunk/zypper/src/zypper-rpm-callbacks.h
trunk/zypper/src/zypper-utils.cc
trunk/zypper/src/zypper-utils.h
trunk/zypper/src/zypper.cc
Modified: trunk/zypper/src/CMakeLists.txt
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/CMakeLists.txt?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/CMakeLists.txt (original)
+++ trunk/zypper/src/CMakeLists.txt Fri Mar 14 09:45:14 2008
@@ -15,8 +15,8 @@
zypper-utils.h
zypper-search.h
zypper-info.h
+ zypper-prompt.h
zypper-tabulator.h
- zypper-callbacks.h
zypper-keyring-callbacks.h
zypper-media-callbacks.h
zypper-rpm-callbacks.h
@@ -34,7 +34,7 @@
zypper-search.cc
zypper-info.cc
zypper-tabulator.cc
- zypper-callbacks.cc
+ zypper-prompt.cc
${zypper_HEADERS}
)
@@ -43,6 +43,7 @@
output/OutNormal.h
output/OutXML.h
output/prompt.h
+ output/AliveCursor.h
)
SET( zypper_out_SRCS
Modified: trunk/zypper/src/output/Out.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/Out.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/output/Out.h (original)
+++ trunk/zypper/src/output/Out.h Fri Mar 14 09:45:14 2008
@@ -7,6 +7,7 @@
#include "zypp/base/Exception.h"
#include "zypp/Url.h"
+#include "../zypper-prompt.h"
#include "prompt.h"
/**
@@ -212,13 +213,14 @@
*
* \param id Unique prompt identifier for use by machines.
* \param prompt Prompt text.
- * \param answer_hint list of answers separated by '/'. \todo improve this
+ * \param options A PromptOptions object
*
* \see prompt.h
*/
virtual void prompt(PromptId id,
const std::string & prompt,
- const std::string & answer_hint) = 0;
+ const PromptOptions & poptions) = 0;
+
public:
/** Get current verbosity. */
Verbosity verbosity() { return _verbosity; }
Modified: trunk/zypper/src/output/OutNormal.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutNormal.cc?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/output/OutNormal.cc (original)
+++ trunk/zypper/src/output/OutNormal.cc Fri Mar 14 09:45:14 2008
@@ -196,16 +196,22 @@
void OutNormal::prompt(PromptId id,
const string & prompt,
- const string & answer_hint)
+ const PromptOptions & poptions)
{
- /**
- vector<string> answers;
- zypp::str::split(answer_hint, back_inserter(answers), "/");
- for (vector<string>::const_iterator ansit = answers.begin();
- ansit != answers.end(); ++ansit)
+ string option_str;
+ PromptOptions::OptionList::const_iterator it;
+ if (poptions.options().begin() != poptions.end())
{
+ //if (is_default) // TODO
+ option_str += *it;
+ }
+ for (;
+ it != poptions.options().end(); ++it)
+ {
+ string option = *it;
+ //if (is_default) // TODO
+ option_str += "/" + option;
}
- */
- cout << CLEARLN << prompt << " [" << answer_hint << "]: " << std::flush;
+ cout << CLEARLN << prompt << " [" << option_str << "]: " << std::flush;
}
Modified: trunk/zypper/src/output/OutNormal.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutNormal.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/output/OutNormal.h (original)
+++ trunk/zypper/src/output/OutNormal.h Fri Mar 14 09:45:14 2008
@@ -55,7 +55,7 @@
virtual void prompt(PromptId id,
const std::string & prompt,
- const std::string & answer_hint);
+ const PromptOptions & poptions);
protected:
virtual bool mine(Type type);
Modified: trunk/zypper/src/output/OutXML.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutXML.cc?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/output/OutXML.cc (original)
+++ trunk/zypper/src/output/OutXML.cc Fri Mar 14 09:45:14 2008
@@ -188,21 +188,20 @@
void OutXML::prompt(PromptId id,
const string & prompt,
- const string & answer_hint)
+ const PromptOptions & poptions)
{
cout << "" << endl;
cout << xml_encode(prompt);
- vector<string> answers;
- zypp::str::split(answer_hint, back_inserter(answers), "/");
- for (vector<string>::const_iterator ansit = answers.begin();
- ansit != answers.end(); ++ansit)
+ int i = 0;
+ for (PromptOptions::OptionList::const_iterator it = poptions.options().begin();
+ it != poptions.options().end(); ++it, i++)
{
- string answer = *ansit;
+ string option = *it;
cout << "" << endl;
}
cout << "</prompt>" << endl;
Modified: trunk/zypper/src/output/OutXML.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/output/OutXML.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/output/OutXML.h (original)
+++ trunk/zypper/src/output/OutXML.h Fri Mar 14 09:45:14 2008
@@ -39,7 +39,7 @@
virtual void prompt(PromptId id,
const std::string & prompt,
- const std::string & answer_hint);
+ const PromptOptions & poptions);
protected:
virtual bool mine(Type type);
Modified: trunk/zypper/src/zypper-keyring-callbacks.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-keyring-callbacks.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-keyring-callbacks.h (original)
+++ trunk/zypper/src/zypper-keyring-callbacks.h Fri Mar 14 09:45:14 2008
@@ -20,7 +20,7 @@
#include "zypp/KeyRing.h"
#include "zypp/Digest.h"
-#include "zypper-callbacks.h"
+#include "zypper-prompt.h"
///////////////////////////////////////////////////////////////////
namespace zypp {
Modified: trunk/zypper/src/zypper-media-callbacks.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-media-callbacks.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-media-callbacks.h (original)
+++ trunk/zypper/src/zypper-media-callbacks.h Fri Mar 14 09:45:14 2008
@@ -21,7 +21,7 @@
#include "zypp/media/MediaUserAuth.h"
#include "zypper.h"
-#include "zypper-callbacks.h"
+#include "zypper-prompt.h"
#include "output/prompt.h"
using zypp::media::MediaChangeReport;
@@ -174,13 +174,13 @@
// << auth_data_ptr->authTypeAsString() << std::endl;
Zypper::instance()->out().prompt(
- PROMPT_AUTH_USERNAME, description, _("User Name"));
+ PROMPT_AUTH_USERNAME, description, PromptOptions(_("User Name"), 0));
string username;
std::cin >> username;
auth_data_ptr->setUserName(username);
Zypper::instance()->out().prompt(
- PROMPT_AUTH_PASSWORD, description, _("Password"));
+ PROMPT_AUTH_PASSWORD, description, PromptOptions(_("Password"), 0));
string password;
std::cin >> password;
if (password.empty()) return false;
Modified: trunk/zypper/src/zypper-misc.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-misc.cc?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-misc.cc (original)
+++ trunk/zypper/src/zypper-misc.cc Fri Mar 14 09:45:14 2008
@@ -26,7 +26,7 @@
#include "zypper-utils.h"
#include "zypper-getopt.h"
#include "zypper-misc.h"
-#include "zypper-callbacks.h"
+#include "zypper-prompt.h"
#include "output/prompt.h"
using namespace std;
@@ -489,14 +489,14 @@
"Choose from above solutions by number or skip, retry or cancel",
solutions.size());
- zypper.out().prompt(PROMPT_DEP_RESOLVE, stm.str(),
- // translators: answers for dependency problem solution input prompt:
- // "Choose from above solutions by number or skip, retry or cancel"
- // Translate the letters to whatever is suitable for your language.
- // The anserws must be separated by slash characters '/' and must
- // correspond to number/skip/retry/cancel in that order.
- // The answers should be lower case letters.
- _("#/s/r/c"));
+ // translators: answers for dependency problem solution input prompt:
+ // "Choose from above solutions by number or skip, retry or cancel"
+ // Translate the letters to whatever is suitable for your language.
+ // The anserws must be separated by slash characters '/' and must
+ // correspond to number/skip/retry/cancel in that order.
+ // The answers should be lower case letters.
+ PromptOptions popts(_("#/s/r/c"), 3);
+ zypper.out().prompt(PROMPT_DEP_RESOLVE, stm.str(), popts);
string reply_s = str::getline (cin, zypp::str::TRIM);
if (! cin.good()) {
Added: trunk/zypper/src/zypper-prompt.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-prompt.cc?rev=9145&view=auto
==============================================================================
--- trunk/zypper/src/zypper-prompt.cc (added)
+++ trunk/zypper/src/zypper-prompt.cc Fri Mar 14 09:45:14 2008
@@ -0,0 +1,140 @@
+#include
+#include <sstream>
+
+#include
+
+#include "zypp/base/Logger.h"
+
+#include "zypper.h"
+//#include "zypper-main.h"
+#include "zypper-prompt.h"
+
+using namespace std;
+using namespace boost;
+
+// ----------------------------------------------------------------------------
+
+PromptOptions::PromptOptions(const std::string option_str, unsigned int default_opt)
+{
+ zypp::str::split(answer_hint, back_inserter(_options), "/");
+
+ if (_options.size() <= default_opt)
+ INT << "Invalid default option index " << default_opt << endl;
+ else
+ _default = default_opt;
+}
+
+PromptOptions::~PromptOptions()
+{
+
+}
+
+// ----------------------------------------------------------------------------
+
+//template<typename Action>
+//Action ...
+int read_action_ari (PromptId pid, int default_action) {
+ Out & out = Zypper::instance()->out();
+ // translators: "a/r/i" are the answers to the
+ // "Abort, retry, ignore?" prompt
+ // Translate the letters to whatever is suitable for your language.
+ // the anserws must be separated by slash characters '/' and must
+ // correspond to abort/retry/ignore in that order.
+ // The answers should be lower case letters.
+ out.prompt(pid, _("Abort, retry, ignore?"), _("a/r/i"));
+
+ // choose abort if no default has been specified
+ if (default_action == -1) {
+ default_action = 0;
+ }
+
+ // non-interactive mode
+ if (Zypper::instance()->globalOpts().non_interactive) {
+ char c;
+ switch (default_action) {
+ case 0: c = 'a'; break;
+ case 1: c = 'r'; break;
+ case 2: c = 'i'; break;
+ default: c = '?';
+ }
+ // print the answer for conveniecne (only for normal output)
+ out.info(string(1, c), Out::QUIET, Out::TYPE_NORMAL);
+ MIL << "answer: " << c << endl;
+ return default_action;
+ }
+
+ // interactive mode, ask user
+ while (cin.good()) { // #269263
+ char c;
+ cin >> c;
+ c = tolower (c);
+ MIL << "answer: " << c << endl;
+ if (c == 'a')
+ return 0;
+ else if (c == 'r')
+ return 1;
+ else if (c == 'i')
+ return 2;
+ // translators: don't translate the letters
+ ostringstream s;
+ s << format(_("Invalid answer '%s'.")) % c << " "
+ << _("Choose letter 'a', 'r', or 'i'");
+ out.prompt(pid, s.str(), _("a/r/i")); //! \todo remove this, handle invalid answers within the first prompt()
+ DBG << "invalid answer" << endl;
+ }
+
+ return default_action;
+}
+
+// ----------------------------------------------------------------------------
+
+bool read_bool_answer(PromptId pid, const string & question, bool default_answer)
+{
+ const GlobalOptions & gopts = Zypper::instance()->globalOpts();
+ Out & out = Zypper::instance()->out();
+
+ string yn = string(_("yes")) + "/" + _("no");
+
+ out.prompt(pid, question, yn);
+
+ // non-interactive mode: print the answer for convenience (only for normal
+ // output) and return default
+ if (gopts.non_interactive)
+ {
+ if (!gopts.machine_readable)
+ out.info((default_answer ? _("yes") : _("no")), Out::QUIET, Out::TYPE_NORMAL);
+ MIL << "answer (default): " << (default_answer ? 'y' : 'n') << endl;
+ return default_answer;
+ }
+
+ istream & stm = cin;
+
+ string c = "";
+ bool been_here_before = false;
+ while (stm.good() && rpmatch(c.c_str()) == -1)
+ {
+ if (been_here_before)
+ {
+ ostringstream s;
+ s << format(_("Invalid answer '%s'.")) % c << " " << format(
+ // TranslatorExplanation don't translate the 'y' and 'n', they can always be used as answers.
+ // The second and the third %s is the translated 'yes' and 'no' string (lowercase).
+ _("Enter 'y' for '%s' or 'n' for '%s' if nothing else works for you"))
+ % _("yes") % _("no");
+ out.prompt(pid, s.str(), yn); //! \todo remove this, handle invalid answers within the first prompt()
+ }
+ c = zypp::str::getline (stm, zypp::str::TRIM);
+ been_here_before = true;
+ }
+
+ MIL << "answer: " << c << endl;
+ int answer = rpmatch(c.c_str());
+ if (answer >= 0)
+ return answer;
+ else // in case of !stm.good()
+ {
+ WAR << "could not read answer, returning default: "
+ << (default_answer ? 'y' : 'n') << endl;
+ return default_answer;
+ }
+}
Added: trunk/zypper/src/zypper-prompt.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-prompt.h?rev=9145&view=auto
==============================================================================
--- trunk/zypper/src/zypper-prompt.h (added)
+++ trunk/zypper/src/zypper-prompt.h Fri Mar 14 09:45:14 2008
@@ -0,0 +1,84 @@
+#ifndef ZYPPERPROMPT_H_
+#define ZYPPERPROMPT_H_
+
+#include "output/prompt.h"
+#include "zypper-main.h" // for gettext macros
+
+class PromptOptions
+{
+public:
+ typedef std::vectorstd::string OptionList;
+
+ /**
+ * Constructor.
+ *
+ * \param option_str translated option string containing one or more
+ * options separated by slash '/' character
+ * e.g. "yes/no/?" or "1/s/r/c"
+ * \param default_opt index of the default answer within the \a option_str
+ */
+ PromptOptions(const std::string option_str, unsigned int default_opt);
+ ~PromptOptions();
+
+ const OptionList & options() const { return _options; }
+ unsigned int defaultOpt() const { return _default; }
+
+private:
+ OptionList _options;
+ unsigned int _default;
+};
+
+
+/**
+ * Abort, Retry, Ignore stdin prompt.
+ * \param default_action Answer to be returned in non-interactive mode. If none
+ * is specified, 0 (ABORT) is returned. In interactive mode, this parameter
+ * is ignored.
+ */
+int read_action_ari (PromptId pid, int default_action = -1);
+
+/**
+ * Prompt for y/n answer (localized) from stdin.
+ *
+ * \param question Question to be printed on prompt.
+ * \param default_answer Value to be returned in non-interactive mode or on
+ * input failure.
+ */
+bool read_bool_answer(PromptId pid, const std::string & question, bool default_answer);
+
+
+/*
+enum Error {
+ NO_ERROR,
+ NOT_FOUND,
+ IO,
+ INVALID,
+};
+*/
+
+//! \todo this must be rewritten as the error enums are different for some zypp callbacks
+template<typename Error>
+std::string zcb_error2str (Error error, const std::string & reason)
+{
+ std::string errstr;
+ if (error != 0 /*NO_ERROR*/)
+ {
+ static const char * error_s[] = {
+ // TranslatorExplanation These are reasons for various failures.
+ "", _("Not found"), _("I/O error"), _("Invalid object")
+ };
+
+ // error type:
+ if (error < 3)
+ errstr += error_s[error];
+ else
+ errstr += _("Error");
+ // description
+ if (!reason.empty())
+ errstr += ": " + reason;
+ }
+
+ return errstr;
+}
+
+#endif /*ZYPPERPROMPT_H_*/
Modified: trunk/zypper/src/zypper-repo-callbacks.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repo-callbacks.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-repo-callbacks.h (original)
+++ trunk/zypper/src/zypper-repo-callbacks.h Fri Mar 14 09:45:14 2008
@@ -19,7 +19,7 @@
#include "zypp/Url.h"
#include "zypper.h"
-#include "zypper-callbacks.h"
+#include "zypper-prompt.h"
#include "zypper-utils.h"
///////////////////////////////////////////////////////////////////
Modified: trunk/zypper/src/zypper-repos.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repos.cc?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-repos.cc (original)
+++ trunk/zypper/src/zypper-repos.cc Fri Mar 14 09:45:14 2008
@@ -19,7 +19,7 @@
#include "zypper-main.h"
#include "zypper-getopt.h"
#include "zypper-tabulator.h"
-#include "zypper-callbacks.h"
+//#include "zypper-callbacks.h"
#include "zypper-utils.h"
#include "zypper-repos.h"
Modified: trunk/zypper/src/zypper-rpm-callbacks.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-rpm-callbacks.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-rpm-callbacks.h (original)
+++ trunk/zypper/src/zypper-rpm-callbacks.h Fri Mar 14 09:45:14 2008
@@ -21,7 +21,7 @@
//#include "zypp/target/rpm/RpmCallbacks.h"
#include "zypper.h"
-#include "zypper-callbacks.h"
+#include "zypper-prompt.h"
using namespace std;
Modified: trunk/zypper/src/zypper-utils.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-utils.cc?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-utils.cc (original)
+++ trunk/zypper/src/zypper-utils.cc Fri Mar 14 09:45:14 2008
@@ -11,7 +11,7 @@
#include "zypper-main.h"
#include "zypper-utils.h"
-#include "zypper-callbacks.h"
+//#include "zypper-callbacks.h"
using namespace std;
using namespace zypp;
@@ -59,6 +59,16 @@
// ----------------------------------------------------------------------------
+void report_too_many_arguments(const string & specific_help)
+{
+ //! \todo make this more explanatory, e.g. "Ingoring arg1 arg2. This command does not take arguments. See %s for more information."
+ ostringstream s;
+ s << _("Usage") << ':' << endl << specific_help;
+ Zypper::instance()->out().error(_("Too many arguments."), s.str());
+}
+
+// ----------------------------------------------------------------------------
+
bool is_changeable_media(const zypp::Url & url)
{
MIL << "Checking if this is a changeable medium" << endl;
Modified: trunk/zypper/src/zypper-utils.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-utils.h?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper-utils.h (original)
+++ trunk/zypper/src/zypper-utils.h Fri Mar 14 09:45:14 2008
@@ -19,6 +19,11 @@
*/
void report_a_bug (Out & out);
+/**
+ *
+ */
+void report_too_many_arguments(const std::string & specific_help);
+
bool is_changeable_media(const zypp::Url & url);
std::string kind_to_string_localized(
Modified: trunk/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=9145&r1=9144&r2=9145&view=diff
==============================================================================
--- trunk/zypper/src/zypper.cc (original)
+++ trunk/zypper/src/zypper.cc Fri Mar 14 09:45:14 2008
@@ -40,7 +40,7 @@
#include "zypper-getopt.h"
#include "zypper-command.h"
#include "zypper-utils.h"
-#include "zypper-callbacks.h"
+//#include "zypper-callbacks.h"
#include "output/OutNormal.h"
#include "output/OutXML.h"
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org