Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH 0/1] terminal.py: Provides devshell support for gnome-terminal >= 3.10
@ 2015-08-18 17:41 Alejandro Hernandez
  2015-08-18 17:41 ` [PATCH 1/1] " Alejandro Hernandez
  0 siblings, 1 reply; 2+ messages in thread
From: Alejandro Hernandez @ 2015-08-18 17:41 UTC (permalink / raw)
  To: openembedded-core

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(-)

-- 
1.9.1



^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] terminal.py: Provides devshell support for gnome-terminal >= 3.10
  2015-08-18 17:41 [PATCH 0/1] terminal.py: Provides devshell support for gnome-terminal >= 3.10 Alejandro Hernandez
@ 2015-08-18 17:41 ` Alejandro Hernandez
  0 siblings, 0 replies; 2+ messages in thread
From: Alejandro Hernandez @ 2015-08-18 17:41 UTC (permalink / raw)
  To: openembedded-core

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]

Signed-off-by: Alejandro Hernandez <alejandro.hernandez@linux.intel.com>
---
 meta/lib/oe/terminal.py | 46 ++++++++++++++++++++++++++++++++++++++--------
 1 file changed, 38 insertions(+), 8 deletions(-)

diff --git a/meta/lib/oe/terminal.py b/meta/lib/oe/terminal.py
index 52a8913..a4798e9 100644
--- a/meta/lib/oe/terminal.py
+++ b/meta/lib/oe/terminal.py
@@ -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)
 
-- 
1.9.1



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-08-18 17:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-18 17:41 [PATCH 0/1] terminal.py: Provides devshell support for gnome-terminal >= 3.10 Alejandro Hernandez
2015-08-18 17:41 ` [PATCH 1/1] " Alejandro Hernandez

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox