added command: patches
authorMartin Vidner <mvidner@suse.cz>
Sun, 1 Oct 2006 11:07:30 +0000 (11:07 +0000)
committerMartin Vidner <mvidner@suse.cz>
Sun, 1 Oct 2006 11:07:30 +0000 (11:07 +0000)
tools/zmart/zmart-misc.cc
tools/zmart/zypper.cc

index 46a8586..d19d854 100644 (file)
@@ -331,33 +331,53 @@ void patch_check ()
   cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )"  << std::endl;
 }
 
+string string_status (const ResStatus& rs)
+{
+  bool i = rs.isInstalled ();
+  if (rs.isUndetermined ())
+    return i? "Installed": "Uninstalled";
+  else if (rs.isEstablishedUneeded ())
+    return i? "No Longer Applicable": "Not Applicable";
+  else if (rs.isEstablishedSatisfied ())
+    return i? "Applied": "Not Needed";
+  else if (rs.isEstablishedIncomplete ())
+    return i? "Broken": "Needed";
+  // if ResStatus interface changes
+  return "error";
+}
+
+// patches
 void show_pool()
 {
   MIL << "Pool contains " << God->pool().size() << " items. Checking whether available patches are needed." << std::endl;
 
   Table tbl;
+  TableRow th;
+  th << "Catalog" << "Name" << "Version" << "Category" << "Status";
+  tbl << th;
+  tbl.hasHeader (true);
+
   ResPool::byKind_iterator
     it = God->pool().byKindBegin<Patch>(),
     e = God->pool().byKindEnd<Patch>();
   for (; it != e; ++it )
   {
     Resolvable::constPtr res = it->resolvable();
+    if ( it->status().isUndetermined() ) {
+#warning is this a library bug?
+      // these are duplicates of those that are determined
+      continue;
+    }
     Patch::constPtr patch = asKind<Patch>(res);
 
-    if ( it->status().isNeeded() )
-    {
-      gData.patches_count++;
-      if (patch->category() == "security")
-        gData.security_patches_count++;
-
-      TableRow tr;
-      tr << patch->name() << patch->edition().asString() << patch->category();
-      tbl << tr;
-    }
+    TableRow tr;
+    tr << patch->source ().alias ();
+    tr << res->name () << res->edition ().asString();
+    tr << patch->category();
+    tr << string_status (it->status ());
+    tbl << tr;
   }
   cout << tbl;
-
-  cout << gData.patches_count << " patches needed. ( " << gData.security_patches_count << " security patches )"  << std::endl;
 }
 
 void usage(int argc, char **argv)
index 27d7a16..e0b27ec 100644 (file)
@@ -233,7 +233,8 @@ int main(int argc, char **argv)
       "\tservice-add, sa\t\tAdd a new service\n"
       "\tservice-delete, sd\tDelete a service\n"
       "\tservice-rename, sr\tRename a service\n"
-      "\tpatch-check,pchk\tCheck for patches\n"
+      "\tpatch-check, pchk\tCheck for patches\n"
+      "\tpatches, pch\t\tList patches\n"
       ;
 
   string help_global_source_options = "  Source options:\n"
@@ -576,6 +577,13 @@ int main(int argc, char **argv)
   }
 
   if (command == "patch-check" || command == "pchk") {
+    if (help) {
+      cerr << "patch-check\n"
+          << specific_help
+       ;
+      return !help;
+    }
+
     cond_init_target ();
     cond_init_system_sources ();
     // TODO additional_sources
@@ -595,5 +603,21 @@ int main(int argc, char **argv)
     return 0;
   }
 
+  if (command == "patches" || command == "pch") {
+    if (help) {
+      cerr << "patches\n"
+          << specific_help
+       ;
+      return !help;
+    }
+
+    cond_init_target ();
+    cond_init_system_sources ();
+    cond_load_resolvables ();
+    establish ();
+    show_pool ();
+    return 0;
+  }
+
   return 0;
 }