Skip to content

Commit a9dd510

Browse files
author
tibut
committed
added -p parameter to dynamically load processing_steps,added -q -qq for logging
1 parent 48a42af commit a9dd510

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

python-bitflow

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,12 @@ from bitflow.script_parser import *
1414
PIPES_INPUTS = []
1515
CLOSING = False
1616

17-
def configure_logging(debug,filename=None):
17+
def configure_logging(logging_level,filename=None):
1818
if filename is None:
19-
if debug:
20-
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.DEBUG)
21-
else:
22-
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)
19+
logging.basicConfig(format='%(asctime)s %(message)s', level=logging_level)
2320
else:
24-
if debug:
25-
logging.basicConfig(filename=filename,format='%(asctime)s %(message)s', level=logging.DEBUG)
26-
else:
27-
logging.basicConfig(filename=filename,format='%(asctime)s %(message)s', level=logging.INFO)
21+
logging.basicConfig(filename=filename,format='%(asctime)s %(message)s', level=logging_level)
22+
2823

2924
def strg_c_exit():
3025
global PIPES_INPUTS
@@ -57,48 +52,53 @@ def main():
5752
# argparse does not support no flag optional arguments ...
5853
# mutually_exclusive groups cannot have name ...
5954
script_group = parser.add_mutually_exclusive_group(required=True)
60-
script_group.add_argument('-script',type=str,help="bitflow script. (https://github.com/bitflow-stream/antlr-grammars/tree/master/bitflow-script)")
55+
script_group.add_argument('-s','-script',type=str,help="bitflow script. (https://github.com/bitflow-stream/antlr-grammars/tree/master/bitflow-script)")
6156
script_group.add_argument("-f",help="Read given file as Bitflow Script and execute the pipeline.", metavar='')
6257
script_group.add_argument("-capabilities",action='store_true',help="list all available processing steps")
63-
#parser.add_argument("-p",help="dynamic import processing steps from a .py file")
58+
parser.add_argument("-p",help="dynamic import processing steps from a .py file")
6459
ld_group = parser.add_argument_group("logging and debug")
6560
ld_group.add_argument("-log",help="Redirect logs to a given file in addition to the console.",metavar='')
66-
ld_group.add_argument("-v",action='store_true',help="Enable verbose logging Sink")
61+
# general groups can not be combined with mutex groups....
62+
ld_group.add_argument("-v",action='store_true',help=" Set log level to Debug (default is Info)")
63+
ld_group.add_argument("-q",action='store_true',help=" Set log level to Warning")
64+
ld_group.add_argument("-qq",action='store_true',help=" Set log level to Error")
65+
6766
args = parser.parse_args()
6867

69-
#################
70-
# MANAGE DEBUG #
71-
#################
68+
##########################
69+
# MANAGE DEBUG & LOGGING #
70+
##########################
7271

73-
debug = False
72+
log_level = logging.INFO
73+
if args.qq:
74+
log_level = logging.ERROR
75+
if args.q:
76+
log_level = logging.WARNING
7477
if args.v:
75-
debug = True
76-
78+
log_level = logging.DEBUG
7779
if args.log:
7880
logfile = args.log
79-
configure_logging(debug,logfile)
81+
configure_logging(log_level,logfile)
8082
else:
81-
configure_logging(debug)
83+
configure_logging(log_level)
8284
logging.debug("debug mode enabled")
8385

84-
85-
#if args.p:
86-
# import importlib.util
87-
# file_path = args.p
88-
# module_name = '*'
89-
# spec = importlib.util.spec_from_file_location(module_name, file_path)
90-
# module = importlib.util.module_from_spec(spec)
91-
# spec.loader.exec_module(module)
86+
if args.p:
87+
import importlib.util
88+
file_path = args.p
89+
module_name = '*'
90+
spec = importlib.util.spec_from_file_location(module_name, file_path)
91+
module = importlib.util.module_from_spec(spec)
92+
spec.loader.exec_module(module)
9293

9394
if args.capabilities:
9495
capabilities()
9596
sys.exit(0)
9697

9798
if args.f:
9899
script = read_script(args.f)
99-
if args.script:
100-
script = args.script
101-
100+
if args.s:
101+
script = args.s
102102

103103
try:
104104
PIPES_INPUTS = parse_script(script)

0 commit comments

Comments
 (0)