aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/util.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2016-05-25 11:37:40 -0400
committerKevin O'Connor <kevin@koconnor.net>2016-05-25 11:37:40 -0400
commitf582a36e4df16d5709943f7df17a900c8bcc12ab (patch)
tree628d927c4f3e19e54618f7f47c7a44af66bf0c2f /klippy/util.py
parent37a91e9c10648208de002c75df304e23ca89e256 (diff)
downloadkutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.gz
kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.tar.xz
kutter-f582a36e4df16d5709943f7df17a900c8bcc12ab.zip
Initial commit of source code.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/util.py')
-rw-r--r--klippy/util.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/klippy/util.py b/klippy/util.py
new file mode 100644
index 00000000..caac827e
--- /dev/null
+++ b/klippy/util.py
@@ -0,0 +1,32 @@
+# Low level unix utility functions
+#
+# Copyright (C) 2016 Kevin O'Connor <kevin@koconnor.net>
+#
+# This file may be distributed under the terms of the GNU GPLv3 license.
+
+import os, pty, fcntl, termios, signal
+
+# Return the SIGINT interrupt handler back to the OS default
+def fix_sigint():
+ signal.signal(signal.SIGINT, signal.SIG_DFL)
+fix_sigint()
+
+# Set a file-descriptor as non-blocking
+def set_nonblock(fd):
+ fcntl.fcntl(fd, fcntl.F_SETFL
+ , fcntl.fcntl(fd, fcntl.F_GETFL) | os.O_NONBLOCK)
+
+# Support for creating a pseudo-tty for emulating a serial port
+def create_pty(ptyname):
+ mfd, sfd = pty.openpty()
+ try:
+ os.unlink(ptyname)
+ except os.error:
+ pass
+ os.symlink(os.ttyname(sfd), ptyname)
+ fcntl.fcntl(mfd, fcntl.F_SETFL
+ , fcntl.fcntl(mfd, fcntl.F_GETFL) | os.O_NONBLOCK)
+ old = termios.tcgetattr(mfd)
+ old[3] = old[3] & ~termios.ECHO
+ termios.tcsetattr(mfd, termios.TCSADRAIN, old)
+ return mfd