[apparmor] [patch] ui.py - when using (N)ew, set selected path as default input
Christian Boltz
apparmor at cboltz.de
Tue Aug 5 23:15:11 UTC 2014
Hello,
this patch sets the currently selected path as (editable) default when
using "(N)ew" in aa-logprof or aa-genprof.
Credits go to
http://stackoverflow.com/questions/2533120/show-default-value-for-editing-on-python-input-possible ;-)
Also, some hate goes to the python devs because they changed the meaning
of input() between py2 and py3 in a terrible way. (Yes, what py2 input()
did was crazy, but it's even more crazy to change its behaviour.)
If someone knows a sane replacement for input() / raw_input() that avoids
the version switch, I'm open for suggestions ;-)
Note: I tested this patch only with py3.
=== modified file 'utils/apparmor/ui.py'
--- utils/apparmor/ui.py 2014-02-24 19:56:28 +0000
+++ utils/apparmor/ui.py 2014-08-05 23:05:47 +0000
@@ -13,6 +13,7 @@
# ----------------------------------------------------------------------
import sys
import re
+import readline
from apparmor.yasti import yastLog, SendDataToYast, GetDataFromYast
from apparmor.common import readkey, AppArmorException, DebugLogger
@@ -170,8 +171,16 @@
debug_logger.debug('UI_GetString: %s: %s %s' % (UI_mode, text, default))
string = default
if UI_mode == 'text':
- sys.stdout.write('\n' + text)
- string = sys.stdin.readline()
+ readline.set_startup_hook(lambda: readline.insert_text(default))
+ try:
+ if sys.version_info[0] >= 3:
+ string = input(text)
+ else:
+ string = raw_input(text)
+ except EOFError:
+ string = ''
+ finally:
+ readline.set_startup_hook()
else:
SendDataToYast({'type': 'dialog-getstring',
'label': text,
Regards,
Christian Boltz
--
Ich denk in Prag werd ich dann hauptsächlich für Euch Kaffee kochen. :)
[Lars Müller in opensuse-de]
More information about the AppArmor
mailing list