void display_progress ( const std::string &id, ostream & out, const string& s, int percent) {
static AliveCursor cursor;
- if (gSettings.machine_readable)
+ if (Zypper::instance()->globalOpts().machine_readable)
{
cout << "<progress id=\"" << id << "\" type=\"percentage\" value=\"" << percent << "\" name=\"" << s << "\"/>" << endl;
return;
void display_tick ( const std::string &id, ostream & out, const string& s) {
static AliveCursor cursor;
- if (gSettings.machine_readable)
+ if (Zypper::instance()->globalOpts().machine_readable)
{
cout << "<progress id=\"" << id << "\" type=\"tick\" value=\"" << -1 << "\" name=\"" << s << "\"/>" << endl;
return;
void display_done ( const std::string &id, ostream & out, const string& s) {
static AliveCursor cursor;
- if (gSettings.machine_readable)
+ if (Zypper::instance()->globalOpts().machine_readable)
{
cout << "<progress id=\"" << id << "\" type=\"done\" name=\"" << s << "\"/>" << endl;
return;
void display_done (const std::string &id, ostream & out) {
- if (gSettings.machine_readable)
+ if (Zypper::instance()->globalOpts().machine_readable)
{
display_done( id, cout, "");
return;
}
// non-interactive mode
- if (gSettings.non_interactive) {
+ if (Zypper::instance()->globalOpts().non_interactive) {
char c;
switch (default_action) {
case 0: c = 'a'; break;
bool read_bool_answer(const string & question, bool default_answer)
{
- if (!gSettings.machine_readable)
+ const GlobalOptions & gopts = Zypper::instance()->globalOpts();
+ if (!gopts.machine_readable)
cout << CLEARLN << question
<< " [" << _("yes") << "/" << _("no") << "]: "
<< flush;
// non-interactive mode: print the answer for convenience and return default
- if (gSettings.non_interactive)
+ if (gopts.non_interactive)
{
- if (!gSettings.machine_readable)
+ if (!gopts.machine_readable)
cout << (default_answer ? _("yes") : _("no")) << endl;
MIL << "answer (default): " << (default_answer ? 'y' : 'n') << endl;
return default_answer;
{
if (e.historySize())
{
- if (gSettings.verbosity > VERBOSITY_NORMAL)
+ if (Zypper::instance()->globalOpts().verbosity > VERBOSITY_NORMAL)
{
// print the whole history
cerr << e.historyAsString();
using boost::format;
extern ZYpp::Ptr God;
-extern GlobalOptions gSettings;
+
/**
*
*/
-void printInfo(const ZypperCommand & command, const vector<string> & arguments) {
+void printInfo(const Zypper & zypper)
+{
Resolvable::Kind kind;
- if (command == ZypperCommand::INFO) kind = ResTraits<Package>::kind;
- else if (command == ZypperCommand::RUG_PATCH_INFO) kind = ResTraits<Patch>::kind;
+ if (zypper.command() == ZypperCommand::INFO)
+ kind = ResTraits<Package>::kind;
+ else if (zypper.command() == ZypperCommand::RUG_PATCH_INFO)
+ kind = ResTraits<Patch>::kind;
ResPool pool = God->pool();
cout << endl;
- for(vector<string>::const_iterator nameit = arguments.begin();
- nameit != arguments.end(); ++nameit ) {
+ for(vector<string>::const_iterator nameit = zypper.arguments().begin();
+ nameit != zypper.arguments().end(); ++nameit )
+ {
// find the resolvable among installed
PoolItem installed;
cout << endl << endl;
- if (command == ZypperCommand::INFO)
- printPkgInfo(installer.item,installed);
- else if (command == ZypperCommand::RUG_PATCH_INFO)
- printPatchInfo(installer.item,installed);
+ if (zypper.command() == ZypperCommand::INFO)
+ printPkgInfo(zypper, installer.item,installed);
+ else if (zypper.command() == ZypperCommand::RUG_PATCH_INFO)
+ printPatchInfo(zypper, installer.item,installed);
}
}
}
</pre>
*
*/
-void printPkgInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item) {
-
- cout << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "))
+void printPkgInfo(const Zypper & zypper,
+ const PoolItem & pool_item, const PoolItem & ins_pool_item)
+{
+ cout << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
<< pool_item.resolvable()->repository().info().name() << endl;
cout << _("Name: ") << pool_item.resolvable()->name() << endl;
cout << _("Version: ") << pool_item.resolvable()->edition().asString() << endl;
</pre>
*
*/
-void printPatchInfo(const PoolItem & pool_item, const PoolItem & ins_pool_item) {
+void printPatchInfo(const Zypper & zypper, const PoolItem & pool_item, const PoolItem & ins_pool_item) {
cout << _("Name: ") << pool_item.resolvable()->name() << endl;
cout << _("Version: ") << pool_item.resolvable()->edition().asString() << endl;
cout << _("Arch: ") << pool_item.resolvable()->arch().asString() << endl;
cout << _("Created On: ") << patch->timestamp().asString() << endl;
cout << _("Reboot Required: ") << (patch->reboot_needed() ? _("Yes") : _("No")) << endl;
- if (!gSettings.is_rug_compatible)
+ if (!zypper.globalOpts().is_rug_compatible)
cout << _("Package Manager Restart Required") << ": ";
else
cout << _("Restart Required: ");
#ifndef ZYPPERINFO_H_
#define ZYPPERINFO_H_
-#include <string>
-#include <vector>
-
#include "zypp/PoolItem.h"
-#include "zypper-command.h"
+#include "zypper.h"
+
+void printInfo(const Zypper & zypper);
+
+void printPkgInfo(const Zypper & zypper,
+ const zypp::PoolItem & pool_item,
+ const zypp::PoolItem & ins_pool_item);
+
+void printPatchInfo(const Zypper & zypper,
+ const zypp::PoolItem & pool_item,
+ const zypp::PoolItem & ins_pool_item);
-void printInfo(const ZypperCommand & command, const std::vector<std::string> & arguments);
-void printPkgInfo(const zypp::PoolItem & pool_item, const zypp::PoolItem & ins_pool_item);
-void printPatchInfo(const zypp::PoolItem & pool_item, const zypp::PoolItem & ins_pool_item);
#endif /*ZYPPERINFO_H_*/
///////////////////////////////////////////////////////////////////
struct KeyRingReceive : public zypp::callback::ReceiveReport<zypp::KeyRingReport>
{
+ KeyRingReceive() : _gopts(Zypper::instance()->globalOpts()) {}
+
virtual bool askUserToAcceptUnsignedFile( const std::string &file )
{
- if (gSettings.no_gpg_checks)
+ if (_gopts.no_gpg_checks)
{
MIL << "Accepting unsigned file (" << file << ")" << endl;
cout_v << boost::format(_("Warning: Accepting an unsigned file %s.")) % file;
virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
{
- if (gSettings.no_gpg_checks)
+ if (_gopts.no_gpg_checks)
{
MIL << "Accepting file signed with an unknown key (" << file << "," << id << ")" << endl;
cout_n << boost::format(
const std::string& keyid = key.id(), keyname = key.name(),
fingerprint = key.fingerprint();
- if (gSettings.no_gpg_checks)
+ if (_gopts.no_gpg_checks)
{
MIL << boost::format("Automatically trusting key id %s, %s, fingerprint %s")
% keyid % keyname % fingerprint << endl;
const std::string& keyid = key.id(), keyname = key.name(),
fingerprint = key.fingerprint();
- if (gSettings.no_gpg_checks)
+ if (_gopts.no_gpg_checks)
{
MIL << boost::format(
"Ignoring failed signature verification for %s"
% file % keyid % keyname % fingerprint);
return read_bool_answer(question, false);
}
+
+ private:
+ const GlobalOptions & _gopts;
};
struct DigestReceive : public zypp::callback::ReceiveReport<zypp::DigestReport>
{
+ DigestReceive() : _gopts(Zypper::instance()->globalOpts()) {}
+
virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
{
std::string question = boost::str(boost::format(
_("No digest for file %s.")) % file) + " " + _("Continue?");
- return read_bool_answer(question, gSettings.no_gpg_checks);
+ return read_bool_answer(question, _gopts.no_gpg_checks);
}
virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
std::string question = boost::str(boost::format(
_("Unknown digest %s for file %s.")) %name % file) + " " +
_("Continue?");
- return read_bool_answer(question, gSettings.no_gpg_checks);
+ return read_bool_answer(question, _gopts.no_gpg_checks);
}
virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
{
- if (gSettings.no_gpg_checks)
+ if (_gopts.no_gpg_checks)
{
WAR << boost::format(
"Ignoring failed digest verification for %s (expected %s, found %s).")
% file.basename() % requested % found) + " " + _("Continue?");
return read_bool_answer(question, false);
}
+
+ private:
+ const GlobalOptions & _gopts;
};
///////////////////////////////////////////////////////////////////
logfile = ZYPPER_LOG;
zypp::base::LogControl::instance().logfile( logfile );
- Zypper zypper;
- return zypper.main(argc, argv);
+ return Zypper::instance()->main(argc, argv);
}
* \see Output Macros
* \see GlobalOptions::verbosity
*/
-#define COND_STREAM(STREAM,LEVEL) ((gSettings.verbosity >= LEVEL) ? STREAM : no_stream)
+#define COND_STREAM(STREAM,LEVEL) ((Zypper::instance()->globalOpts().verbosity >= LEVEL) ? STREAM : no_stream)
/** \name Output Macros
* Alway use these macros to produce output so that the verbosity options
// progress for downloading a file
struct DownloadProgressReportReceiver : public zypp::callback::ReceiveReport<zypp::media::DownloadProgressReport>
{
+ DownloadProgressReportReceiver() : _gopts(Zypper::instance()->globalOpts())
+ {}
+
virtual void start( const zypp::Url & file, zypp::Pathname localfile )
{
- if (gSettings.verbosity < VERBOSITY_NORMAL)
+ if (_gopts.verbosity < VERBOSITY_NORMAL)
return;
- else if (gSettings.verbosity == VERBOSITY_MEDIUM || gData.show_media_progress_hack)
+ else if (_gopts.verbosity == VERBOSITY_MEDIUM || gData.show_media_progress_hack)
{
cout << CLEARLN << _("Downloading: ")
<< zypp::Pathname(file.getPathName()).basename()
<< std::endl;
}
- else if (gSettings.verbosity >= VERBOSITY_HIGH)
+ else if (_gopts.verbosity >= VERBOSITY_HIGH)
{
cout << CLEARLN << _("Downloading: ") << file << std::endl;
}
virtual bool progress(int value, const zypp::Url & /*file*/)
{
- if (gSettings.verbosity < VERBOSITY_NORMAL)
+ if (_gopts.verbosity < VERBOSITY_NORMAL)
return true;
if (gData.show_media_progress_hack)
display_progress ("download", cout, "Downloading", value);
// not used anywhere in libzypp 3.20.0
virtual DownloadProgressReport::Action problem( const zypp::Url & /*file*/, DownloadProgressReport::Error error, const std::string & description )
{
- if (gSettings.verbosity >= VERBOSITY_NORMAL)
+ if (_gopts.verbosity >= VERBOSITY_NORMAL)
{
if (gData.show_media_progress_hack)
display_done ("download", cout_n);
// used only to finish, errors will be reported in media change callback (libzypp 3.20.0)
virtual void finish( const zypp::Url & /*file*/, Error error, const std::string & konreason )
{
- if (gSettings.verbosity < VERBOSITY_NORMAL)
+ if (_gopts.verbosity < VERBOSITY_NORMAL)
return;
else if (gData.show_media_progress_hack)
display_done ("download", cout);
// don't display errors here, they will be reported in media change callback
// display_error (error, konreason);
}
+
+ private:
+ const GlobalOptions & _gopts;
};
+
struct AuthenticationReportReceiver : public zypp::callback::ReceiveReport<zypp::media::AuthenticationReport>
{
virtual bool prompt(const zypp::Url & url,
const std::string & description,
zypp::media::AuthData & auth_data)
{
- if (gSettings.non_interactive)
+ if (Zypper::instance()->globalOpts().non_interactive)
{
MIL << "Non-interactive mode: aborting" << std::endl;
cout_vv << description << std::endl;
extern ZYpp::Ptr God;
extern RuntimeData gData;
-extern GlobalOptions gSettings;
-void cond_init_target () {
+void cond_init_target (Zypper & zypper) {
static bool done = false;
//! \todo do this so that it works in zypper shell
if (!done) {
cout_v << _("Initializing Target") << endl;
- God->initializeTarget(gSettings.root_dir);
+ God->initializeTarget(zypper.globalOpts().root_dir);
done = true;
}
}
}
//! @return true to retry solving now, false to cancel, indeterminate to continue
-tribool show_problem (const ResolverProblem & prob, ProblemSolutionList & todo)
+tribool show_problem (Zypper & zypper,
+ const ResolverProblem & prob, ProblemSolutionList & todo)
{
ostream& stm = cerr;
string det;
stm << " " << det << endl;
}
- if (gSettings.non_interactive)
+ if (zypper.globalOpts().non_interactive)
return false;
int reply;
}
// return true to retry solving, false to cancel transaction
-bool show_problems ()
+bool show_problems(Zypper & zypper)
{
bool retry = true;
ostream& stm = cerr;
// now list all problems with solution proposals
for (i = b; i != e; ++i) {
stm << endl;
- tribool stopnow = show_problem (*(*i), todo);
+ tribool stopnow = show_problem(zypper, *(*i), todo);
if (! indeterminate (stopnow)) {
retry = stopnow == true;
break;
typedef map<KindOf<Resolvable>,set<ResObject::constPtr> > KindToResObjectSet;
void show_summary_resolvable_list(const string & label,
- KindToResObjectSet::const_iterator it)
+ KindToResObjectSet::const_iterator it,
+ int verbosity)
{
cout << endl << label << endl;
{
ResObject::constPtr res(*resit);
- if (gSettings.verbosity == VERBOSITY_NORMAL)
+ if (verbosity == VERBOSITY_NORMAL)
{
// watch the terminal widht
if (cols_written == 0)
cout << INDENT;
// resolvable name
- cout << res->name() << (gSettings.verbosity ? "" : " ");
+ cout << res->name() << (verbosity ? "" : " ");
// plus edition and architecture for verbose output
cout_v << "-" << res->edition() << "." << res->arch();
// plus repo providing this package
cout_v << endl;
}
- if (gSettings.verbosity == VERBOSITY_NORMAL)
+ if (verbosity == VERBOSITY_NORMAL)
cout << endl;
}
* ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
* ZYPPER_EXIT_INF_RESTART_NEEDED - if one of patches to be installed needs package manager restart
*/
-int show_summary()
+int show_summary(Zypper & zypper)
{
int retv = -1; // nothing to do;
if (retv == -1)
{
- if (gSettings.machine_readable)
+ if (zypper.globalOpts().machine_readable)
cout << "<message type=\"warning\">" << _("Nothing to do.") << "</message>" << endl;
else
cout << _("Nothing to do.") << endl;
}
// no output for machines for now
- if (gSettings.machine_readable)
+ if (zypper.globalOpts().machine_readable)
return retv;
KindToResObjectSet toinstall;
it->second.size()
)) % kind_to_string_localized(it->first, it->second.size()));
- show_summary_resolvable_list(title, it);
+ show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
}
for (KindToResObjectSet::const_iterator it = todowngrade.begin();
it->second.size()
)) % kind_to_string_localized(it->first, it->second.size()));
- show_summary_resolvable_list(title, it);
+ show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
}
for (KindToResObjectSet::const_iterator it = toinstall.begin();
it->second.size()
)) % kind_to_string_localized(it->first, it->second.size()));
- show_summary_resolvable_list(title, it);
+ show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
}
for (KindToResObjectSet::const_iterator it = toremove.begin();
it->second.size()
)) % kind_to_string_localized(it->first, it->second.size()));
- show_summary_resolvable_list(title, it);
+ show_summary_resolvable_list(title, it, zypper.globalOpts().verbosity);
}
cout << endl;
dump_pool ();
}
-bool resolve()
+bool resolve(const Zypper & zypper)
{
establish ();
cout_v << _("Resolving dependencies...") << endl;
God->resolver()->setForceResolve(
- gSettings.is_rug_compatible ? true : copts.count("force-resolution") );
+ zypper.globalOpts().is_rug_compatible ? true : copts.count("force-resolution") );
return God->resolver()->resolvePool();
}
}
// patches
-void show_patches()
+void show_patches(const Zypper & zypper)
{
MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
Table tbl;
TableHeader th;
- th << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "))
+ th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
<< _("Name") << _("Version") << _("Category") << _("Status");
tbl << th;
// ----------------------------------------------------------------------------
-void list_patch_updates(bool best_effort)
+void list_patch_updates(const Zypper & zypper, bool best_effort)
{
Table tbl;
Table pm_tbl; // only those that affect packagemanager: they have priority
TableHeader th;
unsigned cols;
- th << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "))
+ th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "))
<< _("Name") << _("Version") << _("Category") << _("Status");
cols = 5;
tbl << th;
// ----------------------------------------------------------------------------
-void list_updates( const ResObject::Kind &kind, bool best_effort )
+void list_updates(const Zypper & zypper, const ResObject::Kind &kind, bool best_effort )
{
bool k_is_patch = kind == ResTraits<Patch>::kind;
if (k_is_patch)
- list_patch_updates( best_effort );
+ list_patch_updates(zypper, best_effort );
else {
Table tbl;
// TranslatorExplanation S stands for Status
th << _("S");
if (!hide_repo) {
- th << (gSettings.is_rug_compatible ? _("Catalog: ") : _("Repository: "));
+ th << (zypper.globalOpts().is_rug_compatible ? _("Catalog: ") : _("Repository: "));
}
- if (gSettings.is_rug_compatible) {
+ if (zypper.globalOpts().is_rug_compatible) {
th << _("Bundle");
}
name_col = th.cols();
if (!hide_repo) {
tr << res->repository().info().name();
}
- if (gSettings.is_rug_compatible)
+ if (zypper.globalOpts().is_rug_compatible)
tr << ""; // Bundle
tr << res->name ();
* ZYPPER_EXIT_INF_REBOOT_NEEDED - if one of patches to be installed needs machine reboot,
* ZYPPER_EXIT_INF_RESTART_NEEDED - if one of patches to be installed needs package manager restart
*/
-int solve_and_commit () {
+void solve_and_commit (Zypper & zypper)
+{
while (true) {
- bool success = resolve();
+ bool success = resolve(zypper);
if (success)
break;
- success = show_problems ();
+ success = show_problems(zypper);
if (! success) {
// TODO cancel transaction?
- return ZYPPER_EXIT_ERR_ZYPP; // #242736
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP); // #242736
+ return;
}
}
// returns -1, 0, ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
- int retv = show_summary();
+ int retv = show_summary(zypper);
bool was_installed = false;
if (retv >= 0) { // there are resolvables to install/uninstall
if (read_bool_answer(_("Continue?"), true)) {
- if (!confirm_licenses()) return ZYPPER_EXIT_OK;
+ if (!confirm_licenses(zypper)) return;
cerr_v << _("committing") << endl;
report_problem(e,
_("Problem downloading the package file from the repository:"),
_("Please, see the above error message to for a hint."));
- return ZYPPER_EXIT_ERR_ZYPP;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
}
catch ( const zypp::repo::RepoException & e ) {
ZYPP_CAUGHT(e);
report_problem(e,
_("Problem downloading the package file from the repository:"),
_("Please, see the above error message to for a hint."));
- return ZYPPER_EXIT_ERR_ZYPP;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
}
catch ( const zypp::FileCheckException & e ) {
ZYPP_CAUGHT(e);
"- refresh the repositories using 'zypper refresh'\n"
"- use another installation medium (if e.g. damaged)\n"
"- use another repository"));
- return ZYPPER_EXIT_ERR_ZYPP;
+ zypper.setExitCode(ZYPPER_EXIT_ERR_ZYPP);
+ return;
}
catch ( const Exception & excpt_r ) {
ZYPP_CAUGHT( excpt_r );
{
if (retv == ZYPPER_EXIT_INF_REBOOT_NEEDED)
{
- if (gSettings.machine_readable)
+ if (zypper.globalOpts().machine_readable)
cout << "<message type=\"warning\">" << _("One of installed patches requires reboot of"
" your machine. Please, do it as soon as possible.") << "</message>" << endl;
else
}
else if (retv == ZYPPER_EXIT_INF_RESTART_NEEDED)
{
- if (!gSettings.machine_readable)
+ if (!zypper.globalOpts().machine_readable)
cout << _("WARNING: One of installed patches affects the package"
" manager itself, thus it requires its restart before executing"
" any further operations.") << endl;
}
}
- return retv;
+ zypper.setExitCode(retv);
}
// TODO confirm licenses
// ask for [y/n/r] with 'r' for read the license text
// (opened throu more or less, etc...)
// - after negative answer, call solve_and_commit() again
-bool confirm_licenses()
+bool confirm_licenses(Zypper & zypper)
{
bool confirmed = true;
if (it->status().isToBeInstalled() &&
!it->resolvable()->licenseToConfirm().empty())
{
- if (gSettings.license_auto_agree)
+ if (zypper.cmdOpts().license_auto_agree)
{
// TranslatorExplanation The first %s is name of the resolvable, the second is its kind (e.g. 'zypper package')
- if (!gSettings.machine_readable)
+ if (!zypper.globalOpts().machine_readable)
cout << format(_("Automatically agreeing with %s %s license."))
% it->resolvable()->name()
% kind_to_string_localized(it->resolvable()->kind(),1)
string question = _("In order to install this package, you must agree"
" to terms of the above license. Continue?");
- if (!read_bool_answer(question, gSettings.license_auto_agree))
+ if (!read_bool_answer(question, zypper.cmdOpts().license_auto_agree))
{
confirmed = false;
- if (gSettings.non_interactive)
+ if (zypper.globalOpts().non_interactive)
{
//! \todo do this with _PL()
cout << endl <<
/**
* Initialize rpm database on target, if not already initialized.
*/
-void cond_init_target();
+void cond_init_target(Zypper & zypper);
/// Parse a capability string. On error print a message and return noCap
zypp::Capability safe_parse_cap (const Zypper & zypper,
const zypp::ResObject::Kind &kind,
const std::string &capstr );
-int show_summary();
+int show_summary(Zypper & zypper);
//std::string calculate_token();
-void establish ();
-bool resolve();
-void dump_pool ();
-void show_patches();
+void establish();
+bool resolve(const Zypper & zypper);
+void dump_pool();
+void show_patches(const Zypper & zypper);
bool xml_list_patches();
void xml_list_updates();
* \param kind resolvable type
* \param best_effort
*/
-void list_updates( const zypp::ResObject::Kind &kind, bool best_effort );
+void list_updates(const Zypper & zypper,
+ const zypp::ResObject::Kind &kind,
+ bool best_effort);
/**
* \param kind resolvable type
* or ZYPPER_EXIT_OK or ZYPPER_EXIT_ERR_ZYPP on zypp erorr.
*
*/
-int solve_and_commit ();
+void solve_and_commit(Zypper & zypper);
/**
* Loops through resolvables, checking if there is license to confirm. When
*
* \returns true if all licenses have been confirmed, false otherwise.
*/
-bool confirm_licenses();
+bool confirm_licenses(Zypper & zypper);
// copied from yast2-pkg-bindings:PkgModuleFunctions::DoProvideNameKind
struct ProvideProcess
extern ZYpp::Ptr God;
extern RuntimeData gData;
-extern GlobalOptions gSettings;
static bool refresh_raw_metadata(const Zypper & zypper,
try
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
if (!force_download)
{
return true;
}
*/
-static bool build_cache(const RepoInfo &repo, bool force_build)
+static bool build_cache(Zypper & zypper, const RepoInfo &repo, bool force_build)
{
if (force_build)
cout << _("Forcing building of repository cache") << endl;
try
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
manager.buildCache(repo, force_build ?
RepoManager::BuildForced : RepoManager::BuildIfNeeded);
}
static void do_init_repos(Zypper & zypper)
{
// load gpg keys
- cond_init_target ();
- RepoManager manager(gSettings.rm_options);
+ cond_init_target(zypper);
+ RepoManager manager(zypper.globalOpts().rm_options);
string specific_repo = copts.count("repo") ? copts["repo"].front() : "";
// handle root user differently
if (geteuid() == 0)
{
- if (refresh_raw_metadata(zypper, repo, false) || build_cache(repo, false))
+ if (refresh_raw_metadata(zypper, repo, false)
+ || build_cache(zypper, repo, false))
{
cerr << format(_("Disabling repository '%s' because of the above error."))
% repo.name() << endl;
if (done)
return;
- if ( !gSettings.disable_system_sources )
+ if ( !zypper.globalOpts().disable_system_sources )
{
do_init_repos(zypper);
}
// ----------------------------------------------------------------------------
-static void print_repo_list( const std::list<zypp::RepoInfo> &repos )
+static void print_repo_list(const Zypper & zypper,
+ const std::list<zypp::RepoInfo> &repos )
{
Table tbl;
// header
TableHeader th;
th << "#" << _("Enabled") << _("Refresh") << _("Type") << _("Alias") << _("Name");
- if (gSettings.verbosity > VERBOSITY_NORMAL)
+ if (zypper.globalOpts().verbosity > VERBOSITY_NORMAL)
th << "URI";
tbl << th;
it != repos.end(); ++it)
{
RepoInfo repo = *it;
- TableRow tr (gSettings.verbosity > VERBOSITY_NORMAL ? 6 : 7);
+ TableRow tr (zypper.globalOpts().verbosity > VERBOSITY_NORMAL ? 6 : 7);
// number
tr << str::numstring (i);
// name
tr << repo.name();
// url
- if (gSettings.verbosity > VERBOSITY_NORMAL)
+ if (zypper.globalOpts().verbosity > VERBOSITY_NORMAL)
tr << (*repo.baseUrlsBegin()).asString(); //! \todo properly handle multiple baseurls
tbl << tr;
// ----------------------------------------------------------------------------
-void list_repos()
+void list_repos(Zypper & zypper)
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
list<RepoInfo> repos;
try
}
}
// print repo list the rug's way
- else if (gSettings.is_rug_compatible)
+ else if (zypper.globalOpts().is_rug_compatible)
print_rug_sources_list(repos);
// print repo list as table
else
- print_repo_list(repos);
+ print_repo_list(zypper, repos);
}
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
-int refresh_repos(const Zypper & zypper, vector<string> & arguments)
+int refresh_repos(Zypper & zypper, vector<string> & arguments)
{
// need gpg keys when downloading (#304672)
- cond_init_target();
- RepoManager manager(gSettings.rm_options);
+ cond_init_target(zypper);
+ RepoManager manager(zypper.globalOpts().rm_options);
list<RepoInfo> repos;
try
{
MIL << "calling buildCache" << (force_build ? ", forced" : "") << endl;
- error = build_cache(repo, force_build);
+ error = build_cache(zypper, repo, force_build);
}
if (error)
// ----------------------------------------------------------------------------
static
-int add_repo(const Zypper & zypper, RepoInfo & repo)
+int add_repo(Zypper & zypper, RepoInfo & repo)
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
bool is_cd = true;
for(RepoInfo::urls_const_iterator it = repo.baseUrlsBegin();
cout_n << ":";
cout << endl;
- if (gSettings.is_rug_compatible)
+ if (zypper.globalOpts().is_rug_compatible)
{
cout_n << ( repo.enabled() ? "[x]" : "[ ]" );
cout_n << ( repo.autorefresh() ? "* " : " " );
cout_n << format(_("Reading data from '%s' media")) % repo.name() << endl;
bool error = refresh_raw_metadata(zypper, repo, false);
if (!error)
- error = build_cache(repo, false);
+ error = build_cache(zypper, repo, false);
if (error)
{
cerr << format(_("Problem reading data from '%s' media")) % repo.name() << endl;
// ----------------------------------------------------------------------------
-int add_repo_by_url( const Zypper & zypper,
+int add_repo_by_url( Zypper & zypper,
const zypp::Url & url, const string & alias,
const string & type,
tribool enabled, tribool autorefresh)
MIL << "going to add repository by url (alias=" << alias << ", url=" << url
<< ")" << endl;
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
RepoInfo repo;
if ( ! type.empty() )
// ----------------------------------------------------------------------------
//! \todo handle zypp exceptions
-int add_repo_from_file(const Zypper & zypper,
+int add_repo_from_file( Zypper & zypper,
const std::string & repo_file_url,
tribool enabled, tribool autorefresh)
{
if (!url.isValid())
return ZYPPER_EXIT_ERR_INVALID_ARGS;
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
list<RepoInfo> repos;
// read the repo file
return false;
}
*/
-static bool do_remove_repo(const RepoInfo & repoinfo)
+static bool do_remove_repo(Zypper & zypper, const RepoInfo & repoinfo)
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
bool found = true;
try
{
// ----------------------------------------------------------------------------
-bool remove_repo( const std::string &alias )
+bool remove_repo(Zypper & zypper, const std::string &alias )
{
- RepoManager manager(gSettings.rm_options);
RepoInfo info;
info.setAlias(alias);
- return do_remove_repo(info);
+ return do_remove_repo(zypper, info);
}
-bool remove_repo(const Url & url, const url::ViewOption & urlview)
+bool remove_repo(Zypper & zypper, const Url & url, const url::ViewOption & urlview)
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
bool found = true;
try
{
RepoInfo info = manager.getRepositoryInfo(url, urlview);
- found = do_remove_repo(info);
+ found = do_remove_repo(zypper, info);
}
catch (const repo::RepoNotFoundException & ex)
{
// ----------------------------------------------------------------------------
-void rename_repo(const std::string & alias, const std::string & newalias)
+void rename_repo(Zypper & zypper,
+ const std::string & alias, const std::string & newalias)
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
try
{
// ----------------------------------------------------------------------------
-void modify_repo(const string & alias)
+void modify_repo(Zypper & zypper, const string & alias)
{
// tell whether currenlty processed options are contradicting each other
// bool contradiction = false;
try
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
RepoInfo repo(manager.getRepositoryInfo(alias));
if (!indeterminate(enable))
// ---------------------------------------------------------------------------
-void cond_load_resolvables(const Zypper & zypper, bool to_pool)
+void cond_load_resolvables(Zypper & zypper, bool to_pool)
{
load_repo_resolvables(zypper, to_pool);
- if (!gSettings.disable_system_resolvables && to_pool)
- load_target_resolvables();
+ if (!zypper.globalOpts().disable_system_resolvables && to_pool)
+ load_target_resolvables(zypper);
}
// ---------------------------------------------------------------------------
-void load_repo_resolvables(const Zypper & zypper, bool to_pool)
+void load_repo_resolvables(Zypper & zypper, bool to_pool)
{
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(zypper.globalOpts().rm_options);
for (std::list<RepoInfo>::iterator it = gData.repos.begin();
it != gData.repos.end(); ++it)
{
cout_v << format(_("Repository '%s' not cached. Caching..."))
% repo.name() << endl;
- error = build_cache(repo, false);
+ error = build_cache(zypper, repo, false);
}
if (error)
// ---------------------------------------------------------------------------
-void load_target_resolvables(bool to_pool)
+void load_target_resolvables(Zypper & zypper, bool to_pool)
{
- if (!gSettings.machine_readable)
+ if (!zypper.globalOpts().machine_readable)
cout_n << _("Reading RPM database...");
MIL << "Going to read RPM database" << endl;
ResStore tgt_resolvables(God->target()->resolvables());
- if (!gSettings.machine_readable)
+ if (!zypper.globalOpts().machine_readable)
{
cout_v << " " << format(_("(%s resolvables)")) % tgt_resolvables.size();
cout_n << endl;
/**
* List defined repositories.
*/
-void list_repos();
+void list_repos(Zypper & zypper);
/**
* Refresh all enabled repositories.
*/
-int refresh_repos(const Zypper & zypper, std::vector<std::string> & arguments);
+int refresh_repos(Zypper & zypper, std::vector<std::string> & arguments);
/**
* \return ZYPPER_EXIT_ERR_ZYPP on unexpected zypp exception,
* ZYPPER_EXIT_OK otherwise
*/
-int add_repo_by_url(const Zypper & zypper,
+int add_repo_by_url(Zypper & zypper,
const zypp::Url & url,
const std::string & alias,
const std::string & type = "",
* \return ZYPPER_EXIT_ERR_ZYPP on unexpected zypp exception,
* ZYPPER_EXIT_OK otherwise
*/
-int add_repo_from_file(const Zypper & zypper,
+int add_repo_from_file(Zypper & zypper,
const std::string & repo_file_url,
boost::tribool enabled = boost::indeterminate,
boost::tribool autorefresh = boost::indeterminate);
/**
* Delte repository specified by \a alias.
*/
-bool remove_repo( const std::string &alias );
+bool remove_repo(Zypper & zypper, const std::string &alias );
-bool remove_repo( const zypp::Url & url, const zypp::url::ViewOption & urlview );
+bool remove_repo(Zypper & zypper,
+ const zypp::Url & url, const zypp::url::ViewOption & urlview);
/**
* Rename repository specified by \a alias to \a newalias.
*/
-void rename_repo(const std::string & alias, const std::string & newalias);
+void rename_repo(Zypper & zypper,
+ const std::string & alias, const std::string & newalias);
/**
* Modify repository properties.
*
* \param alias repository alias
*/
-void modify_repo(const std::string & alias);
+void modify_repo(Zypper & zypper, const std::string & alias);
/**
* \see load_repo_resolvables(bool)
* \see load_target_resolvables(bool)
*/
-void cond_load_resolvables(const Zypper & zypper, bool to_pool = true);
+void cond_load_resolvables(Zypper & zypper, bool to_pool = true);
/**
* Reads resolvables from the RPM database (installed resolvables) into the pool.
* <tt>false</tt> they will be stored \ref gData.target_resolvables
* (global ResStore variable).
*/
-void load_target_resolvables(bool to_pool = true);
+void load_target_resolvables(Zypper & zypper, bool to_pool = true);
/**
* Reads resolvables from the repository sqlite cache.
* <tt>false</tt> they will be stored in \ref gData.repo_resolvables
* (global ResStore vector).
*/
-void load_repo_resolvables(const Zypper & zypper, bool to_pool = true);
+void load_repo_resolvables(Zypper & zypper, bool to_pool = true);
/**
#include "zypp/Package.h"
//#include "zypp/target/rpm/RpmCallbacks.h"
+#include "zypper.h"
#include "zypper-callbacks.h"
#include "AliveCursor.h"
{
virtual void show( zypp::Message::constPtr message )
{
- if ( !gSettings.machine_readable )
+
+ if ( !Zypper::instance()->globalOpts().machine_readable )
{
cout_v << message << endl; // [message]important-msg-1.0-1
cout_n << message->text() << endl;
// check for disabled repos and limit list of repos accordingly.
// "-r/--repo" will override this
try {
- RepoManager manager(gSettings.rm_options);
+ RepoManager manager(Zypper::instance()->globalOpts().rm_options);
std::list<zypp::RepoInfo> known_repos = manager.knownRepositories();
std::list<zypp::RepoInfo>::const_iterator it_r;
for (it_r = known_repos.begin(); it_r != known_repos.end(); ++it_r)
const ZyppSearchOptions & options,
const vector<string> qstrings
) :
- _zypp(zypp), _options(options), _qstrings(qstrings), _query( gSettings.rm_options.repoCachePath ) {
+ _zypp(zypp), _options(options), _qstrings(qstrings),
+ _query( Zypper::instance()->globalOpts().rm_options.repoCachePath ) {
#if 0 // we don't search the pool but iterate on the cache directly, hence no repos needed
// no repos warning
#include "zypper-getopt.h"
#include "zypper-tabulator.h"
-extern GlobalOptions gSettings;
/**
* Represents zypper search options.
, _icache( &icache )
, _query( query )
, _options( options )
+ , _gopts(Zypper::instance()->globalOpts())
{
TableHeader header;
// TranslatorExplanation S as Status
header << _("S");
- if (gSettings.is_rug_compatible)
+ if (_gopts.is_rug_compatible)
header << _("Catalog");
else
header << _("Repository");
- if (gSettings.is_rug_compatible)
+ if (_gopts.is_rug_compatible)
// TranslatorExplanation This is Bundle in as used in rug.
header << _("Bundle");
else
row << "i"
<< pool_item.resolvable()->repository().info().name()
// TODO what about rug's Bundle?
- << (gSettings.is_rug_compatible ?
+ << (_gopts.is_rug_compatible ?
"" : kind_to_string_localized(pool_item.resolvable()->kind(), 1))
<< pool_item.resolvable()->name()
<< pool_item.resolvable()->edition().asString()
// add other fields to the result table
row << alias
// TODO what about rug's Bundle?
- << (gSettings.is_rug_compatible ?
+ << (_gopts.is_rug_compatible ?
"" : kind_to_string_localized(res->kind, 1))
<< res->name
<< res->edition.asString()
// the search options, contains i.e. the list of kinds to show
const ZyppSearchOptions & _options;
+
+ const GlobalOptions & _gopts;
};
ZYpp::Ptr God = NULL;
RuntimeData gData;
-GlobalOptions gSettings;
parsed_opts copts; // command options
+IMPL_PTR_TYPE(Zypper);
Zypper::Zypper()
: _argc(0), _argv(NULL),
MIL << "Bye!" << endl;
}
+Zypper_Ptr Zypper::instance()
+{
+ static Zypper_Ptr _instance;
+
+ if (!_instance)
+ _instance = new Zypper();
+
+ return _instance;
+}
+
int Zypper::main(int argc, char ** argv)
{
parsed_opts::const_iterator it;
if (gopts.count("rug-compatible"))
- gSettings.is_rug_compatible = true;
+ _gopts.is_rug_compatible = true;
// Help is parsed by setting the help flag for a command, which may be empty
// $0 -h,--help
setRunningHelp(true);
if (gopts.count("quiet")) {
- gSettings.verbosity = -1;
- DBG << "Verbosity " << gSettings.verbosity << endl;
+ _gopts.verbosity = -1;
+ DBG << "Verbosity " << _gopts.verbosity << endl;
}
if ((it = gopts.find("verbose")) != gopts.end()) {
- gSettings.verbosity += it->second.size();
+ _gopts.verbosity += it->second.size();
-// gSettings.verbosity += gopts["verbose"].size();
- cout << format(_("Verbosity: %d")) % gSettings.verbosity << endl;
- DBG << "Verbosity " << gSettings.verbosity << endl;
+// _gopts.verbosity += gopts["verbose"].size();
+ cout << format(_("Verbosity: %d")) % _gopts.verbosity << endl;
+ DBG << "Verbosity " << _gopts.verbosity << endl;
}
if (gopts.count("non-interactive")) {
- gSettings.non_interactive = true;
+ _gopts.non_interactive = true;
cout_n << _("Entering non-interactive mode.") << endl;
MIL << "Entering non-interactive mode" << endl;
}
if (gopts.count("no-gpg-checks")) {
- gSettings.no_gpg_checks = true;
+ _gopts.no_gpg_checks = true;
cout_n << _("Entering no-gpg-checks mode.") << endl;
MIL << "Entering no-gpg-checks mode" << endl;
}
}
if ((it = gopts.find("root")) != gopts.end()) {
- gSettings.root_dir = it->second.front();
- Pathname tmp(gSettings.root_dir);
+ _gopts.root_dir = it->second.front();
+ Pathname tmp(_gopts.root_dir);
if (!tmp.absolute())
{
cerr << _("The path specified in the --root option must be absolute.") << endl;
return;
}
- DBG << "root dir = " << gSettings.root_dir << endl;
- gSettings.rm_options.knownReposPath = gSettings.root_dir
- + gSettings.rm_options.knownReposPath;
- gSettings.rm_options.repoCachePath = gSettings.root_dir
- + gSettings.rm_options.repoCachePath;
- gSettings.rm_options.repoRawCachePath = gSettings.root_dir
- + gSettings.rm_options.repoRawCachePath;
+ DBG << "root dir = " << _gopts.root_dir << endl;
+ _gopts.rm_options.knownReposPath = _gopts.root_dir
+ + _gopts.rm_options.knownReposPath;
+ _gopts.rm_options.repoCachePath = _gopts.root_dir
+ + _gopts.rm_options.repoCachePath;
+ _gopts.rm_options.repoRawCachePath = _gopts.root_dir
+ + _gopts.rm_options.repoRawCachePath;
}
if ((it = gopts.find("reposd-dir")) != gopts.end()) {
- gSettings.rm_options.knownReposPath = it->second.front();
+ _gopts.rm_options.knownReposPath = it->second.front();
}
if ((it = gopts.find("cache-dir")) != gopts.end()) {
- gSettings.rm_options.repoCachePath = it->second.front();
+ _gopts.rm_options.repoCachePath = it->second.front();
}
if ((it = gopts.find("raw-cache-dir")) != gopts.end()) {
- gSettings.rm_options.repoRawCachePath = it->second.front();
+ _gopts.rm_options.repoRawCachePath = it->second.front();
}
- DBG << "repos.d dir = " << gSettings.rm_options.knownReposPath << endl;
- DBG << "cache dir = " << gSettings.rm_options.repoCachePath << endl;
- DBG << "raw cache dir = " << gSettings.rm_options.repoRawCachePath << endl;
+ DBG << "repos.d dir = " << _gopts.rm_options.knownReposPath << endl;
+ DBG << "cache dir = " << _gopts.rm_options.repoCachePath << endl;
+ DBG << "raw cache dir = " << _gopts.rm_options.repoRawCachePath << endl;
if (gopts.count("terse"))
{
- gSettings.machine_readable = true;
+ _gopts.machine_readable = true;
cout << "<?xml version='1.0'?>" << endl;
cout << "<stream>" << endl;
}
cout_n <<
_("Repositories disabled, using the database of installed packages only.")
<< endl;
- gSettings.disable_system_sources = true;
+ _gopts.disable_system_sources = true;
}
else
{
{
MIL << "System resolvables disabled" << endl;
cout_v << _("Ignoring installed resolvables...") << endl;
- gSettings.disable_system_resolvables = true;
+ _gopts.disable_system_resolvables = true;
}
/*
if (gopts.count("source"))
if (!url.isValid())
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
- gSettings.additional_sources.push_back(url);
+ _gopts.additional_sources.push_back(url);
}
}
*/
report_a_bug(cerr);
}
- if ( gSettings.machine_readable )
+ if ( globalOpts().machine_readable )
cout << "</stream>" << endl;
}
" package management running. All such applications must be closed before"
" using this command.");
- if ( gSettings.machine_readable )
+ if ( globalOpts().machine_readable )
cout << "<message type=\"error\">" << msg << "</message>" << endl;
else
cerr << msg << endl;
if (runningHelp()) { cout << _command_help << endl; return; }
// if (runningHelp()) display_command_help()
- list_repos();
+ list_repos(*this);
return;
}
warn_if_zmd();
// load gpg keys
- cond_init_target ();
+ cond_init_target(*this);
setExitCode(add_repo_by_url(*this,
url, _arguments[1]/*alias*/, type, enabled, refresh));
warn_if_zmd ();
- bool found = remove_repo(_arguments[0]);
+ bool found = remove_repo(*this, _arguments[0]);
if (found)
{
setExitCode(ZYPPER_EXIT_OK);
if (copts.count("loose-query"))
urlview = urlview - url::ViewOptions::WITH_QUERY_STR;
- found = remove_repo(url, urlview);
+ found = remove_repo(*this, url, urlview);
}
else
found = false;
return;
}
-// cond_init_target ();
+// cond_init_target(*this);
warn_if_zmd ();
try {
// also stores it
- rename_repo(_arguments[0], _arguments[1]);
+ rename_repo(*this, _arguments[0], _arguments[1]);
}
catch ( const Exception & excpt_r )
{
return;
}
- modify_repo(_arguments[0]);
+ modify_repo(*this, _arguments[0]);
}
// --------------------------( refresh )------------------------------------
if (copts.count("auto-agree-with-licenses")
|| copts.count("agree-to-third-party-licenses"))
- gSettings.license_auto_agree = true;
+ _cmdopts.license_auto_agree = true;
// check root user
if (geteuid() != 0)
// rug compatibility code
// switch on non-interactive mode if no-confirm specified
if (copts.count("no-confirm"))
- gSettings.non_interactive = true;
+ _gopts.non_interactive = true;
// read resolvable type
//! \todo support temporary additional repos
/*
- for ( std::list<Url>::const_iterator it = gSettings.additional_sources.begin(); it != gSettings.additional_sources.end(); ++it )
+ for ( std::list<Url>::const_iterator it = globalOpts().additional_sources.begin(); it != globalOpts().additional_sources.end(); ++it )
{
include_source_by_url( *it );
}
" Nothing can be installed.") << endl;
}
- cond_init_target ();
+ cond_init_target(*this);
cond_load_resolvables(*this);
bool install_not_remove = command() == ZypperCommand::INSTALL;
}
else
{
- setExitCode(solve_and_commit());
- return;
+ solve_and_commit(*this);
}
- setExitCode(ZYPPER_EXIT_OK);
return;
}
if (exitCode() != ZYPPER_EXIT_OK)
return;
- cond_init_target();
+ cond_init_target(*this);
// load only repo resolvables, we don't need the installed ones
load_repo_resolvables(*this, false /* don't load to pool */);
return;
}
- if (gSettings.disable_system_resolvables || copts.count("uninstalled-only"))
+ if (globalOpts().disable_system_resolvables || copts.count("uninstalled-only"))
options.setInstalledFilter(ZyppSearchOptions::UNINSTALLED_ONLY);
if (copts.count("installed-only")) options.setInstalledFilter(ZyppSearchOptions::INSTALLED_ONLY);
options.addKind( kind );
}
}
- else if (gSettings.is_rug_compatible) {
+ else if (globalOpts().is_rug_compatible) {
options.clearKinds();
options.addKind( ResTraits<Package>::kind );
}
if (exitCode() != ZYPPER_EXIT_OK)
return;
- cond_init_target(); // calls ZYpp::initializeTarget("/");
+ cond_init_target(*this);
establish();
return;
}
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
}
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
cond_load_resolvables(*this);
- establish ();
- show_patches ();
- setExitCode(ZYPPER_EXIT_OK);
+ establish();
+ show_patches(*this);
+
return;
}
}
string skind = copts.count("type")? copts["type"].front() :
- gSettings.is_rug_compatible? "package" : "patch";
+ globalOpts().is_rug_compatible? "package" : "patch";
kind = string_to_kind (skind);
if (kind == ResObject::Kind ()) {
cerr << format(_("Unknown resolvable type: %s")) % skind << endl;
bool best_effort = copts.count( "best-effort" );
- if (gSettings.is_rug_compatible && best_effort) {
+ if (globalOpts().is_rug_compatible && best_effort) {
best_effort = false;
// 'rug' is the name of a program and must not be translated
// 'best-effort' is a program parameter and can not be translated
cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
}
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
cond_load_resolvables(*this);
establish ();
- list_updates( kind, best_effort );
+ list_updates(*this, kind, best_effort );
setExitCode(ZYPPER_EXIT_OK);
return;
return;
}
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
// rug compatibility code
// switch on non-interactive mode if no-confirm specified
if (copts.count("no-confirm"))
- gSettings.non_interactive = true;
+ _gopts.non_interactive = true;
if (copts.count("auto-agree-with-licenses")
|| copts.count("agree-to-third-party-licenses"))
- gSettings.license_auto_agree = true;
+ _cmdopts.license_auto_agree = true;
string skind = copts.count("type")? copts["type"].front() :
- gSettings.is_rug_compatible? "package" : "patch";
+ globalOpts().is_rug_compatible? "package" : "patch";
kind = string_to_kind (skind);
if (kind == ResObject::Kind ()) {
cerr << format(_("Unknown resolvable type: %s")) % skind << endl;
bool best_effort = copts.count( "best-effort" );
- if (gSettings.is_rug_compatible && best_effort) {
+ if (globalOpts().is_rug_compatible && best_effort) {
best_effort = false;
// 'rug' is the name of a program and must not be translated
// 'best-effort' is a program parameter and can not be translated
cerr << _("Running as 'rug', can't do 'best-effort' approach to update.") << endl;
}
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
cond_load_resolvables(*this);
establish ();
- bool skip_interactive = copts.count("skip-interactive") || gSettings.non_interactive;
+ bool skip_interactive = copts.count("skip-interactive") || globalOpts().non_interactive;
mark_updates( kind, skip_interactive, best_effort );
// ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
else
{
- setExitCode(solve_and_commit());
- return;
+ solve_and_commit(*this);
}
- setExitCode(ZYPPER_EXIT_OK);
return;
}
}
if (copts.count("auto-agree-with-licenses"))
- gSettings.license_auto_agree = true;
+ _cmdopts.license_auto_agree = true;
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
// ZYPPER_EXIT_INF_REBOOT_NEEDED, or ZYPPER_EXIT_INF_RESTART_NEEDED
else
{
- setExitCode(solve_and_commit());
- return;
+ solve_and_commit(*this);
}
- setExitCode(ZYPPER_EXIT_OK);
return;
}
return;
}
- cond_init_target ();
+ cond_init_target(*this);
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
cond_load_resolvables(*this);
establish ();
- printInfo(command(),_arguments);
+ printInfo(*this);
setExitCode(ZYPPER_EXIT_OK);
return;
#include <string>
#include <vector>
+#include "zypp/base/ReferenceCounted.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+
#include "zypp/ResStore.h"
#include "zypp/RepoInfo.h"
#include "zypp/RepoManager.h"
is_rug_compatible(false),
non_interactive(false),
no_gpg_checks(false),
- license_auto_agree(false),
machine_readable(false),
root_dir("/")
{}
bool is_rug_compatible;
bool non_interactive;
bool no_gpg_checks;
- bool license_auto_agree; // TODO move to commandOptions
bool machine_readable;
std::string root_dir;
zypp::RepoManagerOptions rm_options;
};
-class Zypper
+struct CommandOptions
{
-public:
+ CommandOptions()
+ :
+ license_auto_agree(false)
+ {}
- Zypper();
- ~Zypper();
+ bool license_auto_agree;
+};
+
+
+DEFINE_PTR_TYPE(Zypper);
+
+class Zypper : public zypp::base::ReferenceCounted, private zypp::base::NonCopyable
+{
+public:
+ static Zypper_Ptr instance();
int main(int argc, char ** argv);
// setters & getters
const GlobalOptions & globalOpts() const { return _gopts; }
+ const CommandOptions & cmdOpts() const { return _cmdopts; }
const parsed_opts & cOpts() const { return _copts; }
const ZypperCommand & command() const { return _command; }
const std::string & commandHelp() const { return _command_help; }
+ const std::vector<std::string> & arguments() const { return _arguments; }
int exitCode() const { return _exit_code; }
void setExitCode(int exit) { _exit_code = exit; }
bool runningShell() const { return _running_shell; }
char ** argv() { return _running_shell ? _sh_argv : _argv; }
private:
+ Zypper();
+ ~Zypper();
+
void processGlobalOptions();
void processCommandOptions();
void commandShell();
char ** _argv;
GlobalOptions _gopts;
+ CommandOptions _cmdopts;
parsed_opts _copts;
ZypperCommand _command;
std::vector<std::string> _arguments;
int _sh_argc;
char **_sh_argv;
-
};
+
struct RuntimeData
{
RuntimeData()
};
extern RuntimeData gData;
-extern GlobalOptions gSettings;
extern std::ostream no_stream;
#endif /*ZYPPER_H*/