[gedit/gnome-2-28] Execute external tool in shell if no hash bang is specified



commit 8b82e989785150a9ee35e7219e96d04401c8c51c
Author: Jesse van den Kieboom <jesse icecrew nl>
Date:   Sat Nov 7 22:13:58 2009 +0100

    Execute external tool in shell if no hash bang is specified

 plugins/externaltools/tools/capture.py   |    7 ++++---
 plugins/externaltools/tools/functions.py |    7 ++++++-
 plugins/externaltools/tools/library.py   |   15 +++++++++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)
---
diff --git a/plugins/externaltools/tools/capture.py b/plugins/externaltools/tools/capture.py
index d8b21b5..621382d 100644
--- a/plugins/externaltools/tools/capture.py
+++ b/plugins/externaltools/tools/capture.py
@@ -28,6 +28,7 @@ class Capture(gobject.GObject):
     CAPTURE_STDOUT = 0x01
     CAPTURE_STDERR = 0x02
     CAPTURE_BOTH   = 0x03
+    CAPTURE_NEEDS_SHELL = 0x04
     
     WRITE_BUFFER_SIZE = 0x4000
 
@@ -43,7 +44,7 @@ class Capture(gobject.GObject):
         self.pipe = None
         self.env = env
         self.cwd = cwd
-        self.flags = self.CAPTURE_BOTH
+        self.flags = self.CAPTURE_BOTH | self.CAPTURE_NEEDS_SHELL
         self.command = command
         self.input_text = None
 
@@ -69,7 +70,7 @@ class Capture(gobject.GObject):
         # Initialize pipe
         popen_args = {
             'cwd'  : self.cwd,
-            'shell': False,
+            'shell': self.flags & self.CAPTURE_NEEDS_SHELL,
             'env'  : self.env
         }
         
@@ -199,7 +200,7 @@ class Capture(gobject.GObject):
                 os.kill(self.pipe.pid, signal.SIGTERM)
                 self.tried_killing = True
             else:
-                os.killpg(self.pipe.pid, sigal.SIGKILL)
+                os.kill(self.pipe.pid, signal.SIGKILL)
 
     def on_child_end(self, pid, error_code):
         # In an idle, so it is emitted after all the std*-line signals
diff --git a/plugins/externaltools/tools/functions.py b/plugins/externaltools/tools/functions.py
index cec46ef..04a1aea 100644
--- a/plugins/externaltools/tools/functions.py
+++ b/plugins/externaltools/tools/functions.py
@@ -109,7 +109,12 @@ def run_external_tool(window, node):
         capture.set_env(GEDIT_DOCUMENTS_URI  = ' '.join(documents_uri),
                         GEDIT_DOCUMENTS_PATH = ' '.join(documents_path))
 
-    capture.set_flags(capture.CAPTURE_BOTH)
+    flags = capture.CAPTURE_BOTH
+    
+    if not node.has_hash_bang():
+        flags |= capture.CAPTURE_NEEDS_SHELL
+
+    capture.set_flags(flags)
 
     # Get input text
     input_type = node.input
diff --git a/plugins/externaltools/tools/library.py b/plugins/externaltools/tools/library.py
index e42e58d..16a2018 100644
--- a/plugins/externaltools/tools/library.py
+++ b/plugins/externaltools/tools/library.py
@@ -348,6 +348,21 @@ class Tool(object):
         self._set_property_if_changed('Languages', value)
     languages = property(get_languages, set_languages)
 
+    def has_hash_bang(self):
+        if self.filename is None:
+            return True
+
+        filename = self.library.get_full_path(self.get_path())
+        if filename is None:
+            return True
+
+        fp = open(filename, 'r', 1)
+        for line in fp:
+            if line.strip() == '':
+                continue
+            
+            return line.startswith('#!')
+
     # There is no property for this one because this function is quite
     # expensive to perform
     def get_script(self):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]