diff -up beesu-2.7/gedit-beesu-plugin-0.4/beesu.gedit-plugin.fix beesu-2.7/gedit-beesu-plugin-0.4/beesu.gedit-plugin --- beesu-2.7/gedit-beesu-plugin-0.4/beesu.gedit-plugin.fix 2010-07-22 05:38:58.000000000 -0400 +++ beesu-2.7/gedit-beesu-plugin-0.4/beesu.gedit-plugin 2012-03-01 16:54:11.491145515 -0500 @@ -1,4 +1,4 @@ -[Gedit Plugin] +[Plugin] Loader=python Module=beesu IAge=2 diff -up beesu-2.7/gedit-beesu-plugin-0.4/beesu.py.fix beesu-2.7/gedit-beesu-plugin-0.4/beesu.py --- beesu-2.7/gedit-beesu-plugin-0.4/beesu.py.fix 2010-11-04 16:35:56.000000000 -0400 +++ beesu-2.7/gedit-beesu-plugin-0.4/beesu.py 2012-03-01 16:54:11.493145496 -0500 @@ -1,4 +1,5 @@ # 2010 - Copyright by Bee . +# 2012 - Rewritten to work with modern Gedit by Tom Callaway # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 @@ -13,77 +14,91 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import gedit -import pygtk -pygtk.require('2.0') -import gtk +from gi.repository import GObject, Gtk, Gedit +# import gedit +# import pygtk +# pygtk.require('2.0') +# import gtk from gettext import gettext as _ import os import tempfile import time +import sys +import traceback import subprocess import pickle -def error_message(message): - def msg_on_close_destroy(button,response_id,dialog): - if response_id == gtk.RESPONSE_CLOSE: - dialog.destroy() - - msg_dialog = gtk.MessageDialog(flags = gtk.DIALOG_MODAL, buttons = gtk.BUTTONS_CLOSE, type = gtk.MESSAGE_ERROR, message_format = message) - msg_dialog.connect('response', msg_on_close_destroy, msg_dialog) - msg_dialog.run() - -class WindowControl: - def __init__(self, plugin, window): - self._window = window - self._plugin = plugin +ui_str = """ + + + + + + + + + +""" + +class beesuPlugin(GObject.Object, Gedit.WindowActivatable): + __gtype_name__ = "BeesuPlugin" + + window = GObject.property(type=Gedit.Window) + + def __init__(self): + GObject.Object.__init__(self) + + def do_activate(self): self._insert_menu() - def deactivate(self): + def do_deactivate(self): self._remove_menu() - self._window = self._plugin = self._action_group = None + + def _remove_menu(self): + manager = self.window.get_ui_manager() + manager.remove_ui(self._ui_id) + manager.remove_action_group(self._action_group) + self._action_group = None + manager.ensure_update() def _insert_menu(self): - manager = self._window.get_ui_manager() + manager = self.window.get_ui_manager() - self._action_group = gtk.ActionGroup("beesuPluginActions") - self._action_group.add_actions([("beesuPlugin", None, + self._action_group = Gtk.ActionGroup(name="beesuPluginActions") + self._action_group.add_actions([("beesuPlugin", None, _("Open as \"root\""), - None, + None, _("Open this document as \"root\" in gedit with SED_BEESU_COMMAND_LINE_NAME"), self.beesu)]) manager.insert_action_group(self._action_group, -1) - - ui_str = """ - - - - - - - - - """ - self._ui_id = manager.add_ui_from_string(ui_str) - def _remove_menu(self): - manager = self._window.get_ui_manager() - manager.remove_ui(self._ui_id) - manager.remove_action_group(self._action_group) - manager.ensure_update() + def is_configurable(self): + return False + + def error_message(message): + def msg_on_close_destroy(button,response_id,dialog): + if response_id == Gtk.ResponseType.CLOSE: + dialog.destroy() + + msg_dialog = Gtk.MessageDialog(self, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, message) + msg_dialog.connect('response', msg_on_close_destroy, msg_dialog) + msg_dialog.run() - def update_ui(self): - self._action_group.set_sensitive(self._window.get_active_document() != None) def beesu(self, action): - tab = self._window.get_active_tab() - doc = self._window.get_active_document() + tab = self.window.get_active_tab() + doc = self.window.get_active_document() filename = None if doc: - filename = doc.get_uri() + location = doc.get_location() + if location: + uri = location.get_uri() + if uri is not None: + if uri[:7] == "file://": + filename = location.get_parse_name() if not self.beesu_exec(filename): return @@ -91,45 +106,36 @@ class WindowControl: if tab: if doc == tab.get_document(): if doc.get_readonly() or doc.is_untouched(): - self._window.close_tab(tab) - if self._window.get_active_document() == None and self._window.get_active_tab() == None: - self._window.destroy() - + self.window.close_tab(tab) + if self.window.get_active_document() == None and self.window.get_active_tab() == None: + self.window.destroy() + def beesu_exec(self, filename): tmp = tempfile.NamedTemporaryFile(delete = False) lockfile = tmp.name tmp.close() - #['beesu', '-l', '-c', '/usr/libexec/gedit-beesu-plugin','gedit-beesu-plugin','/usr/bin/gedit','gedit',lockfile] - shell_args = [SED_BEESU_COMMAND_LINE_SU,'/usr/libexec/gedit-beesu-plugin','gedit-beesu-plugin','gedit','gedit',lockfile] + #shell_args = [SED_BEESU_COMMAND_LINE_SU,'/usr/libexec/gedit-beesu-plugin','gedit-beesu-plugin','gedit','gedit',lockfile] if filename != None and filename != '': - shell_args.append(filename) + # shell_args = ['beesu', '-l', '-c', '\"/usr/bin/gedit %s\"' % filename] + shell_args = ['beesu', '-l', '-c', '/usr/libexec/gedit-beesu-plugin','gedit-beesu-plugin','gedit','gedit',lockfile, filename] + # shell_args = ['/usr/libexec/gedit-beesu-plugin','gedit-beesu-plugin','gedit','gedit', lockfile, filename] + else: + return False + print shell_args try: subprocess.Popen(shell_args, stderr=open(os.devnull)).wait() except: - error_message(_("Error running SED_BEESU_COMMAND_LINE_NAME: " + sys.exc_info()[0])) + etype = sys.exc_info()[0] + evalue = sys.exc_info()[1] + etb = traceback.extract_tb(sys.exc_info()[2]) + myerror = 'Error running SED_BEESU_COMMAND_LINE_NAME: ' + '\n' + 'Error Type: ' + str(etype) + '\n' + 'Error Value: ' + str(evalue) + '\n' + 'Traceback: ' + str(etb) + self.error_message(_(myerror)) return False + print 'Hey, it says the Popen succeeded.' + if os.path.isfile(lockfile): os.remove(lockfile) return False return True - -class beesuPlugin(gedit.Plugin): - def __init__(self): - gedit.Plugin.__init__(self) - self._instances = {} - - def activate(self, window): - self._instances[window] = WindowControl(self, window) - - def deactivate(self, window): - self._instances[window].deactivate() - del self._instances[window] - - def update_ui(self, window): - self._instances[window].update_ui() - - def is_configurable(self): - return False - diff -up beesu-2.7/gedit-beesu-plugin-0.4/libexec/gedit-beesu-plugin.c.fix beesu-2.7/gedit-beesu-plugin-0.4/libexec/gedit-beesu-plugin.c --- beesu-2.7/gedit-beesu-plugin-0.4/libexec/gedit-beesu-plugin.c.fix 2011-01-07 11:33:15.000000000 -0500 +++ beesu-2.7/gedit-beesu-plugin-0.4/libexec/gedit-beesu-plugin.c 2012-03-01 16:59:49.454787493 -0500 @@ -40,61 +40,109 @@ int main(int argc, char **argv) int fd; int pid; int status; + int dup2_return = 0; char syncfile[]="/tmp/gbeesu.XXXXXX"; + pid_t cpid; if(argc > REQUIRED_ARGC) { + printf("DEBUG: Number of necessary args found.\n"); command = argv[1]; // 1, REQUIRED_ARGC - 3 if(strcmp(command, "gedit-beesu-plugin") == 0) { + printf("DEBUG: strcmp succeeded.\n"); command = argv[2]; // 2, REQUIRED_ARGC - 2 commandline[0] = argv[3]; // 3, REQUIRED_ARGC - 1 lockfile = argv[4]; // 4, REQUIRED_ARGC if(argc > (REQUIRED_ARGC + 1)) + printf("DEBUG: Appending additional args to commandline.\n"); commandline[1] = argv[REQUIRED_ARGC + 1];// 5, REQUIRED_ARGC + 1 if(lstat(lockfile, &buf) == 0) { + printf("DEBUG: lstat on lockfile succeeded.\n"); if(buf.st_size == 0 && S_ISREG(buf.st_mode)) { + printf("DEBUG: buf checks passed.\n"); fd = mkstemp(syncfile); - if(fd == -1) + printf("DEBUG: fd initialized.\n"); + if(fd == -1) { + printf("DEBUG: fd failure, exiting.\n"); return EXIT_FAILURE; + } + printf("DEBUG: About to close fd.\n"); close(fd); + printf("DEBUG: fd closed, about to fork.\n"); pid = fork(); + printf("DEBUG: Going into PID switch.\n"); switch(pid) { case 0: + printf("DEBUG: PID switch case 0.\n"); +/* fd = open("/dev/null", O_RDWR); if(fd != -1) { - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - close(fd); + printf("DEBUG: Opened fd for /dev/null.\n"); + printf("DEBUG: Calling dup2 for 0\n"); + dup2_return = dup2(fd, 0); + if(dup2_return < 0) { + printf("DEBUG: dup2(fd, 0) failed with error %d.\n", dup2_return); + } else { + printf("DEBUG: dup2(fd, 0) succeeded.\n"); + } + printf("DEBUG: Calling dup2 for 1\n"); + dup2_return = dup2(fd, 1); + if(dup2_return < 0) { + printf("DEBUG: dup2(fd, 1) failed with error %d.\n", dup2_return); + + } else { + printf("DEBUG: dup2(fd, 1) succeeded.\n"); + } + printf("DEBUG: Calling dup2 for 2\n"); + dup2_return = dup2(fd, 2); + if(dup2_return < 0) { + printf("DEBUG: dup2(fd, 2) failed with error %d.\n", dup2_return); + } else { + printf("DEBUG: dup2(fd, 2) succeeded.\n"); + } } + printf("DEBUG: Closing fd for /dev/null.\n"); + close(fd); +*/ + printf("DEBUG: About to call signal(SIGHUP, SIG_IGN).\n"); signal(SIGHUP, SIG_IGN); + printf("DEBUG: Going into FORK switch.\n"); switch(fork()) // internal fork!! { case -1: + printf("DEBUG: FORK switch case -1.\n"); _exit(EXIT_FAILURE); break; case 0: + printf("DEBUG: FORK switch case 0.\n"); signal(SIGHUP, SIG_IGN); unlink(syncfile); - execvp(command, commandline); + printf("DEBUG: About to execvp %s %s %s.\n", command, commandline[0], commandline[1]); + if (execvp(command, commandline) < 0) { + printf("DEBUG: execvp failed.\n"); + } _exit(EXIT_FAILURE); break; default: + printf("DEBUG: FORK switch default.\n"); break; } _exit(EXIT_SUCCESS); break; case -1: + printf("DEBUG: PID switch case -1.\n"); unlink(syncfile); return EXIT_FAILURE; break; default: + printf("DEBUG: PID switch case default.\n"); waitpid(pid, &status, 0); // Wait (max 20 seconds!!!) for the syncfile to be removed!!! + printf("DEBUG: Waiting for the syncfile to be removed.\n"); for(status = 0; status < 20; status++) { if(access(syncfile, F_OK) == 0) @@ -108,15 +156,19 @@ int main(int argc, char **argv) } if(access(syncfile, F_OK) == 0) { + printf("DEBUG: Syncfile error.\n"); // Enter here on error unlink(syncfile); } else { + printf("DEBUG: Syncfile success.\n"); // Enter here on success!!!!!! - usleep(50000); + printf("DEBUG: usleeping for 5000000, hope that is long enough for gedit to respawn.\n"); + usleep(5000000); unlink(lockfile); } + printf("DEBUG: About to return SUCCESS.\n"); return EXIT_SUCCESS; break; } @@ -124,6 +176,7 @@ int main(int argc, char **argv) } } } + printf("DEBUG: About to return FAILURE.\n"); return EXIT_FAILURE; } diff -up beesu-2.7/gedit-beesu-plugin-0.4/Makefile.in.fix beesu-2.7/gedit-beesu-plugin-0.4/Makefile.in --- beesu-2.7/gedit-beesu-plugin-0.4/Makefile.in.fix 2010-11-04 16:39:29.000000000 -0400 +++ beesu-2.7/gedit-beesu-plugin-0.4/Makefile.in 2012-03-01 16:54:11.497145456 -0500 @@ -13,19 +13,19 @@ all: # To install things in the right place install: - $(MKDIR) -v -p $(LIBDIR)/gedit-2/plugins - $(INSTALL) -p -m 644 beesu.gedit-plugin $(LIBDIR)/gedit-2/plugins - $(MKDIR) -v -p $(LIBDIR)/gedit-2/plugins/beesu - $(INSTALL) -p -m 644 beesu/__init__.py $(LIBDIR)/gedit-2/plugins/beesu - $(INSTALL) -p -m 644 beesu/beesu.py $(LIBDIR)/gedit-2/plugins/beesu + $(MKDIR) -v -p $(LIBDIR)/gedit/plugins + $(INSTALL) -p -m 644 beesu.gedit-plugin $(LIBDIR)/gedit/plugins/beesu.plugin + $(MKDIR) -v -p $(LIBDIR)/gedit/plugins/beesu + $(INSTALL) -p -m 644 beesu/__init__.py $(LIBDIR)/gedit/plugins/beesu + $(INSTALL) -p -m 644 beesu/beesu.py $(LIBDIR)/gedit/plugins/beesu $(MKDIR) -v -p $(LIBEXECDIR) $(INSTALL) -p -m 755 libexec/gedit-beesu-plugin $(LIBEXECDIR)/ # uninstall uninstall: $(RM) $(LIBEXECDIR)/gedit-beesu-plugin - $(RM) $(LIBDIR)/gedit-2/plugins/beesu/beesu.py - $(RM) $(LIBDIR)/gedit-2/plugins/beesu/__init__.py - $(RM) $(LIBDIR)/gedit-2/plugins/beesu.gedit-plugin - $(RMDIR) $(LIBDIR)/gedit-2/plugins/beesu + $(RM) $(LIBDIR)/gedit/plugins/beesu/beesu.py + $(RM) $(LIBDIR)/gedit/plugins/beesu/__init__.py + $(RM) $(LIBDIR)/gedit/plugins/beesu.plugin + $(RMDIR) $(LIBDIR)/gedit/plugins/beesu