Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions blech_clust.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ def initialize_groups(self):
found_list.append(this_group)

if len(found_list) > 0 and not self.force_run:
print(f'Data already present: {found_list}')
reload_msg = f'Data already present: {found_list}' + '\n' +\
'Reload data? (yes/y/n/no) ::: '
reload_data_str, continue_bool = entry_checker(
msg='Reload data? (yes/y/n/no) ::: ',
msg= reload_msg,
check_func=lambda x: x in ['y', 'yes', 'n', 'no'],
fail_response='Please enter (yes/y/n/no)')
else:
Expand Down
36 changes: 35 additions & 1 deletion utils/blech_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,32 @@
import glob
import json
import pandas as pd
import sys
from datetime import datetime

class Tee:
"""Tee output to both stdout/stderr and a log file"""
def __init__(self, data_dir, name='output.log'):
self.log_path = os.path.join(data_dir, name)
self.file = open(self.log_path, 'a')
self.stdout = sys.stdout
self.stderr = sys.stderr
sys.stdout = self
sys.stderr = self

def write(self, data):
self.file.write(data)
self.stdout.write(data)
self.file.flush()

def flush(self):
self.file.flush()

def close(self):
sys.stdout = self.stdout
sys.stderr = self.stderr
self.file.close()

class path_handler():

def __init__(self):
Expand All @@ -28,9 +52,10 @@ class pipeline_graph_check():
"""

def __init__(self, data_dir):
self.data_dir = data_dir
self.tee = Tee(data_dir)
self.load_graph()
self.check_graph()
self.data_dir = data_dir

def load_graph(self):
"""
Expand Down Expand Up @@ -129,10 +154,19 @@ def write_to_log(self, script_path, type = 'attempted'):
if 'attempted' not in log_dict.keys():
log_dict['attempted'] = {}
log_dict['attempted'][script_path] = current_datetime
print('============================================================')
print(f'Attempting {os.path.basename(script_path)}, started at {current_datetime}')
print('============================================================')
elif type == 'completed':
if 'completed' not in log_dict.keys():
log_dict['completed'] = {}
log_dict['completed'][script_path] = current_datetime
print('============================================================')
print(f'Completed {os.path.basename(script_path)}, ended at {current_datetime}')
print('============================================================')
# Close tee when completing
if hasattr(self, 'tee'):
self.tee.close()
# log_dict[script_path] = current_datetime
with open(self.log_path, 'w') as log_file_connect:
json.dump(log_dict, log_file_connect, indent = 4)
Expand Down