- --xmlout for patterns added
authorJan Kupec <jkupec@suse.cz>
Fri, 12 Sep 2008 11:46:18 +0000 (11:46 +0000)
committerJan Kupec <jkupec@suse.cz>
Fri, 12 Sep 2008 11:46:18 +0000 (11:46 +0000)
src/search.cc
src/utils/misc.cc

index 76ee597..b87ea4d 100644 (file)
@@ -350,8 +350,23 @@ void list_patches(Zypper & zypper)
     cout << tbl;
 }
 
+static void list_patterns_xml(Zypper & zypper)
+{
+  cout << "<pattern-list>" << endl;
 
-void list_patterns(Zypper & zypper)
+  ResPool::byKind_iterator
+    it = God->pool().byKindBegin(ResKind::pattern),
+    e  = God->pool().byKindEnd(ResKind::pattern);
+  for (; it != e; ++it )
+  {
+    Pattern::constPtr pattern = asKind<Pattern>(it->resolvable());
+    cout << asXML(*pattern, it->isSatisfied()) << endl;
+  }
+
+  cout << "</pattern-list>" << endl;
+}
+
+static void list_pattern_table(Zypper & zypper)
 {
   MIL << "Going to list patterns." << std::endl;
 
@@ -391,6 +406,14 @@ void list_patterns(Zypper & zypper)
     cout << tbl;
 }
 
+void list_patterns(Zypper & zypper)
+{
+  if (zypper.out().type() == Out::TYPE_XML)
+    list_patterns_xml(zypper);
+  else
+    list_pattern_table(zypper);
+}
+
 void list_packages(Zypper & zypper)
 {
   MIL << "Going to list packages." << std::endl;
index 273fbf3..a1a3b07 100644 (file)
@@ -323,6 +323,10 @@ Capability safe_parse_cap (Zypper & zypper,
   return Capability();
 }
 
+/**
+ * \todo this is an ugly quick-hack code, let's do something reusable and maintainable in libzypp later
+ */
+// ----------------------------------------------------------------------------
 string asXML(const Product & p, bool is_installed)
 {
   ostringstream str;
@@ -349,5 +353,23 @@ string asXML(const Product & p, bool is_installed)
 
 string asXML(const Pattern & p, bool is_installed)
 {
-  return "";
+  ostringstream str;
+  str
+    << "<pattern"
+       " name=\"" << xml_encode(p.name()) << "\""
+       " version=\"" << p.edition() << "\""
+       " arch=\"" << p.arch() << "\""
+       " vendor=\"" << xml_encode(p.vendor()) << "\""
+       " summary=\"" << xml_encode(p.summary()) << "\""
+       " repo=\"" << xml_encode(p.repoInfo().alias()) << "\""
+       " installed=\"" << (is_installed ? 1 : 0) << "\"";
+  if (p.description().empty())
+    str << "/>";
+  else
+    str
+      << ">" << endl << "<description>" << p.description() << "</description>"
+      << endl << "</pattern>";
+  return str.str();
 }
+
+// ----------------------------------------------------------------------------
\ No newline at end of file