add "xml-updates-patches" command to zypper that creates output like zypp-checkpatches
authorThomas Goettlicher <tgoettlicher@suse.de>
Wed, 18 Jul 2007 15:52:27 +0000 (15:52 +0000)
committerThomas Goettlicher <tgoettlicher@suse.de>
Wed, 18 Jul 2007 15:52:27 +0000 (15:52 +0000)
src/zypper-command.cc
src/zypper-command.h
src/zypper-misc.cc
src/zypper-misc.h
src/zypper.cc

index 690eb53..7c9b6de 100644 (file)
@@ -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;
index 06a4276..cb9e5da 100644 (file)
@@ -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,
index e43aca1..be9c099 100644 (file)
@@ -9,6 +9,7 @@
 #include <zypp/RepoManager.h>
 #include <zypp/RepoInfo.h>
 #include <zypp/repo/RepoException.h>
+#include <zypp/target/store/xml_escape_parser.hpp>
 
 #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<Patch> (),
+    e  = pool.byKindEnd<Patch> ();
+
+  for (; it != e; ++it )
+  {
+    ResObject::constPtr res = it->resolvable();
+    if ( it->status().isNeeded() ) {
+      Patch::constPtr patch = asKind<Patch>(res);
+
+                       cout << " <update ";
+                       cout << "name=\"" << res->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 << "  <summary>" << xml_escape(patch->summary()) << "  </summary>" << endl;
+                       cout << "  <description>" << xml_escape(patch->description()) << "</description>" << endl;
+
+                       if ( patch->repository() != Repository::noRepository )
+                       {
+                               cout << "  <source url=\"" << *(patch->repository().info().baseUrlsBegin());
+                               cout << "\" alias=\"" << patch->repository().info().alias() << "\"/>" << endl;
+                       }
+
+      cout << " </update>" << 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<Package>::kind, candidates);
+
+    Candidates::iterator cb = candidates.begin (), ce = candidates.end (), ci;
+    for (ci = cb; ci != ce; ++ci) {
+      ResObject::constPtr res = ci->resolvable();
+
+                       cout << " <update ";
+                       cout << "name=\"" << res->name () << "\" " ;
+                       cout << "edition=\""  << res->edition ().asString() << "\" ";
+                       cout << "resolvabletype=\"" << "package" << "\" ";
+                       cout << ">" << endl;
+                       cout << "  <summary>" << xml_escape(res->summary()) << "  </summary>" << endl;
+                       cout << "  <description>" << xml_escape(res->description()) << "</description>" << endl;
+
+                       if ( res->repository() != Repository::noRepository )
+                       {
+                               cout << "  <source url=\"" << *(res->repository().info().baseUrlsBegin());
+                               cout << "\" alias=\"" << res->repository().info().alias() << "\"/>" << endl;
+                       }
+
+      cout << " </update>" << endl;
+    }
+}
+
+
+
+// ----------------------------------------------------------------------------
+
 static
 void mark_patch_updates (bool skip_interactive)
 {
index 9692ba5..f8d683c 100644 (file)
@@ -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?
index a37d0a6..872c32c 100644 (file)
@@ -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 << "<?xml version='1.0'?>" << endl;
+               cout << "<update-status version=\"0.4\">" << endl;
+               cout << "<update-list>" << endl;
+               xml_list_patches ();
+               xml_list_updates ();
+               cout << "</update-list>" << endl;
+               cout << "</update-status>" << endl;
+
+    return ZYPPER_EXIT_OK;
+       }
+
   // -----------------------------( update )----------------------------------
 
   else if (command == ZypperCommand::UPDATE) {