summaryrefslogtreecommitdiffstats
path: root/scripts/oepydevshell-internal.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/oepydevshell-internal.py')
-rwxr-xr-xscripts/oepydevshell-internal.py104
1 files changed, 0 insertions, 104 deletions
diff --git a/scripts/oepydevshell-internal.py b/scripts/oepydevshell-internal.py
deleted file mode 100755
index 3bf7df1114..0000000000
--- a/scripts/oepydevshell-internal.py
+++ /dev/null
@@ -1,104 +0,0 @@
1#!/usr/bin/env python3
2#
3# Copyright OpenEmbedded Contributors
4#
5# SPDX-License-Identifier: GPL-2.0-only
6#
7
8import os
9import sys
10import time
11import select
12import fcntl
13import termios
14import readline
15import signal
16
17def nonblockingfd(fd):
18 fcntl.fcntl(fd, fcntl.F_SETFL, fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
19
20def echonocbreak(fd):
21 old = termios.tcgetattr(fd)
22 old[3] = old[3] | termios.ECHO | termios.ICANON
23 termios.tcsetattr(fd, termios.TCSADRAIN, old)
24
25def cbreaknoecho(fd):
26 old = termios.tcgetattr(fd)
27 old[3] = old[3] &~ termios.ECHO &~ termios.ICANON
28 termios.tcsetattr(fd, termios.TCSADRAIN, old)
29
30if len(sys.argv) != 3 or sys.argv[1] in ('-h', '--help'):
31 print('oepydevshell-internal.py: error: the following arguments are required: pty, pid\n'
32 'Usage: oepydevshell-internal.py pty pid\n\n'
33 'OpenEmbedded oepydevshell-internal.py - internal script called from meta/classes/devshell.bbclass\n\n'
34 'arguments:\n'
35 ' pty pty device name\n'
36 ' pid parent process id\n\n'
37 'options:\n'
38 ' -h, --help show this help message and exit\n')
39 sys.exit(2)
40
41pty = open(sys.argv[1], "w+b", 0)
42parent = int(sys.argv[2])
43
44nonblockingfd(pty)
45nonblockingfd(sys.stdin)
46
47
48histfile = os.path.expanduser("~/.oepydevshell-history")
49readline.parse_and_bind("tab: complete")
50try:
51 readline.read_history_file(histfile)
52except IOError:
53 pass
54
55try:
56
57 i = ""
58 o = ""
59 # Need cbreak/noecho whilst in select so we trigger on any keypress
60 cbreaknoecho(sys.stdin.fileno())
61 # Send our PID to the other end so they can kill us.
62 pty.write(str(os.getpid()).encode('utf-8') + b"\n")
63 while True:
64 try:
65 writers = []
66 if i:
67 writers.append(sys.stdout)
68 (ready, _, _) = select.select([pty, sys.stdin], writers , [], 0)
69 try:
70 if pty in ready:
71 readdata = pty.read()
72 if readdata:
73 i = i + readdata.decode('utf-8')
74 if i:
75 # Write a page at a time to avoid overflowing output
76 # d.keys() is a good way to do that
77 sys.stdout.write(i[:4096])
78 sys.stdout.flush()
79 i = i[4096:]
80 if sys.stdin in ready:
81 echonocbreak(sys.stdin.fileno())
82 o = input().encode('utf-8')
83 cbreaknoecho(sys.stdin.fileno())
84 pty.write(o + b"\n")
85 except (IOError, OSError) as e:
86 if e.errno == 11:
87 continue
88 if e.errno == 5:
89 sys.exit(0)
90 raise
91 except EOFError:
92 sys.exit(0)
93 except KeyboardInterrupt:
94 os.kill(parent, signal.SIGINT)
95
96except SystemExit:
97 pass
98except Exception as e:
99 import traceback
100 print("Exception in oepydehshell-internal: " + str(e))
101 traceback.print_exc()
102 time.sleep(5)
103finally:
104 readline.write_history_file(histfile)