13 #define YUILogComponent "gtk-pkg"
15 #include "yzyppwrapper.h"
20 static bool g_autoSolver =
true;
24 Ypp::Repository::Repository (zypp::Repository repo)
25 : m_repo (repo), m_repo_info (repo.info()), m_onlyInfo (false) {}
27 Ypp::Repository::Repository (zypp::RepoInfo repo)
28 : m_repo (NULL), m_repo_info (repo), m_onlyInfo (true) {}
30 std::string Ypp::Repository::name()
31 {
return m_repo_info.name(); }
33 std::string Ypp::Repository::url()
34 {
return m_repo_info.url().asString(); }
36 bool Ypp::Repository::enabled()
37 {
return m_repo_info.enabled(); }
39 bool Ypp::Repository::isOutdated()
40 {
return m_onlyInfo ?
false : m_repo.maybeOutdated(); }
42 bool Ypp::Repository::isSystem()
43 {
return m_repo.isSystemRepo(); }
46 {
return this->m_repo.info().alias() == other.m_repo.info().alias(); }
48 void Ypp::getRepositoryFromAlias (
const std::string &alias, std::string &name, std::string &url)
50 static std::map <std::string, zypp::RepoInfo> repos;
52 zypp::RepoManager manager;
53 std::list <zypp::RepoInfo> known_repos = manager.knownRepositories();
54 for (std::list <zypp::RepoInfo>::const_iterator it = known_repos.begin();
55 it != known_repos.end(); it++)
56 repos[it->alias()] = *it;
59 std::map <std::string, zypp::RepoInfo>::iterator it = repos.find (alias);
60 if (it != repos.end()) {
61 zypp::RepoInfo *repo = &it->second;
63 url = repo->url().asString();
71 Ypp::Version::Version (ZyppResObject zobj)
74 int Ypp::Version::type()
75 {
return Selectable::asType (m_zobj->kind()); }
77 std::string Ypp::Version::number()
78 {
return m_zobj->edition().asString(); }
80 std::string Ypp::Version::arch()
81 {
return m_zobj->arch().asString(); }
84 {
return Repository (m_zobj->repository()); }
86 Size_t Ypp::Version::size()
87 {
return m_zobj->installSize(); }
89 Size_t Ypp::Version::downloadSize()
90 {
return m_zobj->downloadSize(); }
92 bool Ypp::Version::isInstalled()
94 zypp::ResStatus status = m_zobj->poolItem().status();
96 case Ypp::Selectable::PATCH:
97 case Ypp::Selectable::PATTERN:
98 return status.isSatisfied() && !status.isToBeInstalled();
100 return status.isInstalled();
104 bool Ypp::Version::toModify()
106 zypp::ResStatus status = m_zobj->poolItem().status();
107 return status.transacts();
111 {
return this->m_zobj->edition() < other.m_zobj->edition(); }
114 {
return this->m_zobj->edition() > other.m_zobj->edition(); }
117 {
return this->m_zobj->edition() == other.m_zobj->edition(); }
121 zypp::ResKind Ypp::Selectable::asKind (Type type)
124 case PATTERN:
return zypp::ResKind::pattern;
125 case PATCH:
return zypp::ResKind::patch;
126 case PACKAGE:
case LANGUAGE:
case ALL:
break;
128 return zypp::ResKind::package;
131 Ypp::Selectable::Type Ypp::Selectable::asType (zypp::ResKind kind)
133 if (kind == zypp::ResKind::patch)
135 if (kind == zypp::ResKind::pattern)
140 Ypp::Selectable::Selectable (ZyppSelectable sel)
141 : m_type (asType (sel->kind())), m_sel (sel)
144 Ypp::Selectable::Selectable (zypp::Locale locale)
145 : m_type (LANGUAGE), m_locale (locale) {}
147 Ypp::Selectable::Type Ypp::Selectable::type()
150 std::string Ypp::Selectable::name()
153 case LANGUAGE:
return m_locale.name() +
" (" + m_locale.code() +
")";
154 case PATTERN:
return m_sel->theObj()->summary();
157 return m_sel->name();
160 std::string Ypp::Selectable::summary()
165 Collection col (*
this);
166 int installed, total;
167 col.stats (&installed, &total);
168 std::ostringstream stream;
169 stream << _(
"Installed:") <<
" " << installed <<
" " << _(
"of") <<
" " << total;
174 return m_sel->theObj()->summary();
177 std::string Ypp::Selectable::description (
bool as_html)
179 if (m_type == LANGUAGE)
182 std::string text (m_sel->theObj()->description()), br (
"\n");
183 if (as_html) br =
"<br />";
187 const char *header =
"<!-- DT:Rich -->", header_len = 16;
188 if (!text.compare (0, header_len, header, header_len))
192 std::string::size_type i = text.find (
"\nAuthors:", 0);
193 if (i == std::string::npos)
194 i = text.find (
"\nAuthor:", 0);
195 if (i != std::string::npos)
198 while (text.length() > 0 && text [text.length()-1] ==
'\n')
199 text.erase (text.length()-1);
201 text = YGUtils::escapeMarkup (text);
203 YGUtils::replace (text,
"\n\n", 2,
"<br>");
209 ZyppPatch patch = castZyppPatch (m_sel->theObj());
210 if (patch->rebootSuggested()) {
211 text += br + br +
"<b>" + _(
"Reboot required:") +
" </b>";
212 text += _(
"the system will have to be restarted in order for "
213 "this patch to take effect.");
215 if (patch->reloginSuggested()) {
216 text += br + br +
"<b>" + _(
"Relogin required:") +
" </b>";
217 text += _(
"you must logout and login again for "
218 "this patch to take effect.");
220 if (patch->referencesBegin() != patch->referencesEnd()) {
221 text += br + br +
"<b>Bugzilla:</b><ul>";
222 for (zypp::Patch::ReferenceIterator it = patch->referencesBegin();
223 it != patch->referencesEnd(); it++)
224 text +=
"<li><a href=\"" + it.href() +
"\">" + it.title() +
"</a></li>";
230 text += br + br + summary();
238 bool Ypp::Selectable::visible()
242 ZyppPattern pattern = castZyppPattern (zyppSel()->theObj());
243 return pattern->userVisible();
246 if (zyppSel()->hasCandidateObj())
247 if (!zyppSel()->candidateObj().isRelevant())
255 bool Ypp::Selectable::isInstalled()
259 return !m_sel->installedEmpty();
262 if (hasCandidateVersion())
263 return candidate().isInstalled();
266 return _zyppPool().isRequestedLocale (m_locale);
272 bool Ypp::Selectable::hasUpgrade()
275 case LANGUAGE:
break;
277 const ZyppResObject candidate = m_sel->candidateObj();
278 const ZyppResObject installed = m_sel->installedObj();
279 if (!!candidate && !!installed)
280 return zypp::Edition::compare (candidate->edition(), installed->edition()) > 0;
286 bool Ypp::Selectable::isLocked()
289 case LANGUAGE:
break;
291 zypp::ui::Status status = m_sel->status();
292 return status == zypp::ui::S_Taboo || status == zypp::ui::S_Protected;
298 bool Ypp::Selectable::toInstall()
301 case LANGUAGE:
break;
302 default:
return m_sel->toInstall();
307 bool Ypp::Selectable::toRemove()
310 case LANGUAGE:
break;
311 default:
return m_sel->toDelete();
316 bool Ypp::Selectable::toModify()
319 case LANGUAGE:
break;
320 default:
return m_sel->toModify();
325 bool Ypp::Selectable::toModifyAuto()
328 case LANGUAGE:
break;
330 return m_sel->toModify() && m_sel->modifiedBy() != zypp::ResStatus::USER;
335 void Ypp::Selectable::install()
341 if (!_zyppPool().isRequestedLocale (m_locale))
342 _zyppPool().addRequestedLocale (m_locale);
345 if (!m_sel->hasLicenceConfirmed()) {
346 ZyppResObject obj = m_sel->candidateObj();
347 if (obj && g_interface && g_autoSolver) {
348 const std::string &license = obj->licenseToConfirm();
349 if (!license.empty())
350 if (!g_interface->showLicense (*
this, license))
352 const std::string &msg = obj->insnotify();
354 if (!g_interface->showMessage (*
this, msg))
357 m_sel->setLicenceConfirmed();
360 zypp::ui::Status status = m_sel->status();
363 case zypp::ui::S_Protected:
364 case zypp::ui::S_Taboo:
365 case zypp::ui::S_Install:
366 case zypp::ui::S_Update:
369 case zypp::ui::S_Del:
370 if (hasInstalledVersion())
371 status = zypp::ui::S_Update;
373 status = zypp::ui::S_Install;
376 case zypp::ui::S_AutoDel:
379 case zypp::ui::S_NoInst:
380 case zypp::ui::S_AutoInstall:
381 status = zypp::ui::S_Install;
383 case zypp::ui::S_KeepInstalled:
384 case zypp::ui::S_AutoUpdate:
385 status = zypp::ui::S_Update;
388 m_sel->setStatus (status);
393 if (!runSolver()) undo();
396 void Ypp::Selectable::remove()
400 if (_zyppPool().isRequestedLocale (m_locale))
401 _zyppPool().eraseRequestedLocale (m_locale);
404 if (m_sel->hasCandidateObj() && g_interface && g_autoSolver) {
405 ZyppResObject obj = m_sel->candidateObj();
406 const std::string &msg = obj->delnotify();
408 if (!g_interface->showMessage (*
this, msg))
412 zypp::ui::Status status = m_sel->status();
415 case zypp::ui::S_Protected:
416 case zypp::ui::S_Taboo:
417 case zypp::ui::S_NoInst:
418 case zypp::ui::S_Del:
421 case zypp::ui::S_AutoInstall:
422 case zypp::ui::S_AutoUpdate:
425 case zypp::ui::S_Install:
426 case zypp::ui::S_Update:
428 case zypp::ui::S_KeepInstalled:
429 case zypp::ui::S_AutoDel:
430 status = zypp::ui::S_Del;
433 m_sel->setStatus (status);
438 if (!runSolver()) undo();
441 void Ypp::Selectable::undo()
445 zypp::ui::Status status = m_sel->status();
446 zypp::ui::Status prev_status = status;
449 case zypp::ui::S_Protected:
450 case zypp::ui::S_Taboo:
451 case zypp::ui::S_NoInst:
452 case zypp::ui::S_KeepInstalled:
455 case zypp::ui::S_Install:
456 case zypp::ui::S_AutoInstall:
457 status = zypp::ui::S_NoInst;
459 case zypp::ui::S_AutoUpdate:
460 case zypp::ui::S_AutoDel:
461 case zypp::ui::S_Update:
462 case zypp::ui::S_Del:
463 status = zypp::ui::S_KeepInstalled;
466 m_sel->setStatus (status);
469 m_sel->setStatus (prev_status);
474 void Ypp::Selectable::lock (
bool lock)
477 zypp::ui::Status status;
479 status = isInstalled() ? zypp::ui::S_Protected : zypp::ui::S_Taboo;
481 status = isInstalled() ? zypp::ui::S_KeepInstalled : zypp::ui::S_NoInst;
482 m_sel->setStatus (status);
484 if (!runSolver()) undo();
487 bool Ypp::Selectable::canRemove()
490 case PACKAGE:
case LANGUAGE:
return true;
496 bool Ypp::Selectable::canLock()
507 int Ypp::Selectable::totalVersions()
508 {
return m_sel->installedSize() + m_sel->availableSize(); }
512 if (n < (
signed) m_sel->installedSize()) {
513 zypp::ui::Selectable::installed_iterator it = m_sel->installedBegin();
514 for (
int i = 0; i < n; i++) it++;
515 return Version (*it);
518 n -= m_sel->installedSize();
519 zypp::ui::Selectable::available_iterator it = m_sel->availableBegin();
520 for (
int i = 0; i < n; i++) it++;
521 return Version (*it);
525 bool Ypp::Selectable::hasCandidateVersion()
526 {
return !m_sel->availableEmpty(); }
529 {
return Version (m_sel->candidateObj()); }
531 void Ypp::Selectable::setCandidate (
Ypp::Version &version)
533 m_sel->setCandidate (version.zyppObj());
537 bool Ypp::Selectable::hasInstalledVersion()
538 {
return !m_sel->installedEmpty(); }
542 if (m_type == PATCH || m_type == PATTERN) {
543 if (m_sel->candidateObj() && m_sel->candidateObj().isSatisfied())
550 {
return Version (m_sel->theObj()); }
553 {
return this->m_sel == other.m_sel; }
556 {
return this->m_sel != other.m_sel; }
563 static std::map <ZyppPattern, Ypp::List> g_patternsContent;
564 static std::map <zypp::Locale, Ypp::List> g_languagesContent;
568 if (m_sel.type() == Ypp::Selectable::PATTERN) {
569 ZyppPattern pattern = castZyppPattern (m_sel.zyppSel()->theObj());
570 std::map <ZyppPattern, Ypp::List>::iterator it;
571 if ((it = g_patternsContent.find (pattern)) != g_patternsContent.end())
574 zypp::Pattern::Contents c = pattern->contents();
576 for (zypp::Pattern::Contents::Selectable_iterator it = c.selectableBegin();
577 it != c.selectableEnd(); it++)
578 list.append (Selectable (*it));
579 g_patternsContent.insert (std::make_pair (pattern, list));
580 return &g_patternsContent.find (pattern)->second;
583 zypp::Locale locale = m_sel.zyppLocale();
584 std::map <zypp::Locale, Ypp::List>::iterator it;
585 if ((it = g_languagesContent.find (locale)) != g_languagesContent.end())
588 zypp::sat::LocaleSupport locale_sup (locale);
590 for_( it, locale_sup.selectableBegin(), locale_sup.selectableEnd() ) {
591 list.append (Selectable (*it));
593 g_languagesContent.insert (std::make_pair (locale, list));
594 return &g_languagesContent.find (locale)->second;
600 if (m_sel.type() == Ypp::Selectable::PATCH) {
601 if (m_sel.hasCandidateVersion()) {
602 ZyppResObject
object = m_sel.zyppSel()->candidateObj();
603 ZyppPatch patch = castZyppPatch (
object);
604 zypp::Patch::Contents contents (patch->contents());
605 ZyppSelectable pkg = sel.zyppSel();
606 for (zypp::Patch::Contents::Selectable_iterator it =
607 contents.selectableBegin(); it != contents.selectableEnd(); it++) {
617 return content->find (sel) != -1;
620 void Ypp::Collection::stats (
int *installed,
int *total)
624 *installed = props.isInstalledNb();
625 *total = content->size();
633 int Ypp::Package::support()
635 ZyppPackage pkg = castZyppPackage (m_sel.zyppSel()->theObj());
636 switch (pkg->vendorSupport()) {
637 case zypp::VendorSupportUnknown:
return 0;
638 case zypp::VendorSupportUnsupported:
return 1;
639 case zypp::VendorSupportACC:
return 2;
640 case zypp::VendorSupportLevel1:
return 3;
641 case zypp::VendorSupportLevel2:
return 4;
642 case zypp::VendorSupportLevel3:
return 5;
647 int Ypp::Package::supportTotal()
650 static zypp::VendorSupportOption asSupportOpt (
int support)
653 case 0:
return zypp::VendorSupportUnknown;
654 case 1:
return zypp::VendorSupportUnsupported;
655 case 2:
return zypp::VendorSupportACC;
656 case 3:
return zypp::VendorSupportLevel1;
657 case 4:
return zypp::VendorSupportLevel2;
658 case 5:
return zypp::VendorSupportLevel3;
660 return zypp::VendorSupportUnknown;
663 std::string Ypp::Package::supportSummary (
int support)
664 {
return zypp::asUserString (asSupportOpt (support)); }
666 std::string Ypp::Package::supportDescription (
int support)
667 {
return zypp::asUserStringDescription (asSupportOpt (support)); }
669 std::string Ypp::Package::url()
671 ZyppPackage
package = castZyppPackage (m_sel.zyppSel()->theObj());
672 return package->url();
675 YPkgGroupEnum Ypp::Package::group()
677 static std::map <ZyppPackage, YPkgGroupEnum> pkgGroupMap;
678 ZyppPackage pkg = castZyppPackage (m_sel.zyppSel()->theObj());
679 std::map <ZyppPackage, YPkgGroupEnum>::iterator it = pkgGroupMap.find (pkg);
680 if (it == pkgGroupMap.end()) {
681 YPkgGroupEnum group = zypp_tag_convert (pkg->group());
682 pkgGroupMap.insert (std::make_pair (pkg, group));
688 std::string Ypp::Package::rpm_group()
690 ZyppPackage pkg = castZyppPackage (m_sel.zyppSel()->theObj());
694 static std::map <std::string, ZyppSelectable> g_selPatch;
698 std::string name (sel.name());
699 std::map <std::string, ZyppSelectable>::iterator it = g_selPatch.find (name);
700 if (it != g_selPatch.end())
706 if (query.hasNext()) {
708 g_selPatch[name] = patch.zyppSel();
711 g_selPatch[name] = NULL;
712 return g_selPatch[name];
715 bool Ypp::Package::isCandidatePatch()
717 if (m_sel.hasCandidateVersion() && m_sel.hasInstalledVersion()) {
718 Ypp::Version candidate (m_sel.candidate()), installed (m_sel.installed());
719 if (candidate > installed)
720 return getSelPatch (m_sel) != NULL;
726 {
return Selectable (getSelPatch (m_sel)); }
733 int Ypp::Patch::priority()
735 ZyppPatch patch = castZyppPatch (m_sel.zyppSel()->theObj());
736 switch (patch->categoryEnum()) {
737 case zypp::Patch::CAT_SECURITY:
return 0;
738 case zypp::Patch::CAT_RECOMMENDED:
return 1;
739 case zypp::Patch::CAT_YAST:
return 2;
740 case zypp::Patch::CAT_DOCUMENT:
return 3;
741 case zypp::Patch::CAT_OPTIONAL:
return 4;
742 case zypp::Patch::CAT_OTHER:
return 5;
747 int Ypp::Patch::priorityTotal()
750 const char *Ypp::Patch::prioritySummary (
int priority)
754 case 0:
return _(
"Security");
756 case 1:
return _(
"Recommended");
757 case 2:
return "YaST";
758 case 3:
return _(
"Documentation");
760 case 4:
return _(
"Optional");
762 case 5:
return _(
"Other");
769 std::vector <std::string> Ypp::getPartitionList()
771 ZyppDuSet diskUsage = zypp::getZYpp()->diskUsage();
772 std::vector <std::string> partitions;
773 partitions.reserve (diskUsage.size());
774 for (ZyppDuSet::iterator it = diskUsage.begin(); it != diskUsage.end(); it++) {
775 const ZyppDu &point = *it;
777 partitions.push_back (point.dir);
779 std::sort (partitions.begin(), partitions.end());
783 const ZyppDu Ypp::getPartition (
const std::string &mount_point)
785 ZyppDuSet diskUsage = zypp::getZYpp()->diskUsage();
786 for (ZyppDuSet::iterator it = diskUsage.begin(); it != diskUsage.end(); it++) {
787 const ZyppDu &point = *it;
788 if (mount_point == point.dir)
791 return *zypp::getZYpp()->diskUsage().begin();
797 static bool g_busy_running =
false;
800 { g_busy_listener = listener; }
808 : cur (0), size (size), showing (
false)
810 g_get_current_time (&start_t);
811 g_busy_running =
true;
812 g_busy_listener->loading (0);
817 g_busy_running =
false;
818 g_busy_listener->loading (1);
827 if ((cur % 500) == 0)
828 g_busy_listener->loading (cur / (
float) size);
830 else if (cur == 499) {
832 g_get_current_time (&now_t);
833 if (now_t.tv_usec - start_t.tv_usec >= 35*1000 ||
834 now_t.tv_sec - start_t.tv_sec >= 1) {
839 g_busy_listener->loading (cur / (
float) size);
844 Ypp::Busy::Busy (
int size) : impl (NULL)
846 if (g_busy_listener && !g_busy_running)
847 impl =
new Impl (size);
853 void Ypp::Busy::inc()
854 {
if (impl) impl->inc(); }
858 std::list <Ypp::SelListener *> g_sel_listeners;
859 static bool g_transacting =
false;
862 { g_sel_listeners.push_back (listener); }
865 { g_sel_listeners.remove (listener); }
867 void Ypp::notifySelModified()
869 for (std::list <Ypp::SelListener *>::iterator it = g_sel_listeners.begin();
870 it != g_sel_listeners.end(); it++)
871 (*it)->selectableModified();
876 g_interface = interface;
882 {
return (Solution *) g_slist_nth_data ((GSList *) impl, nb); }
884 bool Ypp::runSolver (
bool force)
886 if (g_transacting)
return true;
887 if (!g_autoSolver && !force) {
893 g_busy_listener->loading (0);
895 zypp::Resolver_Ptr zResolver = zypp::getZYpp()->resolver();
896 bool resolved =
false;
898 if (zResolver->resolvePool()) {
902 zypp::ResolverProblemList zProblems = zResolver->problems();
903 if ((resolved = zProblems.empty()))
break;
904 if (!g_interface)
break;
906 std::list <Problem *> problems;
907 for (zypp::ResolverProblemList::iterator it = zProblems.begin();
908 it != zProblems.end(); it++) {
909 Problem *problem =
new Problem();
910 problem->description = (*it)->description();
911 problem->details = (*it)->details();
912 GSList *solutions = NULL;
913 zypp::ProblemSolutionList zSolutions = (*it)->solutions();
914 for (zypp::ProblemSolutionList::iterator jt = zSolutions.begin();
915 jt != zSolutions.end(); jt++) {
916 Problem::Solution *solution =
new Problem::Solution();
917 solution->description = (*jt)->description();
918 solution->details = (*jt)->details();
919 solution->apply =
false;
920 solution->impl = (
void *) get_pointer (*jt);
921 solutions = g_slist_append (solutions, solution);
923 problem->impl = (
void *) solutions;
924 problems.push_back (problem);
927 resolved = g_interface->resolveProblems (problems);
929 zypp::ProblemSolutionList choices;
930 for (std::list <Problem *>::iterator it = problems.begin();
931 it != problems.end(); it++) {
932 for (
int i = 0; (*it)->getSolution (i); i++) {
933 Problem::Solution *solution = (*it)->getSolution (i);
934 if (resolved && solution->apply)
935 choices.push_back ((zypp::ProblemSolution *) solution->impl);
938 g_slist_free ((GSList *) (*it)->impl);
941 zResolver->applySolutions (choices);
951 g_busy_listener->loading (1);
955 void Ypp::setEnableSolver (
bool enabled)
957 g_autoSolver = enabled;
958 if (enabled) runSolver();
961 bool Ypp::isSolverEnabled()
962 {
return g_autoSolver; }
964 bool Ypp::showPendingLicenses (Ypp::Selectable::Type type)
966 const zypp::ResKind &kind = Selectable::asKind (type);
967 for (ZyppPool::const_iterator it = zyppPool().byKindBegin(kind);
968 it != zyppPool().byKindEnd(kind); it++) {
969 ZyppSelectable zsel = (*it);
970 switch (zsel->status()) {
971 case zypp::ui::S_Install:
case zypp::ui::S_AutoInstall:
972 case zypp::ui::S_Update:
case zypp::ui::S_AutoUpdate:
973 if (zsel->candidateObj()) {
974 std::string license = zsel->candidateObj()->licenseToConfirm();
975 if (!license.empty())
976 if (!zsel->hasLicenceConfirmed()) {
977 Selectable sel (zsel);
978 if (!g_interface->showLicense (sel, license))
988 void Ypp::startTransactions()
989 { g_transacting =
true; }
991 bool Ypp::finishTransactions()
992 { g_transacting =
false;
return runSolver(); }
998 std::list <std::string> strings;
1000 Impl (
int attrbs) : attrbs (attrbs) {}
1003 Ypp::StrMatch::StrMatch (
int attrbs)
1004 : impl (new
Impl (attrbs)) {}
1006 Ypp::StrMatch::~StrMatch()
1009 void Ypp::StrMatch::add (
const std::string &str)
1010 { impl->strings.push_back (str); }
1014 std::string haystack;
1015 haystack.reserve (2048);
1016 if (impl->attrbs & NAME)
1017 haystack += sel.name();
1018 if (impl->attrbs & SUMMARY)
1019 haystack += sel.summary();
1020 if (impl->attrbs & DESCRIPTION)
1021 haystack += sel.description (
false);
1023 for (std::list <std::string>::iterator it = impl->strings.begin();
1024 it != impl->strings.end(); it++) {
1025 const std::string &needle = *it;
1026 if (!strcasestr (haystack.c_str(), needle.c_str()))
1032 Ypp::StatusMatch::StatusMatch (Ypp::StatusMatch::Status status)
1033 : m_status (status) {}
1035 bool Ypp::StatusMatch::match (Selectable &sel)
1038 case IS_INSTALLED:
return sel.isInstalled();
1039 case NOT_INSTALLED:
return !sel.isInstalled();
1040 case HAS_UPGRADE:
return sel.hasUpgrade();
1041 case IS_LOCKED:
return sel.isLocked();
1042 case TO_MODIFY:
return sel.toModify();
1047 Ypp::PKGroupMatch::PKGroupMatch (YPkgGroupEnum group)
1048 : m_group (group) {}
1050 bool Ypp::PKGroupMatch::match (Selectable &sel)
1052 ZyppPackage pkg = castZyppPackage (sel.zyppSel()->theObj());
1054 case YPKG_GROUP_RECOMMENDED:
return zypp::PoolItem (pkg).status().isRecommended();
1055 case YPKG_GROUP_SUGGESTED:
return zypp::PoolItem (pkg).status().isSuggested();
1056 case YPKG_GROUP_ORPHANED:
return zypp::PoolItem (pkg).status().isOrphaned();
1057 case YPKG_GROUP_RECENT:
1058 if (sel.hasCandidateVersion()) {
1059 time_t build = static_cast <time_t> (sel.candidate().zyppObj()->buildtime());
1060 time_t now = time (NULL);
1061 time_t delta = (now - build) / (60*60*24);
1065 #if ZYPP_VERSION >= 6030004
1066 case YPKG_GROUP_MULTIVERSION:
return sel.zyppSel()->multiversionInstall();
1068 default:
return Package (sel).group() == m_group;
1073 Ypp::RpmGroupMatch::RpmGroupMatch (
const std::string &group)
1074 : m_group (group) {}
1076 bool Ypp::RpmGroupMatch::match (Selectable &sel)
1078 std::string pkg_group (Package (sel).rpm_group());
1079 int len = MIN (m_group.size(), pkg_group.size());
1080 return m_group.compare (0, len, pkg_group, 0, len) == 0;
1083 Ypp::FromCollectionMatch::FromCollectionMatch (Collection &col)
1084 : m_collection (col) {}
1086 bool Ypp::FromCollectionMatch::match (Selectable &sel)
1087 {
return m_collection.contains (sel); }
1089 Ypp::CollectionContainsMatch::CollectionContainsMatch (
Ypp::Selectable &sel)
1090 : m_contains (sel) {}
1094 Collection collection (sel);
1095 return collection.contains (m_contains);
1100 std::list <Match *> criterias;
1101 bool filelist_attrb;
1102 ZyppQuery::Selectable_iterator it;
1105 Impl() : filelist_attrb (
false), begin (
true) {}
1109 for (std::list <Match *>::iterator it = criterias.begin();
1110 it != criterias.end(); it++)
1116 for (std::list <Match *>::iterator it = criterias.begin();
1117 it != criterias.end(); it++)
1118 if (!(*it)->match (sel))
1123 ZyppQuery::Selectable_iterator untilMatch (ZyppQuery::Selectable_iterator it)
1125 while (it != query.selectableEnd()) {
1127 if (sel.visible() && match (sel))
break;
1134 Ypp::PoolQuery::PoolQuery (Ypp::Selectable::Type type)
1137 assert (type != Selectable::LANGUAGE);
1138 if (type != Selectable::ALL)
1139 impl->query.addKind (Selectable::asKind (type));
1142 Ypp::PoolQuery::~PoolQuery()
1145 void Ypp::PoolQuery::setStringMode (
bool caseSensitive, Ypp::PoolQuery::MatchType match)
1147 impl->query.setCaseSensitive (caseSensitive);
1149 case CONTAINS: impl->query.setMatchSubstring();
break;
1150 case EXACT: impl->query.setMatchExact();
break;
1151 case GLOB: impl->query.setMatchGlob();
break;
1152 case REGEX: impl->query.setMatchRegex();
break;
1156 void Ypp::PoolQuery::addStringAttribute (Ypp::PoolQuery::StringAttribute attrb)
1158 zypp::sat::SolvAttr _attrb;
1159 impl->filelist_attrb =
false;
1161 case NAME: _attrb = ZyppAttribute::name;
break;
1162 case SUMMARY: _attrb = ZyppAttribute::summary;
break;
1163 case DESCRIPTION: _attrb = ZyppAttribute::description;
break;
1164 case FILELIST: _attrb = ZyppAttribute::filelist; impl->filelist_attrb =
true;
break;
1165 case REQUIRES: _attrb = ZyppAttribute (
"solvable:requires");
break;
1166 case PROVIDES: _attrb = ZyppAttribute (
"solvable:provides");
break;
1168 impl->query.addAttribute (_attrb);
1171 void Ypp::PoolQuery::addStringOr (
const std::string &str)
1173 if (impl->filelist_attrb && !str.empty())
1174 impl->query.setFilesMatchFullPath (str[0] ==
'/');
1175 impl->query.addString (str);
1179 { impl->query.addRepo (repository.zyppRepo().info().alias()); }
1181 void Ypp::PoolQuery::addCriteria (
Ypp::Match *criteria)
1182 { impl->criterias.push_back (criteria); }
1184 bool Ypp::PoolQuery::hasNext()
1187 impl->it = impl->untilMatch (impl->query.selectableBegin());
1188 impl->begin =
false;
1190 return impl->it != impl->query.selectableEnd();
1196 impl->it = impl->untilMatch (++impl->it);
1200 int Ypp::PoolQuery::guessSize()
1201 {
return impl->query.size(); }
1203 ZyppQuery &Ypp::PoolQuery::zyppQuery()
1204 {
return impl->query; }
1206 Ypp::Selectable::Type Ypp::PoolQuery::poolType()
1207 {
return Selectable::asType (*impl->query.kinds().begin()); }
1210 zypp::LocaleSet locales;
1211 zypp::LocaleSet::const_iterator it;
1214 locales = _zyppPool().getAvailableLocales();
1215 it = locales.begin();
1219 Ypp::LangQuery::LangQuery()
1220 : impl (new
Impl()) {}
1222 Ypp::LangQuery::~LangQuery()
1225 bool Ypp::LangQuery::hasNext()
1226 {
return impl->it != impl->locales.end(); }
1231 int Ypp::LangQuery::guessSize()
1232 {
return impl->locales.size(); }
1237 std::vector <Selectable> vector;
1239 Impl() : refcount (1) {}
1245 reserve (query.guessSize());
1246 while (query.hasNext())
1247 append (query.next());
1250 Ypp::List::List (
int size)
1254 Ypp::List::List (
const List &other)
1256 { impl->refcount++; }
1258 Ypp::List &Ypp::List::operator= (
const List &other)
1260 if (--impl->refcount <= 0)
delete impl;
1267 {
if (--impl->refcount <= 0)
delete impl; }
1272 other.impl->vector = this->impl->vector;
1277 {
return impl->vector[index]; }
1279 int Ypp::List::size()
1280 {
return impl->vector.size(); }
1282 int Ypp::List::count (Match *match)
1285 for (std::vector <Selectable>::iterator it = impl->vector.begin();
1286 it != impl->vector.end(); it++)
1287 if (match->match (*it))
1292 int Ypp::List::find (
const std::string &name)
1294 for (
unsigned int i = 0; i < impl->vector.size(); i++)
1295 if (name == impl->vector[i].name())
1300 int Ypp::List::find (Selectable &sel)
1302 for (
unsigned int i = 0; i < impl->vector.size(); i++)
1303 if (sel == impl->vector[i])
1308 void Ypp::List::reserve (
int size)
1309 { impl->vector.reserve (size); }
1312 { impl->vector.push_back (sel); }
1314 void Ypp::List::install()
1316 startTransactions();
1317 for (std::vector <Selectable>::iterator it = impl->vector.begin();
1318 it != impl->vector.end(); it++)
1320 if (!finishTransactions())
1324 void Ypp::List::remove()
1326 startTransactions();
1327 for (std::vector <Selectable>::iterator it = impl->vector.begin();
1328 it != impl->vector.end(); it++)
1330 if (!finishTransactions())
1334 void Ypp::List::lock (
bool lock)
1336 startTransactions();
1337 for (std::vector <Selectable>::iterator it = impl->vector.begin();
1338 it != impl->vector.end(); it++)
1340 if (!finishTransactions())
1344 void Ypp::List::undo()
1346 startTransactions();
1347 for (std::vector <Selectable>::iterator it = impl->vector.begin();
1348 it != impl->vector.end(); it++)
1350 finishTransactions();
1354 {
return (a.isInstalled() ? 0 : 1) < (b.isInstalled() ? 0 : 1); }
1357 {
return g_utf8_collate (a.name().c_str(), b.name().c_str()) < 0; }
1360 {
return strcasecmp (a.name().c_str(), b.name().c_str()) < 0; }
1363 {
return a.anyVersion().size() < b.anyVersion().size(); }
1367 if (a.hasCandidateVersion())
1368 return a.candidate().repository().zyppRepo().alias();
1373 {
return get_alias (a) < get_alias(b); }
1380 static order_cb _order;
1381 static bool _ascendent;
1385 void Ypp::List::sort (Ypp::List::SortAttribute attrb,
bool ascendent)
1387 if (impl->vector.empty())
1390 bool unique_criteria =
false;
1392 case IS_INSTALLED_SORT: _order = installed_order;
break;
1395 if (impl->vector[0].type() != Selectable::PACKAGE)
1396 _order = utf8_name_order;
1398 _order = name_order;
1399 unique_criteria =
true;
1401 case SIZE_SORT: _order = size_order; unique_criteria =
true;
break;
1402 case REPOSITORY_SORT: _order = repository_order;
break;
1403 case SUPPORT_SORT: _order = support_order;
break;
1405 _ascendent = ascendent;
1406 if (unique_criteria)
1407 std::sort (impl->vector.begin(), impl->vector.end(), proxy_order);
1409 std::stable_sort (impl->vector.begin(), impl->vector.end(), proxy_order);
1412 void Ypp::List::reverse()
1413 { std::reverse (impl->vector.begin(), impl->vector.end()); }
1415 bool Ypp::List::operator == (
const Ypp::List &other)
const
1416 {
return this->impl == other.impl; }
1417 bool Ypp::List::operator != (
const Ypp::List &other)
const
1418 {
return this->impl != other.impl; }
1423 int isInstalled, hasUpgrade, toModify, isLocked, size;
1424 int canRemove : 2, canLock : 2;
1427 isInstalled = hasUpgrade = toModify = isLocked = canRemove = canLock = 0;
1429 for (
int i = 0; i < size; i++) {
1431 if (sel.isInstalled()) {
1433 if (sel.hasUpgrade())
1443 canRemove = sel.canRemove();
1444 canLock = sel.canLock();
1449 Ypp::ListProps::ListProps (
Ypp::List &list)
1450 : impl (new
Impl (list)) {}
1452 Ypp::ListProps::~ListProps()
1455 bool Ypp::ListProps::isInstalled()
const
1456 {
return impl->isInstalled == impl->size; }
1457 bool Ypp::ListProps::isNotInstalled()
const
1458 {
return impl->isInstalled == 0; }
1459 bool Ypp::ListProps::hasUpgrade()
const
1460 {
return impl->hasUpgrade == impl->size; }
1461 bool Ypp::ListProps::toModify()
const
1462 {
return impl->toModify == impl->size; }
1463 bool Ypp::ListProps::isLocked()
const
1464 {
return impl->isLocked == impl->size; }
1465 bool Ypp::ListProps::isUnlocked()
const
1466 {
return impl->isLocked == 0; }
1467 bool Ypp::ListProps::canRemove()
const
1468 {
return impl->canRemove; }
1469 bool Ypp::ListProps::canLock()
const
1470 {
return impl->canLock; }
1472 int Ypp::ListProps::isInstalledNb()
const
1473 {
return impl->isInstalled; }
1474 int Ypp::ListProps::isNotInstalledNb()
const
1475 {
return impl->size - impl->isInstalled; }
1476 int Ypp::ListProps::hasUpgradeNb()
const
1477 {
return impl->hasUpgrade; }
1478 int Ypp::ListProps::isLockedNb()
const
1479 {
return impl->isLocked; }
1480 int Ypp::ListProps::toModifyNb()
const
1481 {
return impl->toModify; }
1487 zyppPool().saveState <zypp::Package>();
1488 zyppPool().saveState <zypp::Pattern>();
1489 zyppPool().saveState <zypp::Patch >();
1492 bool Ypp::isModified()
1494 return zyppPool().diffState <zypp::Package>() ||
1495 zyppPool().diffState <zypp::Pattern>() ||
1496 zyppPool().diffState <zypp::Patch>();
1501 g_sel_listeners.clear();
1503 g_transacting =
false;
1504 g_autoSolver =
true;
1505 g_busy_listener = 0;
1506 g_busy_running =
false;
1507 g_patternsContent.clear();
1508 g_languagesContent.clear();