Skip to content

Commit be5656a

Browse files
AERAdlermhasself
authored andcommitted
update_obsdb can store bad books in a file and raise exception for them.
1 parent 27d726a commit be5656a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

sotodlib/site_pipeline/update_obsdb.py

+20-9
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
lat_tube_list_file: path to yaml dict matching tubes and bands
2121
tolerate_stray_files: True
2222
skip_bad_books: True
23-
known_bad_books:
24-
- oper_1736874485_satp3_0000100
25-
- obs_9999999999_satp0_1111111
23+
known_bad_books_file: path to \n-separated file listing bad books
2624
extra_extra_files:
2725
- Z_bookbinder_log.txt
2826
extra_files:
@@ -153,8 +151,14 @@ def main(config: str,
153151
bookcartobsdb.add_obs_columns(col_list)
154152
if "skip_bad_books" not in config_dict:
155153
config_dict["skip_bad_books"] = False
156-
if "known_bad_books" not in config_dict:
157-
config_dict["known_bad_books"] = []
154+
155+
config_dict["known_bad_books"] = []
156+
if "known_bad_books_file" in config_dict:
157+
try:
158+
with open(config_dict["known_bad_books_file"], "r") as bbf:
159+
config_dict["known_bad_books"] = bbf.read().split("\n")
160+
except:
161+
raise IOError("Bad books file couldn't be read in")
158162

159163
#How far back we should look
160164
tnow = time.time()
@@ -192,6 +196,7 @@ def main(config: str,
192196

193197
logger.info(f"Found {len(bookcart)} new books in {time.time()-tnow} s")
194198
#Check the books for the observations we want
199+
bad_book_counter = 0
195200
for bookpath in sorted(bookcart):
196201
if check_meta_type(bookpath) in accept_type:
197202
t1 = time.time()
@@ -207,7 +212,12 @@ def main(config: str,
207212
logger.info(f"Ran check_book in {time.time()-t1} s")
208213
except Exception as e:
209214
if config_dict["skip_bad_books"]:
210-
logger.warning(f"failed to add {bookpath}")
215+
config_dict["known_bad_books"].append(book_id)
216+
logger.error(f"failed to add {bookpath}. There are now {len(config_dict['known_bad_books'])} known bad books.")
217+
bad_book_counter +=1
218+
if "known_bad_books_file" in config_dict:
219+
with open(config_dict["known_bad_books_file"], "w") as bbf:
220+
bbf.write("\n".join(config_dict["known_bad_books"]))
211221
continue
212222
else:
213223
raise e
@@ -226,8 +236,7 @@ def main(config: str,
226236
for key, val in very_clean.items():
227237
col_list.append(key+" "+type(val).__name__)
228238
bookcartobsdb.add_obs_columns(col_list)
229-
if "skip_bad_books" not in config_dict:
230-
config_dict["skip_bad_books"] = False
239+
231240
#Adding info that should be there for all observations
232241
#Descriptive string columns
233242
try:
@@ -326,7 +335,9 @@ def main(config: str,
326335
logger.info(f"Finished {obs_id} in {time.time()-t1} s")
327336
else:
328337
bookcart.remove(bookpath)
329-
338+
if bad_book_counter != 0:
339+
logger.error(f"Found {bad_book_counter} new bad books, There are now {len(config_dict['known_bad_books'])} known bad books.")
340+
raise(Exception)
330341

331342
def get_parser(parser=None):
332343
if parser is None:

0 commit comments

Comments
 (0)