1
0
Fork 0
baconscript/bs.py

35 lines
920 B
Python
Raw Permalink Normal View History

2019-11-18 13:22:31 -05:00
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
2020-11-23 12:31:44 -05:00
"""Interactive BaconScript shell."""
2019-11-18 13:22:31 -05:00
2019-11-18 20:07:48 -05:00
import logging
2019-11-18 13:22:31 -05:00
import sys
2022-05-12 23:19:40 -04:00
from .bacon import comment, LISTENER, HogNet, load_servers
2019-11-18 13:22:31 -05:00
2022-05-12 19:53:08 -04:00
logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)
2019-11-18 20:07:48 -05:00
2022-05-12 23:19:40 -04:00
LISTENER.osc = HogNet(load_servers('server.cfg'))
2019-11-18 22:23:51 -05:00
2019-11-18 13:22:31 -05:00
# handle user input if run directly
if __name__ == '__main__':
if len(sys.argv) > 1:
# look for macros passed as arguments
2019-11-18 20:07:48 -05:00
logging.debug("found macro at argv[1]")
2019-11-18 13:22:31 -05:00
comment(sys.argv[1])
else:
# be an interactive shell
while True:
# get user input
try:
2020-11-23 12:31:44 -05:00
TEXT = input("comment# ")
2019-11-18 13:22:31 -05:00
except (KeyboardInterrupt, EOFError):
2020-11-23 12:31:44 -05:00
TEXT = 'exit'
print(TEXT)
2019-11-18 13:22:31 -05:00
# catch exit keyword
2020-11-23 12:31:44 -05:00
if TEXT.lower() == 'exit':
2019-11-18 13:22:31 -05:00
break
# exec user input
2020-11-23 12:31:44 -05:00
comment(TEXT)