Skip to contentSkip to conversation

terminal.py: Provides devshell support for gnome-terminal >= 3.10

PATCH New Alejandro Hernandez 1 participant 2 messages Aug 18, 2015

lore
Share & tools
lore
#0 lore raw

cover terminal.py: Provides devshell support for gnome-terminal >= 3.10

The following changes since commit 645435a645a0817cec94ce1433eb74fbe7388416:

bitbake: toastergui: Added IDs to elements used in testing (2015-08-17 08:48:28 +0100)

are available in the git repository at:

git://git.yoctoproject.org/poky-contrib hsalejandro/gnome-terminal-devshell
http://git.yoctoproject.org/cgit.cgi/poky-contrib/log/?h=hsalejandro/gnome-terminal-devshell

Alejandro Hernandez (1):
terminal.py: Provides devshell support for gnome-terminal >= 3.10

 meta/lib/oe/terminal.py | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH 1/1 terminal.py: Provides devshell support for gnome-terminal >= 3.10

gnome-terminal works in a server-client model, we used to disable this using --disable-factory switch, but newer gnome terminals (>= v3.10) lack support for this switch, now were forced to use its default behavior, which is: when launching a new terminal, return immediately and reparent the new bash/sh process to the server gnome-terminal process, instead of returning once the user closes the terminal,
this behavior also breaks the relationship between our running process and the new spawned one, giving us no way of checking if it is stil running.

This patch finds the PID of the gnome-terminal server, gets its children processes before and after spawning our new terminal, finds out the PID of our new spawned terminal, and lastly forces bitbake to wait for it to end before continuing.

[YOCTO #7254]

---
 meta/lib/oe/terminal.py | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)
meta/lib/oe/terminal.py +38 -8
index 52a8913..a4798e9 100644
@@ -3,6 +3,9 @@ import oe.classutils
 import shlex
 from bb.process import Popen, ExecutionError
 from distutils.version import LooseVersion
+import os
+import time
+from subprocess import check_output
 
 logger = logging.getLogger('BitBake.OE.Terminal')
 
@@ -53,7 +56,7 @@ class XTerminal(Terminal):
             raise UnsupportedTerminal(self.name)
 
 class Gnome(XTerminal):
-    command = 'gnome-terminal -t "{title}" --disable-factory -x {command}'
+    command = 'gnome-terminal -t "{title}" -x {command}'
     priority = 2
 
     def __init__(self, sh_cmd, title=None, env=None, d=None):
@@ -63,11 +66,6 @@ class Gnome(XTerminal):
         # Once fixed on the gnome-terminal project, this should be removed.
         if os.getenv('LC_ALL'): os.putenv('LC_ALL','')
 
-        # Check version
-        vernum = check_terminal_version("gnome-terminal")
-        if vernum and LooseVersion(vernum) >= '3.10':
-            logger.debug(1, 'Gnome-Terminal 3.10 or later does not support --disable-factory')
-            self.command = 'gnome-terminal -t "{title}" -x {command}'
         XTerminal.__init__(self, sh_cmd, title, env, d)
 
 class Mate(XTerminal):
@@ -211,8 +209,40 @@ def spawn(name, sh_cmd, title=None, env=None, d=None):
     except KeyError:
         raise UnsupportedTerminal(name)
 
-    pipe = terminal(sh_cmd, title, env, d)
-    output = pipe.communicate()[0]
+
+    # We handle gnome-terminal as a special case
+    # we need to check which is our new spawned process
+    # so we can wait for it to end before we can continue
+
+    if('gnome' in name):
+        logger.debug(1, 'Attempting to get our new spawned gnome-terminal process ID')
+        try:
+            gnome_pid = check_output(["ps", "-C", "gnome-terminal", "-o", "pid"]).split()[1]
+        except subprocess.CalledProcessError as ex:
+            bb.error("Couldn't get gnome-terminal process ID")
+        try:
+            g_children_bfr = check_output(["ps", "--ppid", str(gnome_pid), "-o", "pid"]).split("\n")
+        except subprocess.CalledProcessError as ex:
+            bb.error("Couldn't get gnome-terminal children processes")
+
+        pipe = terminal(sh_cmd, title, env, d)
+        output = pipe.communicate()[0]
+
+        try:
+            g_children_aftr = check_output(["ps", "--ppid", str(gnome_pid), "-o", "pid"]).split("\n")
+        except subprocess.CalledProcessError as ex:
+            bb.error("Couldn't get gnome-terminal children processes")
+
+        new_pid = list(set(g_children_aftr)-set(g_children_bfr))
+        if (len(new_pid) != 1):
+            bb.error("Couldn't get new terminal process ID")
+        else:
+            new_pid = new_pid[0].strip()
+            while(os.path.exists("/proc/%s" % new_pid)):
+                time.sleep(1)
+    else:
+        pipe = terminal(sh_cmd, title, env, d)
+        output = pipe.communicate()[0]
     if pipe.returncode != 0:
         raise ExecutionError(sh_cmd, pipe.returncode, output)
 
Signature · 1 line
1.9.1