Skip to content
Snippets Groups Projects
Commit 969412d6 authored by Leo Tsukada's avatar Leo Tsukada Committed by Prathamesh Joshi
Browse files

gstlal_ll_inspiral_remove_counts : a bit of restructure and fix the minor bug for logging.

parent b201df06
No related branches found
No related tags found
No related merge requests found
......@@ -103,43 +103,52 @@ def submit(filename, gps_time):
return urllib.request.urlopen(url, data = post_data)
logger = logging.getLogger('gstlal_ll_inspiral_remove_counts')
log_level = logging.WARN if options.verbose else logging.INFO
log_level = logging.INFO if options.verbose else logging.WARN
logger.setLevel(log_level)
OK = False
if options.action == "remove":
post_func = submit
check_bool = True
elif options.action == "undo-remove":
post_func = undo
check_bool = False
partially_OK = False
all_OK = True
for filename in filenames:
for gps_time in options.gps_time:
if options.action == "check":
try:
if not check(filename, gps_time):
all_OK &= False
logger.warning(f'gps-time {gps_time} not in {filename}')
else:
partially_OK |= True
logger.info(f'gps-time {gps_time} found in {filename}')
except ConnectionError:
logger.error(f'ConnectionError : could not check for gps-time {gps_time} in {filename}')
continue
elif options.action == "remove":
post_func = submit
check_bool = True
elif options.action == "undo-remove":
post_func = undo
check_bool = False
try:
response = post_func(filename, gps_time)
msg = response.read().decode("utf-8")
if "ValueError" in msg:
raise ValueError(msg.lstrip("ValueError : "))
elif "warning" in msg:
logger.warning(msg)
elif "error" in msg:
logger.error(f'Error came up while {post_func.__name__}-ing for gps-time {gps_time} and {filename}')
elif "OK" in msg and check(filename, gps_time) == check_bool:
OK |= True
logger.info(msg.strip() + f'for {filename}')
elif "OK" in msg:
logger.warning(f'gps-time {gps_time} has been {post_func.__name__}-ed but failed for {filename}')
except URLError:
logger.error(f'URLError : calling {post_func.__name__ }() for gps-time {gps_time} and {filename} failed')
if not OK:
logger.warning("Given files are all getting either warning or error. Please check if the gps time and the files are valid.")
\ No newline at end of file
all_OK &= False
else:
try:
response = post_func(filename, gps_time)
msg = response.read().decode("utf-8")
if "OK" in msg and check(filename, gps_time) == check_bool:
partially_OK |= True
logger.info(msg.strip() + f'for {filename}')
continue
elif "OK" in msg:
logger.warning(f'gps-time {gps_time} has been {post_func.__name__}-ed but failed for {filename}')
elif "ValueError" in msg:
raise ValueError(msg.lstrip("ValueError : "))
elif "warning" in msg:
logger.warning(msg)
elif "error" in msg:
logger.error(f'Error came up while {post_func.__name__}-ing for gps-time {gps_time} and {filename}')
except URLError:
logger.error(f'URLError : calling {post_func.__name__ }() for gps-time {gps_time} and {filename} failed')
all_OK &= False
if not partially_OK:
logger.warning(f'"{options.action}" is getting either warning or error for all the given files. Please check if the gps time and the files are valid.')
if all_OK:
logger.warning(f'"{options.action}" is properly done for all the given files.')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment