def prompt_dup_key(n_dup_key): u.log_print('|') bn = u.big_number(n_dup_key) s = f"Warning: {bn} different lines with the same research key were identified" u.log(s) u.log_example(gl.dup_key_list) s = ("\nFile comparison may not work correctly. Here are your options:" "\na -> save duplicates list and quit" "\nb -> quit without saving duplicates list" "\nc -> save duplicates list and continue" "\nd -> continue without saving duplicates list") if gl.TEST_PROMPT_DK: u.log_print(s) u.log_print('c (TEST_PROMPT_DK = True)') command = 'c' else: command = u.log_input(s) u.log_print('|') if command == 'a' or command == 'c': u.save_csv(gl.dup_key_list, gl.OUT_DUP_KEY_FILE) s = f"List of key duplicates written in file {gl.OUT_DUP_KEY_FILE}" u.log(s) if command == 'a' or command == 'b': sys.exit()
def compare_dates(d_bdd, d_now): if d_bdd == d_now: u.log("IUTD check OK") else: s = (f"Warning: conf of DB '{gl.DB}' don't seem to be up to date:" f"\nDB date: {d_bdd}" f"\nToday's date: {d_now}" "\nContinue? (y/n)") if gl.TEST_IUTD: u.log_print(s) u.log_print('y (TEST_IUTD = True)') elif u.log_input(s) == 'n': sys.exit() u.log_print('|')
def check_internal(recipients): sint = gl.INTERNAL_STR u.log(f"Checking if all recipients are internal (ie. contain '{sint}')") not_int = [elt for elt in recipients if sint not in elt] if not_int: if len(not_int) > 1: s = f'Warning: "{not_int}" are not internal email addresses. Send anyways? (y/n)' else: s = f'Warning: "{not_int}" is not an internal email address. Send anyways? (y/n)' if gl.TEST: u.log(s) u.log_print('y (TEST = True)') elif not u.log_input(s) == 'y': sys.exit()
def recover(): file_list = u.list_files(gl.TMP_DIR, False) a = len(file_list) if a == 0: return s = "Work in progress detected. Recover? (y/n)" if gl.TEST_RECOVER: u.log(s) u.log_print("y (TEST_RECOVER = True)") elif u.log_input(s) == 'n': u.mkdirs(gl.TMP_DIR, True) return modify_ql(file_list) u.log("Query list modified according previous work in progress. " f"Recovering from query '{gl.QUERY_LIST[0][1]}'.")
def split_needed(): n_line = gl.c_out n_out_files = ceil(n_line / gl.MAX_LINE_SPLIT) if n_out_files == 1: return False n_line_2 = n_line + n_out_files - 1 n_out_files = ceil(n_line_2 / gl.MAX_LINE_SPLIT) bn = u.big_number(gl.MAX_LINE_SPLIT) s = (f"Input file has more than {bn} lines." f" It will be split in {n_out_files} files " f"(max file nb set to {gl.MAX_FILE_NB_SPLIT}). Continue? (y/n)") if gl.TEST_PROMPT_SPLIT: u.log(s) u.log_print('y (TEST_PROMPT_SPLIT = True)') return True if u.log_input(s) == "n": sys.exit() return True
def check_recover(): chunk = gl.tmp_file_chunk if os.path.exists(chunk): s = "Injection running detected. Recover? (y/n)" if gl.TEST_RECOVER: u.log(s) u.log_print("y (TEST_RECOVER = True)") elif u.log_input(s) == "n": os.remove(chunk) return False txt = u.load_txt(chunk) try: gl.ref_chunk = int(txt[0]) return True except Exception as e: log.recover_fail(e, chunk, txt) os.remove(chunk) return False
def init_equal_diff_bool(): if gl.EQUAL_OUT: if gl.c_sf_read <= gl.MAX_ROW_EQUAL_OUT: gl.EQUAL = True gl.DIFF = gl.DIFF_OUT else: bn = u.big_number(gl.MAX_ROW_EQUAL_OUT) s = (f"Warning: file to be compared have more than {bn} lines" " and EQUAL_OUT paramter is set to True.\n" "Do you want to write matching lines in output file ? (y/n)") if u.log_input(s) == "y": gl.EQUAL = True gl.DIFF = gl.DIFF_OUT else: gl.EQUAL = False gl.DIFF = True else: gl.EQUAL = False gl.DIFF = True
def check_counter(in_file): if gl.c_read % gl.N_READ == 0: if gl.TEST: u.log_print(gl.s_prompt) u.log_print('e (TEST = True)') command = 'e' else: command = u.log_input(gl.s_prompt) u.log_print() if command == '': return True if command == 'q': return False if command == 'e': goto_eof(in_file) if command[0].isdigit(): skip(command, in_file) return True
def check_field_nb(): if gl.PIVOT_IDX != 0: s = (f"Warning: pivot index is set to {gl.PIVOT_IDX}." " Continue? (y/n)") if u.log_input(s) == 'n': sys.exit()