ResolverInfoMisc.cc

Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
00002 /* ResolverInfoMisc.cc
00003  *
00004  * Copyright (C) 2000-2002 Ximian, Inc.
00005  * Copyright (C) 2005 SUSE Linux Products GmbH
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License,
00009  * version 2, as published by the Free Software Foundation.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #include <map>
00023 #include <sstream>
00024 
00025 #include "zypp/solver/detail/ResolverInfo.h"
00026 #include "zypp/solver/detail/ResolverInfoMisc.h"
00027 #include "zypp/base/String.h"
00028 #include "zypp/base/Logger.h"
00029 #include "zypp/base/Gettext.h"
00030 
00032 namespace zypp
00033 { 
00034 
00035   namespace solver
00036   { 
00037 
00038     namespace detail
00039     { 
00040 
00041 using namespace std;
00042 
00043 IMPL_PTR_TYPE(ResolverInfoMisc);
00044 
00045 //---------------------------------------------------------------------------
00046 
00047 
00048 std::ostream &
00049 ResolverInfoMisc::dumpOn( std::ostream & os ) const
00050 {
00051     ResolverInfo::dumpOn (os);          // this already shows the affected item
00052 
00053     os << ">>" << message() << "<<";
00054     os << itemsToString(true);
00055     if (!_action.empty()) {
00056         os << _(", Action: ") << _action << endl;
00057     }
00058     os << _(", Trigger: ");
00059     switch (_trigger) {
00060         case ResolverInfoMisc::NONE:            os << "none"; break;
00061         case ResolverInfoMisc::OBSOLETE:        os << "obsoletes"; break;
00062         case ResolverInfoMisc::REQUIRE:         os << "requires"; break;
00063         case ResolverInfoMisc::CONFLICT:        os << "conflicts"; break;
00064     }
00065     os << endl;
00066     return os;
00067 }
00068 
00069 //---------------------------------------------------------------------------
00070 
00071 ResolverInfoMisc::ResolverInfoMisc  (ResolverInfoType detailedtype, PoolItem_Ref affected, int priority, const Capability & capability)
00072     : ResolverInfoContainer (detailedtype, affected, priority)
00073       , _capability (capability)
00074       , _trigger (NONE)
00075 {
00076 }
00077 
00078 
00079 ResolverInfoMisc::~ResolverInfoMisc ()
00080 {
00081 }
00082 
00083 //---------------------------------------------------------------------------
00084 
00085 static string
00086 translateResTraits (const Resolvable::Kind & kind)
00087 {
00088     if (kind == ResTraits<Package>::kind) {
00089         // Translator: Notation for (RPM) package
00090         return _( "package" );
00091     }
00092     else if (kind == ResTraits<Selection>::kind) {
00093         // Translator: Notation for SuSE package selection (set of packages)
00094         return _( "selection" );
00095     }
00096     else if (kind == ResTraits<Pattern>::kind) {
00097         // Translator: Notation for SuSE installation pattern (set of packages, describing use of system)
00098         return _( "pattern" );
00099     }
00100     else if (kind == ResTraits<Product>::kind) {
00101         // Translator: Notation for product
00102         return _( "product" );
00103     }
00104     else if (kind == ResTraits<Patch>::kind) {
00105         // Translator: Notation for patch
00106         return _( "patch" );
00107     }
00108     else if (kind == ResTraits<Script>::kind) {
00109         // Translator: Notation for script (part of a patch)
00110         return _( "script" );
00111     }
00112     else if (kind == ResTraits<Message>::kind) {
00113         // Translator: Notation for message (part of a patch)
00114         return _( "message" );
00115     }
00116     else if (kind == ResTraits<Atom>::kind) {
00117         // Translator: Notation for atom (part of a patch)
00118         return _( "atom" );
00119     }
00120     else if (kind == ResTraits<SystemResObject>::kind) {
00121         // Translator: Notation for computer system
00122         return _( "system" );
00123     }
00124 
00125     // Translator: Generic term for an item with dependencies, please leave untranslated for now
00126     return _("Resolvable");
00127 }
00128 
00129 
00130 std::string
00131 ResolverInfoMisc::message (void) const
00132 {
00133     string msg;
00134 
00135     string affected_str = ResolverInfo::toString(affected());
00136 
00137     switch (type()) {
00138 
00139         //===================
00140         // from ResolverContext
00141 
00142         case RESOLVER_INFO_TYPE_INVALID_SOLUTION: {
00143             // TranslatorExplanation: Additional information to dependency solver result, no solution could be found
00144             msg = _("Marking this resolution attempt as invalid.");
00145         }
00146         break;
00147 
00148         case RESOLVER_INFO_TYPE_UNINSTALLABLE: {
00149             // Translator: %s = name of packages,patch,...
00150             // TranslatorExplanation: Additional information to dependency solver result.
00151             msg = str::form (_("Marking resolvable %s as uninstallable"),
00152                         affected_str.c_str());
00153         }
00154         break;
00155 
00156         case RESOLVER_INFO_TYPE_REJECT_INSTALL: {
00157             // Translator: %s = name of packages,patch,...
00158             // TranslatorExplanation: Additional information to dependency solver result.
00159             msg = str::form (_("%s is scheduled to be installed, but this is not possible because of dependency problems."),
00160                         affected_str.c_str());
00161         }
00162         break;
00163 
00164         case RESOLVER_INFO_TYPE_INSTALL_TO_BE_UNINSTALLED: {
00165             // Translator: %s = name of package,patch,...
00166             // TranslatorExplanation: Additional information to dependency solver result.
00167             msg = str::form (_("Can't install %s since it is already marked as needing to be uninstalled"),
00168                          affected_str.c_str());
00169         }
00170         break;
00171 
00172         case RESOLVER_INFO_TYPE_INSTALL_UNNEEDED: {
00173             // Translator: %s = name of patch
00174             // TranslatorExplanation: A patch which is not needed (does not apply) cant be installed
00175             // TranslatorExplanation: Patches contain updates (bug fixes) to packages. Such fixes
00176             // TranslatorExplanation: do only apply if the package to-be-fixed is actually installed.
00177             // TranslatorExplanation: Here a patch was selected for installation but the to-be-fixed
00178             // TranslatorExplanation: package is not installed.
00179             msg = str::form (_("Can't install %s since it is does not apply to this system."),
00180                         affected_str.c_str());
00181         }
00182         break;
00183 
00184         case RESOLVER_INFO_TYPE_INSTALL_PARALLEL: {
00185             // affected() = item 1 which has to be installed
00186             // _capability =
00187             // other() = item 2 which has to be installed
00188             // other_capability() =
00189             // Translator: %s = name of package,patch,...
00190             msg = str::form (_("Can't install %s, since %s is already marked as needing to be installed"),
00191                              affected_str.c_str(),
00192                              toString (other()).c_str());
00193         }
00194         break;
00195 
00196         case RESOLVER_INFO_TYPE_INCOMPLETES: {
00197             // Translator: %s = name of patch,product
00198             msg = str::form (_("This would invalidate %s."),
00199                         affected_str.c_str());
00200         }
00201         break;
00202 
00203         //===================
00204         // from QueueItemEstablish
00205 
00206         //-------------------
00207         // Establishing p
00208         case RESOLVER_INFO_TYPE_ESTABLISHING: {
00209             // Translator: %s = name of patch, pattern, ...
00210             // TranslatorExplanation: Establishing is the process of computing which patches are needed
00211             // TranslatorExplanation: This is just a progress indicator
00212             // TranslatorExplanation: It is also used for other types of resolvables in order to verify
00213             // TranslatorExplanation: the completeness of their dependencies
00214             msg = str::form (_("Establishing %s"), affected_str.c_str());
00215         }
00216         break;
00217 
00218 
00219         //===================
00220         // from QueueItemInstall
00221 
00222         //-------------------
00223         // Installing p
00224 
00225         case RESOLVER_INFO_TYPE_INSTALLING: {
00226             // affected() = resolvable to be installed
00227             // _capability =
00228             // other() =
00229             // other_capability() =
00230 
00231             // Translator: %s = name of package,patch,...
00232             // TranslatorExample: Installing foo
00233             // TranslatorExplanation: Just a progress indicator that something is scheduled for installation
00234             // Translator: %s = packagename
00235             msg = str::form (_("Installing %s"),
00236                              affected_str.c_str());
00237         }
00238         break;
00239 
00240         //-------------------
00241         // Updating q to p
00242 
00243         case RESOLVER_INFO_TYPE_UPDATING: {
00244             // affected() = updated resolvable
00245             // _capability =
00246             // other() = currently installed, being updated resolvable
00247             // other_capability() =
00248 
00249             // Translator: 1.%s and 2.%s = name of package
00250             // TranslatorExample: Updating foo-1.1 to foo-1.2
00251             // TranslatorExplanation: Just a progress indicator that something is scheduled for upgrade
00252             msg = str::form (_("Updating %s to %s"),
00253                              ResolverInfo::toString (other()).c_str(),
00254                              affected_str.c_str());
00255         }
00256         break;
00257 
00258         //-------------------
00259         // skipping p, already installed
00260 
00261         case RESOLVER_INFO_TYPE_SKIPPING: {
00262             // affected() =
00263             // _capability =
00264             // other() =
00265             // other_capability() =
00266 
00267             // Translator: %s = name of package,patch,...
00268             // TranslatorExample: Skipping foo: already installed
00269             // TranslatorExplanation: An installation request for foo is skipped since foo is already installed
00270             msg = str::form (_("Skipping %s: already installed"), affected_str.c_str());
00271         }
00272         break;
00273 
00274         //===================
00275         // from QueueItemRequire
00276 
00277         //-------------------
00278         // There are no alternative installed providers of c [for p]
00279 
00280         case RESOLVER_INFO_TYPE_NO_OTHER_PROVIDER: {
00281             // affected() = is set
00282             // _capability = is set
00283             // other() =
00284             // other_capability() =
00285 
00286             // Translator: 1.%s = dependency
00287             // TranslatorExample: There are no alternative installed providers of foo
00288             // TranslatorExplanation: A resolvable is to be uninstalled. It provides 'foo' which is needed by others
00289             // TranslatorExplanation: We just found out that 'foo' is not provided by anything else (an alternative)
00290             // TranslatorExplanation: removal of this resolvable would therefore break dependency
00291             // TranslatorExplanation: This is an error message explaining that the resolvable cannot be uninstalled
00292             msg = str::form (_("There are no alternative installed providers of %s"), ResolverInfo::toString (_capability).c_str());
00293             if (affected()) {
00294                 msg += " ";
00295                 // Translator: 1.%s = name of package,patch....
00296                 // TranslatorExample: for bar
00297                 // TranslatorExplanation: extension to previous message if we know what the resolvable is
00298                 msg += str::form (_("for %s"), affected_str.c_str());
00299             }
00300         }
00301         break;
00302 
00303         //-------------------
00304         // There are no installable providers of c [for p]
00305 
00306         case RESOLVER_INFO_TYPE_NO_PROVIDER: {
00307             // affected() =
00308             // _capability =
00309             // other() =
00310             // other_capability() =
00311 
00312             // Translator: 1.%s = dependency
00313             // TranslatorExample: There are no installable providers of foo
00314             // TranslatorExplanation: A resolvable is to be installed which requires foo
00315             // TranslatorExplanation: But there is nothing available to fulfill this requirement
00316             // TranslatorExplanation: This is an error message explaining that the resolvable cannot be installed
00317             msg = str::form (_("There are no installable providers of %s"), ResolverInfo::toString (_capability).c_str());
00318             if (affected()) {
00319                 msg += " ";
00320                 // Translator: 1.%s = name of package,patch....
00321                 // TranslatorExample: for bar
00322                 // TranslatorExplanation: extension to previous message if we know what the resolvable is
00323                 msg += str::form (_("for %s"), affected_str.c_str());
00324             }
00325         }
00326         break;
00327 
00328         //-------------------
00329         // Upgrade to q to avoid removing p is not possible
00330 
00331         case RESOLVER_INFO_TYPE_NO_UPGRADE: {
00332             // affected() = resolvable to be removed
00333             // _capability =
00334             // other() = failed upgrade to affected()
00335             // other_capability() =
00336 
00337             string other_str = ResolverInfo::toString(other());
00338             // Translator: 1.%s = name of package,patch,..., 2.%s = name of package,patch,...
00339             // TranslatorExample: Upgrade to foo to avoid removing bar is not possible
00340             // TranslatorExplanation: bar requires something from foo
00341             msg = str::form (_("Upgrade to %s to avoid removing %s is not possible."),
00342                                     other_str.c_str(),
00343                                     affected_str.c_str());
00344         }
00345         break;
00346 
00347         //-------------------
00348         // p provides c but is scheduled to be uninstalled
00349 
00350         case RESOLVER_INFO_TYPE_UNINSTALL_PROVIDER: {
00351             // affected() = requirer of capability
00352             // _capability = provided by other()
00353             // other() = provider of capability
00354             // other_capability() = - empty -
00355 
00356             string other_str = ResolverInfo::toString(other());
00357             string cap_str = ResolverInfo::toString (_capability);
00358             // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
00359             msg = str::form (_("%s provides %s, but is scheduled to be uninstalled."),
00360                              other_str.c_str(),
00361                              cap_str.c_str());
00362         }
00363         break;
00364 
00365         //-------------------
00366         // p provides c but another version is already installed
00367 
00368         case RESOLVER_INFO_TYPE_PARALLEL_PROVIDER: {
00369             // affected() = requirer of capability
00370             // _capability = provided by other()
00371             // other() = provider of capability
00372             // other_capability() = - empty -
00373 
00374             string other_str = ResolverInfo::toString(other());
00375             string cap_str = ResolverInfo::toString (_capability);
00376             // Translator: 1.%s = name of package,patch,...; 2.%s = dependency; 3.%s type (package, patch, ...)
00377             msg = str::form (_("%s provides %s, but another version of that %s is already installed."),
00378                              other_str.c_str(),
00379                              cap_str.c_str(),
00380                              translateResTraits(other()->kind()).c_str());
00381         }
00382         break;
00383 
00384         //-------------------
00385         // p provides c but is uninstallable
00386 
00387         case RESOLVER_INFO_TYPE_NOT_INSTALLABLE_PROVIDER: {
00388             // affected() = requirer of capability
00389             // _capability = provided by other()
00390             // other() = provider of capability
00391             // other_capability() = - empty -
00392 
00393             string other_str = ResolverInfo::toString(other());
00394             string cap_str = ResolverInfo::toString (_capability);
00395             // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
00396             msg = str::form (_("%s provides %s, but it is uninstallable.  Try installing it on its own for more details."),
00397                              other_str.c_str(),
00398                              cap_str.c_str());
00399         }
00400         break;
00401 
00402         //-------------------
00403         // p provides c but is locked
00404 
00405         case RESOLVER_INFO_TYPE_LOCKED_PROVIDER: {
00406             // affected() = requirer of capability
00407             // _capability = provided by other()
00408             // other() = provider of capability
00409             // other_capability() = - empty -
00410 
00411             string other_str = ResolverInfo::toString(other());
00412             string cap_str = ResolverInfo::toString (_capability);
00413             // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
00414             msg = str::form (_("%s provides %s, but it is locked."),
00415                              other_str.c_str(),
00416                              cap_str.c_str());
00417         }
00418         break;
00419 
00420         //-------------------
00421         // p provides c but has other architecture
00422 
00423         case RESOLVER_INFO_TYPE_OTHER_ARCH_PROVIDER: {
00424             // affected() = requirer of capability
00425             // _capability = provided by other()
00426             // other() = provider of capability
00427             // other_capability() = - empty -
00428 
00429             string other_str = ResolverInfo::toString(other());
00430             string cap_str = ResolverInfo::toString (_capability);
00431             // Translator: 1.%s = name of package,patch,...; 2.%s = dependency;
00432             msg = str::form (_("%s provides %s, but has another architecture."),
00433                              other_str.c_str(),
00434                              cap_str.c_str());
00435         }
00436         break;
00437         
00438 
00439         //-------------------
00440         // Can't satisfy requirement
00441 
00442         case RESOLVER_INFO_TYPE_CANT_SATISFY: {
00443             // affected() = requirer of capability
00444             // _capability = required capability
00445             // other() = - empty -
00446             // other_capability() = - empty -
00447 
00448             string cap_str = ResolverInfo::toString (_capability);
00449             // Translator: 1.%s = dependency. 2.%s name of package, patch, ...
00450             msg = str::form (_("Can't satisfy requirement %s for %s"),
00451                                 cap_str.c_str(),
00452                                 affected_str.c_str());
00453         }
00454         break;
00455 
00456         //===================
00457         // from QueueItemUninstall
00458 
00459         //-------------------
00460         // p is to-be-installed, so it won't be unlinked.
00461 
00462         case RESOLVER_INFO_TYPE_UNINSTALL_TO_BE_INSTALLED: {
00463             // affected() = to-be-installed resolvable which was scheduled to be uninstalled
00464             // _capability =
00465             // other() =
00466             // other_capability() =
00467 
00468             // Translator: %s = name of package,patch,...
00469             // TranslatorExample: foo is required by other to-be-installed resolvable, so it won't be unlinked.
00470             // TranslatorExplanation: Cant uninstall foo since it is required by an to-be-installed resolvable
00471             msg = str::form (_("%s is required by other to-be-installed resolvable, so it won't be unlinked."),
00472                              affected_str.c_str());
00473         }
00474         break;
00475 
00476         //-------------------
00477         // p is required by another installed resolvable q, so it won't be unlinked.
00478 
00479         case RESOLVER_INFO_TYPE_UNINSTALL_INSTALLED: {
00480             // affected() = provider of cap
00481             // _capability =
00482             // other() =
00483             // other_capability() =
00484 
00485             // Translator: %s = name of package,patch,...
00486             // TranslatorExample: foo is required by other installed resolvable, so it won't be unlinked.
00487             // TranslatorExplanation: Cant uninstall foo since it is required by an installed resolvable
00488             msg = str::form (_("%s is required by other installed resolvable, so it won't be unlinked."),
00489                              affected_str.c_str());
00490         }
00491         break;
00492 
00493         //-------------------
00494         // cant uninstall, its locked
00495 
00496         case RESOLVER_INFO_TYPE_UNINSTALL_LOCKED: {
00497             // affected() = to-be-uninstalled resolvable which is locked
00498             // _capability =
00499             // other() =
00500             // other_capability() =
00501 
00502             // Translator: %s = name of package,patch,...
00503             // TranslatorExample: foo is locked and cannot be uninstalled.
00504             // TranslatorExplanation: foo is to-be-uninstalled but it is locked
00505             msg = str::form (_("%s is locked and cannot be uninstalled."),
00506                              affected_str.c_str());
00507         }
00508         break;
00509 
00510         //===================
00511         // from QueueItemConflict
00512 
00513         //-------------------
00514         // to-be-installed p conflicts with q due to c
00515 
00516         case RESOLVER_INFO_TYPE_CONFLICT_CANT_INSTALL: {
00517             // affected() = provider of capability
00518             // _capability = provided by provider
00519             // other() = conflict issuer
00520             // other_capability() = conflict capability
00521 
00522             // Translator: 1.%s and 2.%s = Dependency; 4.%s = name of package,patch,...
00523             // TranslatorExample: A conflict over foo (bar) requires the removal of to-be-installed xyz
00524             msg = str::form(_("A conflict over %s (%s) requires the removal of to-be-installed %s"),
00525                             ResolverInfo::toString (_capability).c_str(),
00526                             ResolverInfo::toString (_other_capability).c_str(),
00527                             affected_str.c_str());
00528         }
00529         break;
00530 
00531         //-------------------
00532         // uninstalled p is marked uninstallable it conflicts [with q] due to c
00533 
00534         case RESOLVER_INFO_TYPE_CONFLICT_UNINSTALLABLE: {
00535             // affected() = provider of capability
00536             // _capability = provided by provider
00537             // other() = conflict issuer
00538             // other_capability() = conflict capability from issuer
00539 
00540             // Translator: 1.%s = name of package,patch,...; 3.%s and 4.%s = Dependency;
00541             // TranslatorExample: Marking xyz as uninstallable due to conflicts over foo (bar)
00542             msg = str::form (_("Marking %s as uninstallable due to conflicts over %s"),
00543                                 affected_str.c_str(),
00544                                 ResolverInfo::toString (_capability).c_str());
00545             PoolItem_Ref  issuer = other();
00546             if (issuer) {
00547                 msg += " ";
00548                 // Translator: %s = name of package,patch
00549                 // TranslatorExample: from abc
00550                 msg += str::form (_("from %s"),
00551                         ResolverInfo::toString (issuer).c_str());
00552             }
00553         }
00554         break;
00555 
00556         //===================
00557         //-------------------
00558 
00559         default:
00560             WAR << "Not an InfoMisc type: " << type() << endl;
00561 //          msg = "Unknown";
00562         break;
00563     }
00564     return msg;
00565 }
00566 
00567 //---------------------------------------------------------------------------
00568 
00569 bool
00570 ResolverInfoMisc::merge (ResolverInfo_Ptr info)
00571 {
00572     bool res;
00573     ResolverInfoMisc_Ptr to_be_merged = dynamic_pointer_cast<ResolverInfoMisc>(info);
00574 
00575     res = ResolverInfo::merge(to_be_merged);
00576     if (!res) return res;
00577 
00578     if (type() == to_be_merged->type()
00579         && affected() == to_be_merged->affected()
00580         && _capability == to_be_merged->_capability) {
00581 
00582         return true;
00583     }
00584 
00585     return false;
00586 }
00587 
00588 
00589 ResolverInfo_Ptr
00590 ResolverInfoMisc::copy (void) const
00591 {
00592     ResolverInfoMisc_Ptr cpy = new ResolverInfoMisc(type(), affected(), priority(), _capability);
00593 
00594     ((ResolverInfoContainer_Ptr)cpy)->copy (this);
00595     cpy->_other_item = _other_item;
00596     cpy->_other_capability = _other_capability;
00597     cpy->_action = _action;
00598     cpy->_trigger = _trigger;
00599 
00600     return cpy;
00601 }
00602 
00603 //---------------------------------------------------------------------------
00604 
00605 void
00606 ResolverInfoMisc::addAction (const std::string & action_msg)
00607 {
00608     _action = action_msg;
00609 }
00610 
00611 
00612 void
00613 ResolverInfoMisc::addTrigger (const TriggerReason & trigger)
00614 {
00615     _trigger = trigger;
00616 }
00617 
00618 void
00619 ResolverInfoMisc::setOtherPoolItem (PoolItem_Ref other)
00620 {
00621     _other_item = other;
00622 }
00623 
00624 void
00625 ResolverInfoMisc::setOtherCapability (const Capability & capability)
00626 {
00627     _other_capability = capability;
00628 }
00629 
00631     };// namespace detail
00634   };// namespace solver
00637 };// namespace zypp
00639 

Generated on Thu Jul 6 00:07:23 2006 for zypp by  doxygen 1.4.6