From e361f521c418b8225566f93136f8801d09e62e62 Mon Sep 17 00:00:00 2001 From: Thomas Goettlicher Date: Wed, 18 Jul 2007 15:52:27 +0000 Subject: [PATCH] add "xml-updates-patches" command to zypper that creates output like zypp-checkpatches --- src/zypper-command.cc | 2 ++ src/zypper-command.h | 2 ++ src/zypper-misc.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++ src/zypper-misc.h | 3 ++ src/zypper.cc | 21 ++++++++++++++ 5 files changed, 106 insertions(+) diff --git a/src/zypper-command.cc b/src/zypper-command.cc index 690eb53..7c9b6de 100644 --- a/src/zypper-command.cc +++ b/src/zypper-command.cc @@ -32,6 +32,7 @@ const ZypperCommand ZypperCommand::INFO(ZypperCommand::INFO_e); const ZypperCommand ZypperCommand::LIST_UPDATES(ZypperCommand::LIST_UPDATES_e); const ZypperCommand ZypperCommand::PATCH_CHECK(ZypperCommand::PATCH_CHECK_e); const ZypperCommand ZypperCommand::SHOW_PATCHES(ZypperCommand::SHOW_PATCHES_e); +const ZypperCommand ZypperCommand::XML_LIST_UPDATES_PATCHES(ZypperCommand::XML_LIST_UPDATES_PATCHES_e); const ZypperCommand ZypperCommand::HELP(ZypperCommand::HELP_e); const ZypperCommand ZypperCommand::SHELL(ZypperCommand::SHELL_e); @@ -68,6 +69,7 @@ ZypperCommand::Command ZypperCommand::parse(const std::string & strval_r) _table["list-updates"] = _table["lu"] = ZypperCommand::LIST_UPDATES_e; _table["patch-check"] = _table["pchk"] = ZypperCommand::PATCH_CHECK_e; _table["patches"] = _table["pch"] = ZypperCommand::SHOW_PATCHES_e; + _table["xml-updates-patches"] = _table["x"] = ZypperCommand::XML_LIST_UPDATES_PATCHES_e; _table["help"] = ZypperCommand::HELP_e; _table["shell"] = _table["sh"] = ZypperCommand::SHELL_e; diff --git a/src/zypper-command.h b/src/zypper-command.h index 06a4276..cb9e5da 100644 --- a/src/zypper-command.h +++ b/src/zypper-command.h @@ -26,6 +26,7 @@ struct ZypperCommand static const ZypperCommand LIST_UPDATES; static const ZypperCommand PATCH_CHECK; static const ZypperCommand SHOW_PATCHES; + static const ZypperCommand XML_LIST_UPDATES_PATCHES; static const ZypperCommand HELP; static const ZypperCommand SHELL; @@ -58,6 +59,7 @@ struct ZypperCommand LIST_UPDATES_e, PATCH_CHECK_e, SHOW_PATCHES_e, + XML_LIST_UPDATES_PATCHES_e, HELP_e, SHELL_e, diff --git a/src/zypper-misc.cc b/src/zypper-misc.cc index e43aca1..be9c099 100644 --- a/src/zypper-misc.cc +++ b/src/zypper-misc.cc @@ -9,6 +9,7 @@ #include #include #include +#include #include "zypper.h" #include "zypper-misc.h" @@ -117,6 +118,13 @@ bool ProvideProcess::operator()( const PoolItem& provider ) return true; } +static std::string xml_escape( const std::string &text ) +{ + iobind::parser::xml_escape_parser parser; + return parser.escape(text); +} + + // this does only resolvables with this _name_. // we could also act on _provides_ @@ -565,6 +573,45 @@ void show_patches() // ---------------------------------------------------------------------------- +void xml_list_patches () +{ + const zypp::ResPool& pool = God->pool(); + ResPool::byKind_iterator + it = pool.byKindBegin (), + e = pool.byKindEnd (); + + for (; it != e; ++it ) + { + ResObject::constPtr res = it->resolvable(); + if ( it->status().isNeeded() ) { + Patch::constPtr patch = asKind(res); + + cout << " name () << "\" " ; + cout << "edition=\"" << res->edition ().asString() << "\" "; + cout << "category=\"" << patch->category() << "\" "; + cout << "pkgmanager=\"" << ((patch->affects_pkg_manager()) ? "true" : "false") << "\" "; + cout << "restart=\"" << ((patch->reboot_needed()) ? "true" : "false") << "\" "; + cout << "interactive=\"" << ((patch->interactive()) ? "true" : "false") << "\" "; + cout << "resolvabletype=\"" << "patch" << "\" "; + cout << ">" << endl; + cout << " " << xml_escape(patch->summary()) << " " << endl; + cout << " " << xml_escape(patch->description()) << "" << endl; + + if ( patch->repository() != Repository::noRepository ) + { + cout << " repository().info().baseUrlsBegin()); + cout << "\" alias=\"" << patch->repository().info().alias() << "\"/>" << endl; + } + + cout << " " << endl; + } + } +} + + +// ---------------------------------------------------------------------------- + void list_patch_updates () { Table tbl; @@ -754,6 +801,37 @@ bool mark_item_install (const PoolItem& pi) { // ---------------------------------------------------------------------------- +void xml_list_updates() +{ + Candidates candidates; + find_updates (ResTraits::kind, candidates); + + Candidates::iterator cb = candidates.begin (), ce = candidates.end (), ci; + for (ci = cb; ci != ce; ++ci) { + ResObject::constPtr res = ci->resolvable(); + + cout << " name () << "\" " ; + cout << "edition=\"" << res->edition ().asString() << "\" "; + cout << "resolvabletype=\"" << "package" << "\" "; + cout << ">" << endl; + cout << " " << xml_escape(res->summary()) << " " << endl; + cout << " " << xml_escape(res->description()) << "" << endl; + + if ( res->repository() != Repository::noRepository ) + { + cout << " repository().info().baseUrlsBegin()); + cout << "\" alias=\"" << res->repository().info().alias() << "\"/>" << endl; + } + + cout << " " << endl; + } +} + + + +// ---------------------------------------------------------------------------- + static void mark_patch_updates (bool skip_interactive) { diff --git a/src/zypper-misc.h b/src/zypper-misc.h index 9692ba5..f8d683c 100644 --- a/src/zypper-misc.h +++ b/src/zypper-misc.h @@ -49,6 +49,9 @@ void establish (); bool resolve(); void dump_pool (); void show_patches(); +void xml_list_patches(); +void xml_list_updates(); + /** * Are there applicable patches? diff --git a/src/zypper.cc b/src/zypper.cc index a37d0a6..872c32c 100644 --- a/src/zypper.cc +++ b/src/zypper.cc @@ -103,6 +103,7 @@ string help_commands = _( "\tpatch-check, pchk\tCheck for patches\n" "\tpatches, pch\t\tList patches\n" "\tlist-updates, lu\tList updates\n" + "\txml-updates-patches, x\tList updates and patches in xml format\n" "\tupdate, up\t\tUpdate installed resolvables with newer versions.\n" "\tinfo, if\t\tShow full information for packages\n" "\tpatch-info\t\tShow full information for patches\n" @@ -1058,6 +1059,26 @@ int one_command(const ZypperCommand & command, int argc, char **argv) return ZYPPER_EXIT_OK; } + + // -----------------( xml list updates and patches )------------------------ + + else if (command == ZypperCommand::XML_LIST_UPDATES_PATCHES) { + cond_init_target (); + init_repos (); + cond_load_resolvables(); + establish (); + + cout << "" << endl; + cout << "" << endl; + cout << "" << endl; + xml_list_patches (); + xml_list_updates (); + cout << "" << endl; + cout << "" << endl; + + return ZYPPER_EXIT_OK; + } + // -----------------------------( update )---------------------------------- else if (command == ZypperCommand::UPDATE) { -- 2.7.4