On Sun, Jan 07, 2001 at 05:35:18PM +0100, Yann Dirson wrote:
> Package: menu
> Version: 2.1.5-6
> Severity: wishlist
> 
> I only user ~/.menu temporarily to test things.  When I'm done
> testing, I'd like to be able to run something like "update-menus
> --remove" to suppress those files that were created, instead of
> hunting them by hand.

Hello Yann,

Are you still interested by this feature ?
I have a patch that implement it (with some caveats).
This patch add a --remove option to update-menus.
This cause update-menus to call the menu method with --remove.
install-menu --remove will run the command in the config option
removemenu.
For example:
removemenu="test -d " prefix() " && find " prefix() " -type f -exec rm {} \\;"

The problem is that currently no menu-methods provide such 
config options.

Do you think there are situations where install-menu could be smart
enough to remove the menu without the need for removemenu ?

Cheers,
-- 
Bill. <[EMAIL PROTECTED]>

Imagine a large red swirl here. 
Index: configure.ac
===================================================================
RCS file: /cvsroot/menu/menu/configure.ac,v
retrieving revision 1.26
diff -u -r1.26 configure.ac
--- configure.ac        13 Jun 2005 11:25:38 -0000      1.26
+++ configure.ac        19 Nov 2005 18:04:53 -0000
@@ -2,7 +2,7 @@
 AC_INIT
 AC_CONFIG_SRCDIR([update-menus/update-menus.cc])
 
-AM_INIT_AUTOMAKE(menu,2.1.26)
+AM_INIT_AUTOMAKE(menu,2.1.27)
 AM_CONFIG_HEADER(config.h)
 AM_MAINTAINER_MODE dnl Be nice with packagers, i.e. ourself 
 dnl Checks for programs.
Index: debian/changelog
===================================================================
RCS file: /cvsroot/menu/menu/debian/changelog,v
retrieving revision 1.177
diff -u -r1.177 changelog
--- debian/changelog    4 Oct 2005 17:23:14 -0000       1.177
+++ debian/changelog    19 Nov 2005 18:04:54 -0000
@@ -1,3 +1,13 @@
+menu (2.1.27) unstable; urgency=low
+
+  * The "unreleased" release
+  * Allow to remove generated menus. 
+   - New config option removemenu that should remove the menu.
+   - New install-menu option --remove to call removemenu.
+   - New update-menus option --remove to call install-menu with --remove.
+
+ -- Bill Allombert <[EMAIL PROTECTED]>  Sat, 29 Oct 2005 22:05:33 +0200
+
 menu (2.1.26) unstable; urgency=low
 
   * The "And no, I'm not accepting job offers (2)" release. 
Index: install-menu/install-menu.cc
===================================================================
RCS file: /cvsroot/menu/menu/install-menu/install-menu.cc,v
retrieving revision 1.39
diff -u -r1.39 install-menu.cc
--- install-menu/install-menu.cc        12 Jun 2005 13:21:17 -0000      1.39
+++ install-menu/install-menu.cc        19 Nov 2005 18:04:54 -0000
@@ -76,6 +76,7 @@
 struct option long_options[] = { 
   { "verbose", no_argument, NULL, 'v' }, 
   { "help", no_argument, NULL, 'h' }, 
+  { "remove", no_argument, NULL, 'r' }, 
   { NULL, 0, NULL, 0 } };
 
 // Should we do translations? This is set to 'true' when both outputencoding
@@ -515,7 +516,7 @@
     hint_mlpenalty(2000), hint_max_ntry(4), hint_max_iter_hint(5),
     hint_debug(false), hotkeycase(0)
 {
-  userpref=rootpref=sort=prerun=preruntest=postrun=genmenu=
+  userpref=rootpref=sort=remove=prerun=preruntest=postrun=genmenu=
     hkexclude=startmenu=endmenu=submenutitle=also_run=outputlanguage=0;
 
   /*Should not be translated as this appear in the output file that can use 
@@ -545,6 +546,8 @@
          hkexclude=get_eq_cat_str(i);
        else if(name=="genmenu")
          genmenu=get_eq_cat_str(i);    
+       else if(name=="removemenu")
+         remove=get_eq_cat_str(i);     
        else if(name=="prerun")
          prerun=get_eq_cat_str(i);     
        else if(name=="postrun")
@@ -887,11 +890,13 @@
           "  and generate menu files using the specified menu-method.\n"
           "  Options to install-menu:\n"
          "     -h --help    : this message\n"
-         "     -v --verbose : be verbose\n");
+         "     -v --verbose : be verbose\n"
+         "        --remove  : remove the menu instead\n");
 }
 
 int main(int argc, char **argv)
 {
+  int remove = 0;
   uid_t uid = getuid();
   struct passwd *pw = getpwuid(uid);
   is_root = (uid == 0);
@@ -919,6 +924,7 @@
       case '?': usage(cerr); return 1; break;
       case 'h': usage(cout); return 0; break;
       case 'v': verbose = 1; break;
+      case 'r': remove = 1; break;
     }
   }
     
@@ -947,6 +953,12 @@
         return 0;
     if ((menumethod->onlyrunasuser || menumethod->rootpref == 0) && is_root)
         return 0;
+    if (remove)
+    {
+      if (menumethod->remove)
+        system((menumethod->remove->soutput(root_menu.vars)).c_str());
+      return 0;
+    }
     if (menumethod->prerun)
         system((menumethod->prerun->soutput(root_menu.vars)).c_str());
     if (menumethod->preruntest) {
Index: install-menu/install-menu.h
===================================================================
RCS file: /cvsroot/menu/menu/install-menu/install-menu.h,v
retrieving revision 1.16
diff -u -r1.16 install-menu.h
--- install-menu/install-menu.h 15 Jun 2004 17:14:08 -0000      1.16
+++ install-menu/install-menu.h 19 Nov 2005 18:04:54 -0000
@@ -150,7 +150,7 @@
 
   bool keep_sections;
   cat_str *startmenu, *endmenu, *submenutitle, *hkexclude,
-    *genmenu, *postrun, *prerun, *sort, *rootpref, *userpref,
+    *genmenu, *postrun, *prerun, *remove, *sort, *rootpref, *userpref,
     *outputlanguage, *also_run, *preruntest;
 
   bool onlyrunasroot, onlyrunasuser;
Index: update-menus/update-menus.cc
===================================================================
RCS file: /cvsroot/menu/menu/update-menus/update-menus.cc,v
retrieving revision 1.47
diff -u -r1.47 update-menus.cc
--- update-menus/update-menus.cc        4 Oct 2005 16:02:30 -0000       1.47
+++ update-menus/update-menus.cc        19 Nov 2005 18:04:54 -0000
@@ -580,14 +580,46 @@
   }
 }
 
+/** Run a menu-method with --remove*/
+void run_menumethod_remove(string methodname)
+{
+  const char *args[] = { methodname.c_str(), "--remove", NULL };
+  pid_t child, r;
+  int status;
+  config.report(String::compose(_("Running method: %1 --remove"), methodname),
+      configinfo::report_verbose);
+  if (!(child=fork())) {
+    // child:
+    execv(args[0],(char **)args);
+    exit(1);
+  } 
+  // parent:
+  signal(SIGPIPE,SIG_IGN);
+  r = wait4(child, &status, 0, NULL);
+  signal(SIGPIPE,SIG_DFL);
+  if (r == -1)
+    config.report(String::compose(_("Script %1 could not be executed."), 
methodname),
+        configinfo::report_quiet);
+  if (WEXITSTATUS(status))
+    config.report(String::compose(_("Script %1 returned error status %2."), 
methodname, WEXITSTATUS(status)),
+        configinfo::report_quiet);
+  else if (WIFSIGNALED(status))
+    config.report(String::compose(_("Script %1 received signal %2."), 
methodname, WTERMSIG(status)),
+        configinfo::report_quiet);
+}
+
 /** Run a menu method */
 void run_menumethod(string methodname, const vector<string> &menudata)
 {
+  if (config.remove_menu)
+  {
+    run_menumethod_remove(methodname);
+    return;
+  }
   int fds[2];
   const char *args[] = { methodname.c_str(), NULL };
   pid_t child, r;
   int status;
-
   config.report(String::compose(_("Running method: %1"), methodname), 
configinfo::report_verbose);
 
   if (pipe(fds) == -1) {
@@ -659,7 +691,7 @@
     string method = dirname + entry->d_name;
 
     if (executable(method))
-        run_menumethod(method, menudata);
+      run_menumethod(method, menudata);
   }
   closedir (dir);
 }
@@ -846,9 +878,9 @@
   "  --menumethod=<method>  Run only the menu method <method>.\n"
   "  --nodefaultdirs        Disable the use of all the standard menu 
directories.\n"
   "  --stdout               Output menu list in format suitable for piping 
to\n"
-  "                         install-menu.\n")
-       << _(  /* This is the end of the update-menus --help message*/
-  "  --version              Output version information and exit.\n"  );
+  "                         install-menu.\n"
+  "  --version              Output version information and exit.\n"
+  "  --remove               Remove generated menu.\n");
 }
 
 struct option long_options[] = { 
@@ -860,6 +892,7 @@
   { "nodefaultdirs", no_argument, NULL, 'n'},
   { "stdout", no_argument, NULL, 's'},
   { "version", no_argument, NULL, 'V'},
+  { "remove", no_argument, NULL, 'r'},
   { NULL, 0, NULL, 0 } };
 
 
@@ -891,6 +924,9 @@
     case 'm':
       config.menumethod = optarg;
       break;
+    case 'r':
+      config.remove_menu = true;
+      break;
     case 'V':
       cout << "update-menus "VERSION << std::endl;
       exit(0);
@@ -955,6 +991,27 @@
       home_dir = getenv("HOME");
 }
 
+void run_methods(vector<string> &menudata)
+{
+  if (!config.menumethod.empty())
+  {
+    if (executable(config.menumethod))
+      run_menumethod(config.menumethod, menudata);
+    else
+      config.report(String::compose(_("Script %1 could not be executed."),
+            config.menumethod), configinfo::report_quiet);
+  }
+  else if (!is_root) {
+    try {
+      run_menumethoddir(string(home_dir)+"/"+USERMETHODS, menudata);
+    }
+    catch(dir_error_read d) {
+      run_menumethoddir(MENUMETHODS, menudata);
+    }
+  } else 
+      run_menumethoddir(MENUMETHODS, menudata);
+}
+
 int main (int argc, char **argv)
 {
   is_root = (getuid() == 0);
@@ -978,6 +1035,11 @@
       close(2);
       dup2(1,2);
     }
+    if (config.remove_menu)
+    {
+      run_methods(menudata);
+      return 0;
+    }
     read_pkginfo();
     transinfo = 0;
 
@@ -999,24 +1061,8 @@
         for(vector<string>::const_iterator i = menudata.begin(); i != 
menudata.end(); ++i)
               cout << *i;
 
-    } else if (!config.menumethod.empty()) {
-      if (executable(config.menumethod))
-        run_menumethod(config.menumethod, menudata);
-      else
-        config.report(String::compose(_("Script %1 could not be executed."),
-              config.menumethod), configinfo::report_quiet);
-    } else {
-      if (!is_root) {
-        try {
-          run_menumethoddir(string(home_dir)+"/"+USERMETHODS, menudata);
-        }
-        catch(dir_error_read d) {
-          run_menumethoddir(MENUMETHODS, menudata);
-        }
-      } else {
-          run_menumethoddir(MENUMETHODS, menudata);
-      }
-    }
+    } else 
+        run_methods(menudata);
   }
   catch(genexcept& p) { p.report(); }
 
Index: update-menus/update-menus.h
===================================================================
RCS file: /cvsroot/menu/menu/update-menus/update-menus.h,v
retrieving revision 1.17
diff -u -r1.17 update-menus.h
--- update-menus/update-menus.h 31 May 2004 11:42:54 -0000      1.17
+++ update-menus/update-menus.h 19 Nov 2005 18:04:55 -0000
@@ -116,7 +116,7 @@
   configinfo()
       : method(method_stderr), compat(parsestream::eol_newline),
       usedefaultmenufilesdirs(true), onlyoutput_to_stdout(false),
-      verbosity(report_quiet)
+      remove_menu(false), verbosity(report_quiet)
     { }
 
   typedef enum { report_quiet, report_normal, report_verbose, report_debug} 
verbosity_type;
@@ -125,6 +125,7 @@
   std::string menumethod;
   bool usedefaultmenufilesdirs;
   bool onlyoutput_to_stdout;
+  bool remove_menu;
 
 
   /** Read configuration file from filename */

Reply via email to