From 8728fe9a2b632a5b3e964791891caca61c851359 Mon Sep 17 00:00:00 2001 From: robvanholstein Date: Tue, 29 Sep 2020 13:58:37 +0200 Subject: [PATCH] Add possibility to toggle printing log statements in terminal from a terminal command --- irdap/__main__.py | 21 +++++++++++++++++++++ irdap/irdap.py | 12 ++++++++++-- irdap/print_in_terminal.txt | 1 + 3 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 irdap/print_in_terminal.txt diff --git a/irdap/__main__.py b/irdap/__main__.py index 5dcd4ce..ea28b40 100644 --- a/irdap/__main__.py +++ b/irdap/__main__.py @@ -97,6 +97,8 @@ def main(args=None): help='show program\'s version number') parser.add_argument('-w', '--website', action='store_true', help='open IRDAP online documentation in web browser') + parser.add_argument('-p', '--print', action='store_true', + help='toggle printing of log statements in the terminal') parser.add_argument('-d', '--demo', action='store_true', help='run pipeline in current working directory with example\ndata of the circumstellar disk of T Cha (1 HWP cycle)') parser.add_argument('-o', '--headers', action='store_true', @@ -124,6 +126,25 @@ def main(args=None): elif args.website: webbrowser.open_new_tab('https://irdap.readthedocs.io') + if args.print: + # Toggle printing in terminal + path_file = os.path.join(os.path.dirname(__file__), 'print_in_terminal.txt') + f = open(path_file, 'r') + current_value = f.read() + f.close() + if current_value == 'True': + print('\nIRDAP will not print log statements in the terminal.') + f = open(path_file, 'w') + f.write('False') + f.close() + elif current_value == 'False': + print('\nIRDAP will print log statements in the terminal.') + f = open(path_file, 'w') + f.write('True') + f.close() + else: + print('\nThe file ' + path_file + ' should contain either the word \'True\' or \'False\'.') + elif args.demo: # Run example reduction run_demo(path_main_dir) diff --git a/irdap/irdap.py b/irdap/irdap.py index 382ffe5..ef5b607 100644 --- a/irdap/irdap.py +++ b/irdap/irdap.py @@ -280,9 +280,10 @@ def printandlog(single_object, wrap=True): if type(single_object) == str and wrap == True: single_object = wrapstr(single_object) - # Print object in log file and on screen + # Print object in log file and on screen if selected as such print(single_object, file=open(path_log_file, 'a')) - print(single_object) + if print_in_terminal: + print(single_object) ############################################################################### # create_overview_headers @@ -6427,6 +6428,7 @@ def run_pipeline(path_main_dir): ############################################################################### # Define which variables should be global + global print_in_terminal global pupil_offset global true_north_correction global pixel_scale @@ -6450,6 +6452,12 @@ def run_pipeline(path_main_dir): global path_overview global path_static_calib_dir + # Determine whether to print in terminal + path_file = os.path.join(os.path.dirname(__file__), 'print_in_terminal.txt') + f = open(path_file, 'r') + print_in_terminal = f.read() == 'True' + f.close() + # Define pupil-offset (deg) in pupil-tracking mode (SPHERE User Manual P99.0, 6th public release, P99 Phase 1) pupil_offset = 135.99 diff --git a/irdap/print_in_terminal.txt b/irdap/print_in_terminal.txt new file mode 100644 index 0000000..4791ed5 --- /dev/null +++ b/irdap/print_in_terminal.txt @@ -0,0 +1 @@ +True \ No newline at end of file