Re: Python - getch() and kbhit()
On Tue, 9 Jan 2018 10:36:51 +0200 Shlomo Solomonwrote: > Since import msvcrt in Python is Windows specific, I adapted some code > I found to provide kbhit() and getch() in Python under Linux. > > I'm attaching KBHIT.py which replaces msvcrt and a small program to > demonstrate how to use it - KBHIT-test.py. > > The KBHIT.py documentation includes usage instructions and also a link > to the code I borrowed and (I hope) improved. > > I've been using the attached code in my UMENU2 program so menu choices can be selected with a single keystroke and no Enter key necessary. What you've added is kbhit() so you can do non-blocking keyboard reads, and of course the ability to handle both Posix and Windows transparently. If I were to rewrite your KBHIT.py program, I'd rewrite it to carry a lot less state. I'd get rid of _init_(), and I'd make getch(), kbhit() and set_normal_term() class functions so the only reason for making it a class is namespacing. The world's fastest typist is what, 200 wpm which is about 3.1/second: There's plenty of time to go raw and then go cooked for each character retrieved. It doesn't seem as efficient, but the bottleneck is the typist and going raw then cooked on each keystroke makes your code simpler, eliminates state, and probably decreases the need for set_norm_term(). SteveT Steve Litt December 2017 featured book: Thriving in Tough Times http://www.troubleshooters.com/thrive getch_unix.py Description: Binary data ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: oVirt over CentOS or ovirt-node
On Mon, Jan 8, 2018 at 10:48 PM, Rabin Yasharzadehewrote: > Just wondering which OS used for the host, I was wondering if one version is > more supported then the other. > > Thanks. > > -- > Rabin Hello, We've installed oVrit on stock CentOS 7 using the oVirt yum repositories. - Gilboa > > On 8 January 2018 at 09:50, Gilboa Davara wrote: >> >> On Tue, Jan 2, 2018 at 5:41 PM, Rabin Yasharzadehe wrote: >> > >> > ovirt-node with version 4.1 gave a alot of problems with nfs shares >> > but 4.2 did work much better "out of the box" after clean install (I was >> > not >> > able to upgrade from 4.1 to 4.2 with ovirt-nodes) >> > >> > so my question is basicly , if I'm looking to setup something for the >> > long >> > run, which I can extend and upgrade in the near future, >> > which host platform should I choose ? ovirt-node or a simple CentOS7 ? >> > >> > Tx >> >> We're using 3-node oVirt 4.0.6 over GlusterFS cluster (w/ self hosted >> engine) in production for long while now. >> The system was installed by my IT manager from barebone (was >> originally installed in the 3.6 days). >> If you have specific questions I can forward them... >> >> - Gilboa > > ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: oVirt over CentOS or ovirt-node
Hi Didi ... long time ... On 9 January 2018 at 16:00, Yedidyah Bar Davidwrote: > Hi Rabin :-), > > On Mon, Jan 8, 2018 at 10:48 PM, Rabin Yasharzadehe > wrote: > >> Just wondering which OS used for the host, I was wondering if one version >> is more supported then the other. >> > > Why not start a thread on us...@ovirt.org, then? > Yaniv all ready point me to the mailing list, I subscribed, but didn't have time to post a question there yet. > You might find this useful/interesting: > > http://lists.ovirt.org/pipermail/users/2017-April/081221.html > > Partial quote: > > - oVirt Node jumped from 7.1% on 3.6 survey to 19.9% in 4.1! > > So most people use CentOS, but some do use ovirt-node, > and now more than in the past. > Thank you, the is exactly what i was looking for. Right now I'm starting to play with ovirt which is more of POC for a small setup, but as you may know, some setups will become "production" if the POC works and I was looking around to see which platform is more popular, and where can i find more support and which host-os have a better upgrade path > Both are supported. I'd say node is more for people that prefer > pre-made appliances, while CentOS is for people that want the > most control. > > If you consider node, you might want to read e.g.: > > https://www.ovirt.org/node/faq/ > https://www.ovirt.org/develop/release-management/features/ > node/node-next-persistence/ > > Disclaimer: I am an oVirt developer. > > Best regards, > Thanks for the pointers, and the survey link ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: oVirt over CentOS or ovirt-node
Hi Rabin :-), On Mon, Jan 8, 2018 at 10:48 PM, Rabin Yasharzadehewrote: > Just wondering which OS used for the host, I was wondering if one version > is more supported then the other. > Why not start a thread on us...@ovirt.org, then? You might find this useful/interesting: http://lists.ovirt.org/pipermail/users/2017-April/081221.html Partial quote: - oVirt Node jumped from 7.1% on 3.6 survey to 19.9% in 4.1! So most people use CentOS, but some do use ovirt-node, and now more than in the past. Both are supported. I'd say node is more for people that prefer pre-made appliances, while CentOS is for people that want the most control. If you consider node, you might want to read e.g.: https://www.ovirt.org/node/faq/ https://www.ovirt.org/develop/release-management/features/ node/node-next-persistence/ Disclaimer: I am an oVirt developer. Best regards, > > -- > Rabin > > On 8 January 2018 at 09:50, Gilboa Davara wrote: > >> On Tue, Jan 2, 2018 at 5:41 PM, Rabin Yasharzadehe >> wrote: >> > >> > ovirt-node with version 4.1 gave a alot of problems with nfs shares >> > but 4.2 did work much better "out of the box" after clean install (I >> was not >> > able to upgrade from 4.1 to 4.2 with ovirt-nodes) >> > >> > so my question is basicly , if I'm looking to setup something for the >> long >> > run, which I can extend and upgrade in the near future, >> > which host platform should I choose ? ovirt-node or a simple CentOS7 ? >> > >> > Tx >> >> We're using 3-node oVirt 4.0.6 over GlusterFS cluster (w/ self hosted >> engine) in production for long while now. >> The system was installed by my IT manager from barebone (was >> originally installed in the 3.6 days). >> If you have specific questions I can forward them... >> >> - Gilboa >> > > > ___ > Linux-il mailing list > Linux-il@cs.huji.ac.il > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > > ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Python - getch() and kbhit()
thanks for the update, Shlomo. On Tue, Jan 9, 2018 at 12:40 PM, Shlomo Solomonwrote: > Hi Shlomi, > Thanks for your feedback - my reply below. > > On Tue, 9 Jan 2018 12:21:51 +0200 > Shlomi Fish wrote: > > > Hi Shlomo, > > > > On Tue, Jan 9, 2018 at 10:36 AM, Shlomo Solomon > > wrote: > > > > > Since import msvcrt in Python is Windows specific, I adapted some > > > code I found to provide kbhit() and getch() in Python under Linux. > > > > > > I'm attaching KBHIT.py which replaces msvcrt and a small program to > > > demonstrate how to use it - KBHIT-test.py. > > > > > > The KBHIT.py documentation includes usage instructions and also a > > > link to the code I borrowed and (I hope) improved. > > > > > > > > thanks for your contribution. > > > > some comments: > > > > 1. What is the licence of the code? See > > https://www.mail-archive.com/perl6-users@perl.org/msg04541.html . > > Note the following statement in the code (was already in the code I > "borrowed" and I felt it would be wrong/dis-honest to change it): > This program is free software: you can redistribute it and/or modify > it under the terms of the GNU Lesser General Public License as > published by the Free Software Foundation, either version 3 of the > License, or (at your option) any later version. > > > > > 2. Please use a PyPI-like distribution format, see > > https://github.com/ofek/hatch or > > https://github.com/audreyr/cookiecutter-pypackage . > > You're probably right, but since this was just something I hacked > together to solve a specific problem I was having, I didn't really see > the need to "formalize" it. > > > > > 3. For more best practices, see > > https://github.com/shlomif/Freenode-programming-channel- > FAQ/blob/master/FAQ.mdwn#what-are-some-best-practices-in- > programming-that-i-should-adopt > > . > > > > 4. -test.py should be -example.py > > > > > > > > > > -- > > > Shlomo Solomon > > > http://the-solomons.net > > > Claws Mail 3.11.1 - KDE 4.14.30 - Dolphin 4.14.3 - LINUX Mageia 5 > > > ___ > > > Linux-il mailing list > > > Linux-il@cs.huji.ac.il > > > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > > > > > > > > > > > > > > -- > Shlomo Solomon > http://the-solomons.net > Claws Mail 3.11.1 - KDE 4.14.30 - Dolphin 4.14.3 - LINUX Mageia 5 > -- Shlomi Fish http://www.shlomifish.org/ You can never truly appreciate The Gilmore Girls until you've watched it in the original Klingon. Please reply to list if it's a mailing list post - http://shlom.in/reply . ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Python - getch() and kbhit()
Hi Shlomi, Thanks for your feedback - my reply below. On Tue, 9 Jan 2018 12:21:51 +0200 Shlomi Fishwrote: > Hi Shlomo, > > On Tue, Jan 9, 2018 at 10:36 AM, Shlomo Solomon > wrote: > > > Since import msvcrt in Python is Windows specific, I adapted some > > code I found to provide kbhit() and getch() in Python under Linux. > > > > I'm attaching KBHIT.py which replaces msvcrt and a small program to > > demonstrate how to use it - KBHIT-test.py. > > > > The KBHIT.py documentation includes usage instructions and also a > > link to the code I borrowed and (I hope) improved. > > > > > thanks for your contribution. > > some comments: > > 1. What is the licence of the code? See > https://www.mail-archive.com/perl6-users@perl.org/msg04541.html . Note the following statement in the code (was already in the code I "borrowed" and I felt it would be wrong/dis-honest to change it): This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. > > 2. Please use a PyPI-like distribution format, see > https://github.com/ofek/hatch or > https://github.com/audreyr/cookiecutter-pypackage . You're probably right, but since this was just something I hacked together to solve a specific problem I was having, I didn't really see the need to "formalize" it. > > 3. For more best practices, see > https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ.mdwn#what-are-some-best-practices-in-programming-that-i-should-adopt > . > > 4. -test.py should be -example.py > > > > > > -- > > Shlomo Solomon > > http://the-solomons.net > > Claws Mail 3.11.1 - KDE 4.14.30 - Dolphin 4.14.3 - LINUX Mageia 5 > > ___ > > Linux-il mailing list > > Linux-il@cs.huji.ac.il > > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > > > > > > -- Shlomo Solomon http://the-solomons.net Claws Mail 3.11.1 - KDE 4.14.30 - Dolphin 4.14.3 - LINUX Mageia 5 ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Re: Python - getch() and kbhit()
Hi Shlomo, On Tue, Jan 9, 2018 at 10:36 AM, Shlomo Solomonwrote: > Since import msvcrt in Python is Windows specific, I adapted some code > I found to provide kbhit() and getch() in Python under Linux. > > I'm attaching KBHIT.py which replaces msvcrt and a small program to > demonstrate how to use it - KBHIT-test.py. > > The KBHIT.py documentation includes usage instructions and also a link > to the code I borrowed and (I hope) improved. > > thanks for your contribution. some comments: 1. What is the licence of the code? See https://www.mail-archive.com/perl6-users@perl.org/msg04541.html . 2. Please use a PyPI-like distribution format, see https://github.com/ofek/hatch or https://github.com/audreyr/cookiecutter-pypackage . 3. For more best practices, see https://github.com/shlomif/Freenode-programming-channel-FAQ/blob/master/FAQ.mdwn#what-are-some-best-practices-in-programming-that-i-should-adopt . 4. -test.py should be -example.py > > -- > Shlomo Solomon > http://the-solomons.net > Claws Mail 3.11.1 - KDE 4.14.30 - Dolphin 4.14.3 - LINUX Mageia 5 > ___ > Linux-il mailing list > Linux-il@cs.huji.ac.il > http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il > > -- Shlomi Fish http://www.shlomifish.org/ You can never truly appreciate The Gilmore Girls until you've watched it in the original Klingon. Please reply to list if it's a mailing list post - http://shlom.in/reply . ___ Linux-il mailing list Linux-il@cs.huji.ac.il http://mailman.cs.huji.ac.il/mailman/listinfo/linux-il
Python - getch() and kbhit()
Since import msvcrt in Python is Windows specific, I adapted some code I found to provide kbhit() and getch() in Python under Linux. I'm attaching KBHIT.py which replaces msvcrt and a small program to demonstrate how to use it - KBHIT-test.py. The KBHIT.py documentation includes usage instructions and also a link to the code I borrowed and (I hope) improved. -- Shlomo Solomon http://the-solomons.net Claws Mail 3.11.1 - KDE 4.14.30 - Dolphin 4.14.3 - LINUX Mageia 5""" KBHIT-test.py Shlomo Solomon program to demonstrate the use of kbhit and getch in LINUX """ import KBHIT kbd = KBHIT.KBHit() # define a keyboard object def get_input(): """ use kbhit and getch to get keyboard input """ key_code = 0 key_char = None if kbd.kbhit(): print "hit ", key_char = kbd.getch() key_code = ord(key_char) if key_code == KBHIT.ENTER: print "ENTER" elif key_code == KBHIT.TAB: print "TAB" elif key_code == KBHIT.BACKSPACE: print "BACKSPACE" elif key_code == KBHIT.ESC: print "ESCAPE" else: print key_char, "code=", key_code return key_code, key_char def main(): """ main runs until Escape is hit """ print "Starting test program - waiting for input" print "Hit ESC to end the test" key_code = 0 while key_code != KBHIT.ESC: key_code, key_char = get_input() print "End of test" if __name__ == "__main__": main() """ KBHIT.py A Python class to implement kbhit() and getch() adapted by Shlomo Solomon from http://home.wlu.edu/~levys/software/kbhit.py NOTES- This version has been tested on LINUX, but should work on Windows too - the original code also had getarrow() which I deleted in this version - works with ASCII chars, ENTER, ESC, BACKSPACE - NOT with special keys - Does not work with IDLE. > 2 ways to use in LINUX - the 2nd one is better!! >>> 1 > from KBHIT import KBHit kbd = KBHit() Then use as follows: if kbd.kbhit(): print kbd.getch() optionally - add the following constants: ENTER = 10 ESC = 27 BACKSPACE = 127 TAB = 9 >>> >>> 2 > import KBHIT kbd = KBHIT.KBHit() Then use as follows: if kbd.kbhit(): print kbd.getch() the constants mentioned in the first method will be available as: KBHIT.ENTER, etc >>> This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. """ import os if os.name == 'nt': # Windows os = 'nt' import msvcrt else:# Posix (Linux, OS X) os = 'LINUX' import sys import termios import atexit from select import select # special key definitions ENTER = 10 ESC = 27 BACKSPACE = 127 TAB = 9 class KBHit: """ this class does the work """ def __init__(self): """Creates a KBHit object to get keyboard input """ if os == 'LINUX': # Save the terminal settings self.fd = sys.stdin.fileno() self.new_term = termios.tcgetattr(self.fd) self.old_term = termios.tcgetattr(self.fd) # New terminal setting unbuffered self.new_term[3] = (self.new_term[3] & ~termios.ICANON & ~termios.ECHO) termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.new_term) # Support normal-terminal reset at exit atexit.register(self.set_normal_term) def set_normal_term(self): """ Resets to normal terminal. On Windows does nothing """ if os == 'LINUX': termios.tcsetattr(self.fd, termios.TCSAFLUSH, self.old_term) def getch(self): """ Returns a keyboard character after kbhit() has been called """ if os == 'nt': return msvcrt.getch().decode('utf-8') else: return sys.stdin.read(1) def kbhit(self): """ Returns True if keyboard character was hit, False otherwise. """ if os == 'nt': return msvcrt.kbhit() else: dr, dw, de = select([sys.stdin], [], [], 0) return dr != [] # Test if __name__ == "__main__": """ main() tests the kbhit() and getch() functions """ kbd = KBHit() print'Hit any key, or ESC to exit' while True: if kbd.kbhit(): print "HIT ", char_hit = kbd.getch() if ord(char_hit) == ESC: print "ESC - ending test" break print