manage exiting without external dependency
This commit is contained in:
parent
1aaf12b6f3
commit
999624bd49
15
comment.py
15
comment.py
|
@ -19,7 +19,6 @@ import antlr4
|
||||||
import configparser
|
import configparser
|
||||||
import logging
|
import logging
|
||||||
import readline
|
import readline
|
||||||
import signal
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from CommentMacroLexer import CommentMacroLexer
|
from CommentMacroLexer import CommentMacroLexer
|
||||||
|
@ -58,20 +57,18 @@ def comment(text):
|
||||||
walker.walk(oscMacro, tree)
|
walker.walk(oscMacro, tree)
|
||||||
|
|
||||||
|
|
||||||
def orderly_exit():
|
|
||||||
logger.info('Goodbye.')
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
signal.signal(signal.SIGINT, orderly_exit)
|
|
||||||
if len(sys.argv) > 1:
|
if len(sys.argv) > 1:
|
||||||
logger.debug("found macro at argv[1]")
|
logger.debug("found macro at argv[1]")
|
||||||
comment(sys.argv[1])
|
comment(sys.argv[1])
|
||||||
else:
|
else:
|
||||||
while True:
|
while True:
|
||||||
text = input("comment# ")
|
try:
|
||||||
|
text = input("comment# ")
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print()
|
||||||
|
sys.exit(0)
|
||||||
if text == 'exit':
|
if text == 'exit':
|
||||||
orderly_exit()
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
comment(text)
|
comment(text)
|
||||||
|
|
Loading…
Reference in New Issue