diff options
-rw-r--r-- | meta/classes/devshell.bbclass | 32 | ||||
-rwxr-xr-x | scripts/oepydevshell-internal.py | 32 |
2 files changed, 64 insertions, 0 deletions
diff --git a/meta/classes/devshell.bbclass b/meta/classes/devshell.bbclass index 92edb9ef25e..bdc2df20425 100644 --- a/meta/classes/devshell.bbclass +++ b/meta/classes/devshell.bbclass @@ -31,3 +31,35 @@ python () { d.setVarFlag("do_devshell", "manualfakeroot", "1") d.delVarFlag("do_devshell", "fakeroot") } + +python do_devpyshell() { + m, s = os.openpty() + sname = os.ttyname(s) + os.system('stty cs8 -icanon -echo < %s' % sname) + pid = os.fork() + if pid: + oe_terminal("oepydevshell-internal.py %s" % sname, 'OpenEmbedded Developer PyShell', d) + os._exit(0) + else: + os.dup2(m, sys.stdin.fileno()) + os.dup2(m, sys.stdout.fileno()) + os.dup2(m, sys.stderr.fileno()) + bb.utils.nonblockingfd(sys.stdout) + bb.utils.nonblockingfd(sys.stdin) + + _context = { + "os": os, + "bb": bb, + "time": time, + "d": d, + } + + import code + try: + code.interact("BB: ", local=_context) + except Exception as e: + bb.fatal(str(e)) +} +addtask devpyshell after do_patch + +do_devpyshell[nostamp] = "1" diff --git a/scripts/oepydevshell-internal.py b/scripts/oepydevshell-internal.py new file mode 100755 index 00000000000..946f56298cd --- /dev/null +++ b/scripts/oepydevshell-internal.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +import os +import sys +import time +import select +import fcntl + +def nonblockingfd(fd): + fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK) + +if len(sys.argv) != 2: + print("Incorrect parameters") + sys.exit(1) + +try: + print(sys.argv[1]) + pty = open(sys.argv[1], "w+b") + nonblockingfd(pty) + nonblockingfd(sys.stdin) + while True: + (ready, _, _) = select.select([pty, sys.stdin], [] , [], 1) + if pty in ready: + r = pty.read() + sys.stdout.write(r) + if sys.stdin in ready: + r = sys.stdin.read() + pty.write(r) +except Exception as e: + print(str(e)) + time.sleep(5) + |