[ros-users] rospack find quiet ?

Top Page
Attachments:
Message as email
+ (text/plain)
+ rospack-quiet.patch (text/x-patch)
Delete this message
Reply to this message
Author: User discussions
Date:  
To: ros-users
Subject: [ros-users] rospack find quiet ?
I was missing a 'quiet errors' option in rospack. I've added the '-q' option
to quiet any 'top-level' error printing. This means that corruptions etc. are
still reported, but the final result, like '[rospack] couldn't find package
[foo]' isn't.

I needed this when using 'rospack find' from the roslib API.

Patch is against cturtle.

Peter
Index: core/roslib/src/package.cpp
===================================================================
--- core/roslib/src/package.cpp    (revision 12439)
+++ core/roslib/src/package.cpp    (working copy)
@@ -55,12 +55,15 @@
     ret = rp.run(_cmd);
     if(ret == 0)
       return rp.getOutput();
-    else
-      std::cerr << "ROSPack::run returned non-zero." << std::endl;
+    else {
+      if ( !rp.is_quiet() )
+    std::cerr << "ROSPack::run returned non-zero." << std::endl;
+    }
   }
   catch(std::runtime_error &e)
   {
-    std::cerr << "[rospack] " << e.what() << std::endl;
+    if ( !rp.is_quiet() )
+      std::cerr << "[rospack] " << e.what() << std::endl;
   }
   return std::string("");
 }
Index: tools/rospack/include/rospack/rospack.h
===================================================================
--- tools/rospack/include/rospack/rospack.h    (revision 12439)
+++ tools/rospack/include/rospack/rospack.h    (working copy)
@@ -272,6 +272,9 @@
   // Get the accumulated output
   std::string getOutput() { return output_acc; }


+ // is -q (quiet) provided ?
+ bool is_quiet() { return opt_quiet; }
+
int cmd_print_package_list(bool print_path);

int cmd_print_langs_list();
@@ -305,6 +308,8 @@
bool opt_warn_on_missing_deps;

 private:
+  // is quiet
+  bool opt_quiet;
   bool cache_lock_failed;
   bool crawled;
   std::string getCachePath();
Index: tools/rospack/rospack.cpp
===================================================================
--- tools/rospack/rospack.cpp    (revision 12439)
+++ tools/rospack/rospack.cpp    (working copy)
@@ -632,7 +632,7 @@
 //////////////////////////////////////////////////////////////////////////////



-ROSPack::ROSPack() : ros_root(NULL), cache_lock_failed(false), crawled(false),
+ROSPack::ROSPack() : ros_root(NULL), opt_quiet(false), cache_lock_failed(false), crawled(false),
         my_argc(0), my_argv(NULL), opt_profile_length(0), total_num_pkgs(0)
 {
   g_rospack = this;
@@ -695,7 +695,9 @@
           "    libs-only-L [--deps-only] [package]\n"
           "    libs-only-l [--deps-only] [package]\n"
           "    libs-only-other [--deps-only] [package]\n"
-          "    profile [--length=<length>] [--zombie-only]\n\n"
+          "    profile [--length=<length>] [--zombie-only]\n"
+          "  Extra options:\n"
+          "    -q     Quiets error reports.\n\n"
           " If [package] is omitted, the current working directory\n"
           " is used (if it contains a manifest.xml).\n\n";
 }
@@ -1135,6 +1137,7 @@
   const char* opt_length_name  = "--length=";
   const char* opt_top_name     = "--top=";
   const char* opt_target_name  = "--target=";
+  const char* opt_quiet_name   = "-q";


   // Reset to defaults.
   opt_deps_only = false;
@@ -1170,6 +1173,8 @@
       opt_deps_only=true;
     else if(!strcmp(argv[i], opt_zombie_name))
       opt_profile_zombie_only=true;
+    else if(!strcmp(argv[i], opt_quiet_name))
+      opt_quiet=true;
     else if(!strncmp(argv[i], opt_target_name, strlen(opt_target_name)))
     {
       if(opt_target.size())
Index: tools/rospack/main.cpp
===================================================================
--- tools/rospack/main.cpp    (revision 12439)
+++ tools/rospack/main.cpp    (working copy)
@@ -39,15 +39,16 @@
     return 0;
   }
   int ret;
+  rospack::ROSPack rp;
   try
   {
-    rospack::ROSPack rp;
     ret = rp.run(argc, argv);
     printf("%s", rp.getOutput().c_str());
   }
   catch(std::runtime_error &e)
   {
-    fprintf(stderr, "[rospack] %s\n", e.what());
+    if ( !rp.is_quiet() )
+      fprintf(stderr, "[rospack] %s\n", e.what());
     ret = -1;
   }