Skip to content

Commit

Permalink
Add possibility to toggle printing log statements in terminal from a …
Browse files Browse the repository at this point in the history
…terminal command
  • Loading branch information
robvanholstein committed Sep 29, 2020
1 parent 655e7cb commit 8728fe9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
21 changes: 21 additions & 0 deletions irdap/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions irdap/irdap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions irdap/print_in_terminal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
True

0 comments on commit 8728fe9

Please sign in to comment.