Disable sig handler when reading input (#117)
* Disable sig handler when reading input * Rename read_input to read_in * Update prompt messages
This commit is contained in:
parent
9980e4926a
commit
bbf7428818
37
buku.py
37
buku.py
@ -67,6 +67,16 @@ logger = logging.getLogger()
|
|||||||
logdbg = logger.debug
|
logdbg = logger.debug
|
||||||
logerr = logger.error
|
logerr = logger.error
|
||||||
|
|
||||||
|
def read_in(msg):
|
||||||
|
disable_sigint_handler()
|
||||||
|
message = None
|
||||||
|
try:
|
||||||
|
message = input(msg)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('Interrupted.')
|
||||||
|
|
||||||
|
enable_sigint_handler()
|
||||||
|
return message
|
||||||
|
|
||||||
class BukuHTMLParser(HTMLParser.HTMLParser):
|
class BukuHTMLParser(HTMLParser.HTMLParser):
|
||||||
'''Class to parse and fetch the title
|
'''Class to parse and fetch the title
|
||||||
@ -557,7 +567,7 @@ class BukuDb:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
resp = input('Append specified tags to ALL bookmarks? (y/n): ')
|
resp = read_in('Append the tags to ALL bookmarks? (y/n): ')
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -591,7 +601,7 @@ class BukuDb:
|
|||||||
tags_to_delete = tags_in.strip(DELIM).split(DELIM)
|
tags_to_delete = tags_in.strip(DELIM).split(DELIM)
|
||||||
|
|
||||||
if index == 0:
|
if index == 0:
|
||||||
resp = input('Delete specified tag(s) from ALL bookmarks? (y/n): ')
|
resp = read_in('Delete the tag(s) from ALL bookmarks? (y/n): ')
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -743,7 +753,7 @@ class BukuDb:
|
|||||||
return ret
|
return ret
|
||||||
|
|
||||||
if index == 0: # Update all records
|
if index == 0: # Update all records
|
||||||
resp = input('Update ALL bookmarks? (y/n): ')
|
resp = read_in('Update ALL bookmarks? (y/n): ')
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1073,7 +1083,7 @@ class BukuDb:
|
|||||||
:return: True on success, False on failure
|
:return: True on success, False on failure
|
||||||
'''
|
'''
|
||||||
|
|
||||||
resp = input('Delete the search results? (y/n): ')
|
resp = read_in('Delete the search results? (y/n): ')
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1097,7 +1107,7 @@ class BukuDb:
|
|||||||
:return: True on success, False on failure
|
:return: True on success, False on failure
|
||||||
'''
|
'''
|
||||||
|
|
||||||
resp = input('Remove ALL bookmarks? (y/n): ')
|
resp = read_in('Remove ALL bookmarks? (y/n): ')
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
print('No bookmarks deleted')
|
print('No bookmarks deleted')
|
||||||
return False
|
return False
|
||||||
@ -1303,7 +1313,7 @@ class BukuDb:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if os.path.exists(filepath):
|
if os.path.exists(filepath):
|
||||||
resp = input('%s exists. Overwrite? (y/n): ' % filepath)
|
resp = read_in('%s exists. Overwrite? (y/n): ' % filepath)
|
||||||
if resp != 'y':
|
if resp != 'y':
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1844,9 +1854,9 @@ def taglist_subprompt(obj, msg, noninteractive=False):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nav = input(msg)
|
nav = read_in(msg)
|
||||||
if not nav:
|
if not nav:
|
||||||
nav = input(msg)
|
nav = read_in(msg)
|
||||||
if not nav:
|
if not nav:
|
||||||
# Quit on double enter
|
# Quit on double enter
|
||||||
return 'q'
|
return 'q'
|
||||||
@ -1910,9 +1920,9 @@ def prompt(obj, results, noninteractive=False, deep=False, subprompt=False):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
nav = input(msg)
|
nav = read_in(msg)
|
||||||
if not nav:
|
if not nav:
|
||||||
nav = input(msg)
|
nav = read_in(msg)
|
||||||
if not nav:
|
if not nav:
|
||||||
# Quit on double enter
|
# Quit on double enter
|
||||||
break
|
break
|
||||||
@ -2175,8 +2185,13 @@ def sigint_handler(signum, frame):
|
|||||||
# Do a hard exit from here
|
# Do a hard exit from here
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
signal.signal(signal.SIGINT, sigint_handler)
|
|
||||||
|
|
||||||
|
DEFAULT_HANDLER = signal.signal(signal.SIGINT, sigint_handler)
|
||||||
|
def disable_sigint_handler():
|
||||||
|
signal.signal(signal.SIGINT, DEFAULT_HANDLER)
|
||||||
|
|
||||||
|
def enable_sigint_handler():
|
||||||
|
signal.signal(signal.SIGINT, sigint_handler)
|
||||||
|
|
||||||
# ---------------------
|
# ---------------------
|
||||||
# Editor mode functions
|
# Editor mode functions
|
||||||
|
Loading…
Reference in New Issue
Block a user