1
0
Fork 0
baconscript/bs.py

42 lines
1.0 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""Interactive BaconScript shell.
"""
import logging
import sys
from bacon.script import comment, listener
from bacon.script import loadConfig as loadBsConfig
from bacon.hog4 import HogNet
# setup logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
listener.osc = HogNet(loadBsConfig('server.cfg'))
# handle user input if run directly
if __name__ == '__main__':
if len(sys.argv) > 1:
# look for macros passed as arguments
logging.debug("found macro at argv[1]")
comment(sys.argv[1])
else:
# for input history and line editing
import readline
# be an interactive shell
while True:
# get user input
try:
text = input("comment# ")
except (KeyboardInterrupt, EOFError):
text = 'exit'
print(text)
# catch exit keyword
if text.lower() == 'exit':
break
# exec user input
comment(text)