def finish_del_dup(out_list, out_path, open_out): u.log(f"Saving list without duplicates in '{out_path}'...") u.save_list(out_list, out_path) bn_out = u.big_number(len(out_list)) u.log(f"List saved, it has {bn_out} lines") if open_out: u.startfile(out_path)
def diff_list(list1, list2, out_path): if not out_path: out_path = u.g.dirs['OUT'] + 'file_match_out.csv' out1 = [e for e in list1 if e not in list2] out2 = [e for e in list2 if e not in list1] out = to.del_dup_list(out1 + out2) u.save_list(out, out_path) u.log(f"Comparison result available here: {out_path}")
def extract_doc(in_dirs, out_path): """Extracts all Python doc ('# comments included) present in the 'in_dir' directories (can be usefull for spell check) """ out = [] for in_dir in in_dirs: extract_doc_from_dir(in_dir, out) u.save_list(out, out_path) u.startfile(out_path)
def init_mail(): if p.exists(cfg.MAILS_DIR): return files_dir = f'{p.dirname(__file__)}/files' files_dir = files_dir.replace('\\', '/') if not p.exists(files_dir): s = f"Warning: mail folder couldn't be initialised because {files_dir} was not found" u.log(s) return copytree(files_dir, cfg.MAILS_DIR) u.save_list(['*'], cfg.MAILS_DIR + '.gitignore') u.log(f"Mail folder '{cfg.MAILS_DIR}' successfully initialised")
def shuffle_file(in_path, out_path, open_out=False): """Shuffles the line order of a file using the native random package""" u.log("[toolShuf] shuffle_file: start") cur_list = u.load_txt(in_path) if u.has_header(cur_list): header = cur_list[0] cur_list = cur_list[1:] shuffle(cur_list) cur_list = [header] + cur_list u.save_list(cur_list, out_path) u.log(f"Shuffled file saved in {out_path}") if open_out: u.startfile(out_path) u.log("[toolShuf] shuffle_file: end")
def finish_sbf(out_path, start_time): if gl.FOUND: lowI = gl.c_row - 1 - gl.PRINT_SIZE // 2 if lowI < 0: lowI = 0 highI = gl.c_row - 1 + gl.PRINT_SIZE // 2 u.save_list(gl.cur_list[lowI:highI], out_path) s = f"Current list written in {out_path}" u.log(s.format()) if gl.OPEN_OUT_FILE: u.startfile(out_path) else: bn = u.big_number(gl.c_main) s = (f"EOF reached ({bn} lines, {gl.c_list} temporary lists)" f", string '{gl.LOOK_FOR}' not found") u.log(s) dstr = u.get_duration_string(start_time) u.log(f"[toolBF] search_big_file: end ({dstr})\n")
def save_mail(HTMLbody): u.mkdirs(gl.mail_dir) gl.last_sent = gl.mail_dir + 'last_sent.html' u.save_list([HTMLbody], gl.last_sent) u.log(f"Mail saved to {gl.last_sent}")
def test_mail(): u.init_log('test_mail', True) u.delete_folder('mail_back') if os.path.exists(cfg.MAILS_DIR): copytree(cfg.MAILS_DIR, 'mail_back') u.delete_folder(cfg.MAILS_DIR) u.log_print("Test gmail - KO, recipients not configureed", dashes=100) args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT] ttry(mail.gmail, gl.E_NOT_CONFIGURED, *args) u.log_print() u.log_print("Test gmail - KO, confidential file not found", dashes=100) recipients_path = cfg.MAILS_DIR + gl.MAIL_NAME + '/' + mail.gl.RECIPIENTS u.save_list(gl.RECIPIENTS_FILE, recipients_path) if os.path.exists(cfg.CFI_PATH): os.rename(cfg.CFI_PATH, cfg.CFI_PATH + '_') args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT] ttry(mail.gmail, gl.E_CFI, *args) os.rename(cfg.CFI_PATH + '_', cfg.CFI_PATH) u.log_print() mail.gl.TEST = True u.log_print(f"Test gmail - {gl.S_VDHT}", dashes=100) args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT] mail.gmail(*args) ast(gl.NVAR, gl.HT) u.log_print() u.log_print(f"Test gmail - {gl.S_VDPT}", dashes=100) args = [gl.MAIL_NAME, gl.S_VDPT, gl.VD, [], tm.BODY, gl.RECIPIENTS_IN, KEY] mail.gmail(*args) ast(gl.NVAR, gl.PT) u.log_print() u.log_print(f"Test gmail - {gl.S_HT}", dashes=100) args = [gl.MAIL_NAME, gl.S_HT] mail.gmail(*args) ast(gl.VAR, gl.HT) u.log_print() u.log_print(f"Test gmail - {gl.S_PT}", dashes=100) args = [gl.MAIL_NAME, gl.S_PT, [], [], tm.BODY] mail.gmail(*args) ast(gl.VAR, gl.PT) u.log_print() u.log_print("Test no_auth", dashes=100) args = [gl.MAIL_NAME, gl.S_VDHT, gl.VD, gl.ATT] ttry(mail.no_auth, gl.E_NO_AUT, *args) ast(gl.NVAR, gl.HT) u.log_print() u.log_print("Test outlook", dashes=100) args = [gl.MAIL_NAME, gl.S_VDPT, gl.VD, [], tm.BODY] ttry(mail.outlook, gl.E_OUTLOOK, *args) ast(gl.NVAR, gl.PT) u.log_print() # Restauring mail backup u.delete_folder(cfg.MAILS_DIR) copytree('mail_back', cfg.MAILS_DIR) u.delete_folder('mail_back') u.check_log(tm.CL)